replaced init method to pydantic one
This commit is contained in:
@@ -18,5 +18,7 @@ class SolarisClient:
|
|||||||
async def send_messages(self, messages: list[InputMessage]) -> list[OutputMessage]:
|
async def send_messages(self, messages: list[InputMessage]) -> list[OutputMessage]:
|
||||||
data = json.dumps([msg.model_dump() for msg in messages], ensure_ascii=True)
|
data = json.dumps([msg.model_dump() for msg in messages], ensure_ascii=True)
|
||||||
resp = await self.chat.send_message(data, config=MESSAGE_CONTENT_CONFIG)
|
resp = await self.chat.send_message(data, config=MESSAGE_CONTENT_CONFIG)
|
||||||
output_messages = [OutputMessage.fromdict(msg) for msg in json.loads(resp.text)]
|
output_messages = [
|
||||||
|
OutputMessage.model_validate(msg) for msg in json.loads(resp.text)
|
||||||
|
]
|
||||||
return output_messages
|
return output_messages
|
||||||
|
|||||||
@@ -8,12 +8,3 @@ class OutputMessage(BaseModel):
|
|||||||
text: Optional[str]
|
text: Optional[str]
|
||||||
reaction: Optional[str]
|
reaction: Optional[str]
|
||||||
reply_to: Optional[int]
|
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