added structured output

This commit is contained in:
shinrei
2025-07-01 16:05:01 +00:00
parent 2fee90f07d
commit be2e6dc50b

View File

@@ -2,7 +2,6 @@ import json
from google import genai
from google.genai.types import GenerateContentConfig, ThinkingConfig
from .structures import InputMessage, OutputMessage
from typing import List
from dataclasses import asdict
class SolarisClient:
@@ -15,12 +14,18 @@ class SolarisClient:
thinking_config=ThinkingConfig(thinking_budget=0),
),
)
async def send_messages(self, messages: List[InputMessage]):
async def send_messages(self, messages: list[InputMessage]) -> list[OutputMessage]:
data = json.dumps(
[asdict(msg) for msg in messages], # хм а asdict с датаклассов ваще можно юзать с НЕ датакласами но чем-то датаклассоподобным
ensure_ascii=True
)
resp = await self.chat.send_message(data)
resp = await self.chat.send_message(
data,
config = {
"response_mime_type": "application/json",
"response_schema": list[OutputMessage],
}
)
output_messages = [
OutputMessage.fromdict(msg)
for msg in json.loads(resp.text)