style(global): use formatters

This commit is contained in:
h
2025-07-02 10:03:57 +03:00
parent 4bd0df4e5a
commit 240384840e
5 changed files with 39 additions and 42 deletions

View File

@@ -1,28 +1,22 @@
import json
from google import genai
from .structures import InputMessage, OutputMessage
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
model="gemini-2.5-flash", config=MAIN_CONTENT_CONFIG
)
#self.tts
# self.tts
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.fromdict(msg)
for msg in json.loads(resp.text)
]
return output_messages
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.fromdict(msg) for msg in json.loads(resp.text)]
return output_messages

View File

@@ -1,19 +1,18 @@
from google.genai import types
from .structures import OutputMessage
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 надо? мне просто каж что судя по всему вот эта нам
response_schema=list[
OutputMessage
], # ты уверен что там json надо? мне просто каж что судя по всему вот эта нам
safety_settings=[
types.SafetySetting(
category=category,
threshold=types.HarmBlockThreshold.OFF
)
types.SafetySetting(category=category, threshold=types.HarmBlockThreshold.OFF)
for category in types.HarmCategory
]
],
)
@@ -28,15 +27,12 @@ TTS_CONTENT_CONFIG = types.GenerateContentConfig(
speech_config=types.SpeechConfig(
voice_config=types.VoiceConfig(
prebuilt_voice_config=types.PrebuiltVoiceConfig(
voice_name='Kore',
voice_name="Kore",
)
)
),
safety_settings=[
types.SafetySetting(
category=category,
threshold=types.HarmBlockThreshold.OFF
)
types.SafetySetting(category=category, threshold=types.HarmBlockThreshold.OFF)
for category in types.HarmCategory
]
],
)

View File

@@ -1,2 +1,2 @@
from .input_message import InputMessage
from .output_message import OutputMessage
from .output_message import OutputMessage

View File

@@ -1,10 +1,14 @@
from pydantic import BaseModel
from typing import Optional
from pydantic import BaseModel
class InputMessage(BaseModel):
time: str
message_id: int
text: str
user_id: int
username: Optional[str] # хуйня я не помню зачем жт надо, наверное first_name важнее будет
reply_to: Optional[int]
username: Optional[
str
] # хуйня я не помню зачем жт надо, наверное first_name важнее будет
reply_to: Optional[int]

View File

@@ -1,16 +1,19 @@
from pydantic import BaseModel
from typing import Optional
from pydantic import BaseModel
class OutputMessage(BaseModel):
priority: int # удалишь там есличе
priority: int # удалишь там есличе
text: Optional[str]
reaction: Optional[str]
reply_to: Optional[int]
@classmethod
def fromdict(cls, data: dict):
return cls(
priority = data.get('priority'),
text = data.get('text'),
reaction = data.get('reaction'),
reply_to = data.get('reply_to')
)
priority=data.get("priority"),
text=data.get("text"),
reaction=data.get("reaction"),
reply_to=data.get("reply_to"),
)