Add support for message conversion in ChatOutputResponse class
This commit is contained in:
parent
5277798cca
commit
7eac47f4c8
1 changed files with 10 additions and 2 deletions
|
|
@ -1,10 +1,18 @@
|
|||
from typing import Dict, List, Optional, Union
|
||||
|
||||
from langchain_core.messages import BaseMessage
|
||||
from pydantic import BaseModel
|
||||
from typing import Optional
|
||||
|
||||
|
||||
class ChatOutputResponse(BaseModel):
|
||||
"""Chat output response schema."""
|
||||
|
||||
message: str
|
||||
message: Union[str, List[Union[str, Dict]]]
|
||||
sender: Optional[str] = "Machine"
|
||||
sender_name: Optional[str] = "AI"
|
||||
|
||||
@classmethod
|
||||
def from_message(cls, message: BaseMessage, sender: Optional[str] = "Machine", sender_name: Optional[str] = "AI"):
|
||||
"""Build chat output response from message."""
|
||||
content = message.content
|
||||
return cls(message=content, sender=sender, sender_name=sender_name)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue