From be2e6dc50bddb14ad970846e9e8a108341cc6df4 Mon Sep 17 00:00:00 2001 From: shinrei Date: Tue, 1 Jul 2025 16:05:01 +0000 Subject: [PATCH] added structured output --- src/bot/modules/solaris/client.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/bot/modules/solaris/client.py b/src/bot/modules/solaris/client.py index a4fdf87..30252db 100644 --- a/src/bot/modules/solaris/client.py +++ b/src/bot/modules/solaris/client.py @@ -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)