feat(solaris): changed agents logic; made content_configs dynamic and maybe smth else..
This commit is contained in:
0
src/bot/modules/solaris/agents/build.py
Normal file
0
src/bot/modules/solaris/agents/build.py
Normal file
20
src/bot/modules/solaris/agents/respond.py
Normal file
20
src/bot/modules/solaris/agents/respond.py
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import json
|
||||||
|
from dataclasses import asdict
|
||||||
|
|
||||||
|
from google import genai
|
||||||
|
|
||||||
|
from ..content_configs import generate_respond_config
|
||||||
|
from ..structures import InputMessage, OutputMessage
|
||||||
|
|
||||||
|
|
||||||
|
class RespondAgent:
|
||||||
|
def __init__(self, api_key: str) -> None:
|
||||||
|
client = genai.Client(api_key=api_key).aio
|
||||||
|
self.chat = client.chats.create(
|
||||||
|
model="gemini-2.5-flash", config=generate_respond_config(prompt="im gay")
|
||||||
|
)
|
||||||
|
|
||||||
|
async def send_messages(self, messages: list[InputMessage]) -> list[OutputMessage]:
|
||||||
|
data = json.dumps([msg.model_dump() for msg in messages], ensure_ascii=True)
|
||||||
|
response = await self.chat.send_message(data)
|
||||||
|
return response.parsed
|
||||||
23
src/bot/modules/solaris/agents/review.py
Normal file
23
src/bot/modules/solaris/agents/review.py
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import io
|
||||||
|
import json
|
||||||
|
|
||||||
|
from google import genai
|
||||||
|
from google.genai import types
|
||||||
|
from pydub import AudioSegment
|
||||||
|
|
||||||
|
from ..content_configs import generate_review_config
|
||||||
|
from ..structures import InputMessage
|
||||||
|
|
||||||
|
|
||||||
|
class ReviewAgent:
|
||||||
|
def __init__(self, api_key: str) -> None:
|
||||||
|
self.client = genai.Client(api_key=api_key).aio
|
||||||
|
|
||||||
|
async def review(self, messages: list[InputMessage]) -> list[InputMessage]:
|
||||||
|
data = json.dumps([msg.model_dump() for msg in messages], ensure_ascii=True)
|
||||||
|
response = await self.client.models.generate_content(
|
||||||
|
model="gemini-2.5-flash-lite-preview-06-17", # надо будет гемму
|
||||||
|
contents=data,
|
||||||
|
config=generate_review_config(prompt="fortnite balls"),
|
||||||
|
)
|
||||||
|
return [msg for msg in messages if msg.message_id in response.parsed]
|
||||||
@@ -3,21 +3,9 @@ from dataclasses import asdict
|
|||||||
|
|
||||||
from google import genai
|
from google import genai
|
||||||
|
|
||||||
from .content_configs import MAIN_CONTENT_CONFIG, MESSAGE_CONTENT_CONFIG
|
|
||||||
from .structures import InputMessage, OutputMessage
|
from .structures import InputMessage, OutputMessage
|
||||||
|
|
||||||
|
|
||||||
class SolarisClient:
|
class SolarisClient:
|
||||||
def __init__(self, api_key: str) -> None:
|
def __init__(self, api_key: str) -> None:
|
||||||
client = genai.Client(api_key=api_key).aio
|
client = genai.Client(api_key=api_key).aio
|
||||||
self.chat = client.chats.create(
|
|
||||||
model="gemini-2.5-flash", config=MAIN_CONTENT_CONFIG
|
|
||||||
)
|
|
||||||
|
|
||||||
async def send_messages(self, messages: list[InputMessage]) -> list[OutputMessage]:
|
|
||||||
data = json.dumps([msg.model_dump() for msg in messages], ensure_ascii=True)
|
|
||||||
resp = await self.chat.send_message(data, config=MESSAGE_CONTENT_CONFIG)
|
|
||||||
output_messages = [
|
|
||||||
OutputMessage.model_validate(msg) for msg in json.loads(resp.text)
|
|
||||||
]
|
|
||||||
return output_messages
|
|
||||||
|
|||||||
@@ -2,27 +2,43 @@ from google.genai import types
|
|||||||
|
|
||||||
from .structures import OutputMessage
|
from .structures import OutputMessage
|
||||||
|
|
||||||
MAIN_CONTENT_CONFIG = types.GenerateContentConfig(
|
safety_settings = [
|
||||||
system_instruction="meow meow meow", # надо где-то промпт хранить, в бд наверное хезе
|
types.SafetySetting(category=category, threshold=types.HarmBlockThreshold.OFF)
|
||||||
|
for category in types.HarmCategory
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def generate_respond_config(prompt: str) -> types.GenerateContentConfig:
|
||||||
|
return types.GenerateContentConfig(
|
||||||
|
system_instruction=prompt,
|
||||||
thinking_config=types.ThinkingConfig(thinking_budget=0),
|
thinking_config=types.ThinkingConfig(thinking_budget=0),
|
||||||
response_mime_type="application/json",
|
response_mime_type="application/json",
|
||||||
response_schema=list[
|
response_schema=list[
|
||||||
OutputMessage
|
OutputMessage
|
||||||
], # ты уверен что там json надо? мне просто каж что судя по всему вот эта нам
|
], # ты уверен что там json надо? мне просто каж что судя по всему вот эта нам
|
||||||
safety_settings=[
|
safety_settings=safety_settings,
|
||||||
types.SafetySetting(category=category, threshold=types.HarmBlockThreshold.OFF)
|
|
||||||
for category in types.HarmCategory
|
|
||||||
],
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
MESSAGE_CONTENT_CONFIG = types.GenerateContentConfig(
|
def generate_review_config(prompt: str) -> types.GenerateContentConfig:
|
||||||
response_mime_type="application/json", # возможно можно скипнуть это если мы используем response_schema, надо проверить
|
return types.GenerateContentConfig(
|
||||||
response_schema=list[OutputMessage],
|
system_instruction=prompt,
|
||||||
|
thinking_config=types.ThinkingConfig(thinking_budget=0),
|
||||||
|
response_mime_type="application/json",
|
||||||
|
response_schema=list[int],
|
||||||
|
safety_settings=safety_settings,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
TTS_CONTENT_CONFIG = types.GenerateContentConfig(
|
# MESSAGE_CONTENT_CONFIG = types.GenerateContentConfig(
|
||||||
|
# response_mime_type="application/json", # возможно можно скипнуть это если мы используем response_schema, надо проверить
|
||||||
|
# response_schema=list[OutputMessage],
|
||||||
|
# )
|
||||||
|
|
||||||
|
|
||||||
|
# можно было и константу оставить но хезе некрасиво чет
|
||||||
|
def generate_tts_config() -> types.GenerateContentConfig:
|
||||||
|
return types.GenerateContentConfig(
|
||||||
response_modalities=[types.Modality.AUDIO],
|
response_modalities=[types.Modality.AUDIO],
|
||||||
speech_config=types.SpeechConfig(
|
speech_config=types.SpeechConfig(
|
||||||
voice_config=types.VoiceConfig(
|
voice_config=types.VoiceConfig(
|
||||||
@@ -31,8 +47,5 @@ TTS_CONTENT_CONFIG = types.GenerateContentConfig(
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
safety_settings=[
|
safety_settings=safety_settings,
|
||||||
types.SafetySetting(category=category, threshold=types.HarmBlockThreshold.OFF)
|
|
||||||
for category in types.HarmCategory
|
|
||||||
],
|
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user