out msg
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import json
|
||||
from google import genai
|
||||
from google.genai.types import GenerateContentConfig, ThinkingConfig
|
||||
|
||||
from .structures import InputMessage, OutputMessage
|
||||
from typing import List
|
||||
|
||||
class SolarisClient:
|
||||
def __init__(self, api_key: str) -> None:
|
||||
@@ -12,3 +14,15 @@ class SolarisClient:
|
||||
thinking_config=ThinkingConfig(thinking_budget=0),
|
||||
),
|
||||
)
|
||||
async def send_messages(self, messages: List[InputMessage]):
|
||||
data = json.dumps(
|
||||
[asdict(msg) for msg in messages],
|
||||
ensure_ascii=True
|
||||
)
|
||||
resp = await self.chat.send_message(data)
|
||||
print(resp.text)
|
||||
output_messages = [
|
||||
OutputMessage.fromdict(msg)
|
||||
for msg in json.loads(resp.text)
|
||||
]
|
||||
return output_messages
|
||||
2
src/bot/modules/solaris/structures/__init__.py
Normal file
2
src/bot/modules/solaris/structures/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
from .input_message import InputMessage
|
||||
from .output_message import OutputMessage
|
||||
16
src/bot/modules/solaris/structures/output_message.py
Normal file
16
src/bot/modules/solaris/structures/output_message.py
Normal file
@@ -0,0 +1,16 @@
|
||||
from pydantic import BaseModel
|
||||
from typing import Optional
|
||||
|
||||
class OutputMessage(BaseModel):
|
||||
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')
|
||||
)
|
||||
Reference in New Issue
Block a user