feat(solaris): changed agents logic; made content_configs dynamic and maybe smth else..

This commit is contained in:
shinrei
2025-07-02 21:46:19 +00:00
parent 38d0c09b85
commit b7cd2de0f3
5 changed files with 85 additions and 41 deletions

View File

View 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

View 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]

View File

@@ -3,21 +3,9 @@ from dataclasses import asdict
from google import genai
from .content_configs import MAIN_CONTENT_CONFIG, MESSAGE_CONTENT_CONFIG
from .structures import InputMessage, OutputMessage
class SolarisClient:
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=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

View File

@@ -2,37 +2,50 @@ from google.genai import types
from .structures import OutputMessage
MAIN_CONTENT_CONFIG = types.GenerateContentConfig(
system_instruction="meow meow meow", # надо где-то промпт хранить, в бд наверное хезе
thinking_config=types.ThinkingConfig(thinking_budget=0),
response_mime_type="application/json",
response_schema=list[
OutputMessage
], # ты уверен что там json надо? мне просто каж что судя по всему вот эта нам
safety_settings=[
types.SafetySetting(category=category, threshold=types.HarmBlockThreshold.OFF)
for category in types.HarmCategory
],
)
safety_settings = [
types.SafetySetting(category=category, threshold=types.HarmBlockThreshold.OFF)
for category in types.HarmCategory
]
MESSAGE_CONTENT_CONFIG = types.GenerateContentConfig(
response_mime_type="application/json", # возможно можно скипнуть это если мы используем response_schema, надо проверить
response_schema=list[OutputMessage],
)
def generate_respond_config(prompt: str) -> types.GenerateContentConfig:
return types.GenerateContentConfig(
system_instruction=prompt,
thinking_config=types.ThinkingConfig(thinking_budget=0),
response_mime_type="application/json",
response_schema=list[
OutputMessage
], # ты уверен что там json надо? мне просто каж что судя по всему вот эта нам
safety_settings=safety_settings,
)
TTS_CONTENT_CONFIG = types.GenerateContentConfig(
response_modalities=[types.Modality.AUDIO],
speech_config=types.SpeechConfig(
voice_config=types.VoiceConfig(
prebuilt_voice_config=types.PrebuiltVoiceConfig(
voice_name="Kore",
def generate_review_config(prompt: str) -> types.GenerateContentConfig:
return types.GenerateContentConfig(
system_instruction=prompt,
thinking_config=types.ThinkingConfig(thinking_budget=0),
response_mime_type="application/json",
response_schema=list[int],
safety_settings=safety_settings,
)
# 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],
speech_config=types.SpeechConfig(
voice_config=types.VoiceConfig(
prebuilt_voice_config=types.PrebuiltVoiceConfig(
voice_name="Kore",
)
)
)
),
safety_settings=[
types.SafetySetting(category=category, threshold=types.HarmBlockThreshold.OFF)
for category in types.HarmCategory
],
)
),
safety_settings=safety_settings,
)