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 import json
from google import genai
from .structures import InputMessage, OutputMessage
from dataclasses import asdict from dataclasses import asdict
from google import genai
from .content_configs import MAIN_CONTENT_CONFIG, MESSAGE_CONTENT_CONFIG from .content_configs import MAIN_CONTENT_CONFIG, MESSAGE_CONTENT_CONFIG
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( self.chat = client.chats.create(
model="gemini-2.5-flash", model="gemini-2.5-flash", config=MAIN_CONTENT_CONFIG
config=MAIN_CONTENT_CONFIG
) )
# self.tts # self.tts
async def send_messages(self, messages: list[InputMessage]) -> list[OutputMessage]: async def send_messages(self, messages: list[InputMessage]) -> list[OutputMessage]:
data = json.dumps( data = json.dumps([msg.model_dump() for msg in messages], ensure_ascii=True)
[msg.model_dump() for msg in messages], resp = await self.chat.send_message(data, config=MESSAGE_CONTENT_CONFIG)
ensure_ascii=True output_messages = [OutputMessage.fromdict(msg) for msg in json.loads(resp.text)]
)
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 return output_messages

View File

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

View File

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

View File

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