Generate a response from the language model, supporting image update triggers.
| Parameters: |
-
messages
(List[Message])
–
The chat history/messages.
|
| Returns: |
-
–
Tuple[str|dict, Any]: The response content (str or dict if image update) and metadata.
|
Source code in llm_utils/aiweb_common/generate/ChatServicer.py
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 | def generate_langchain_response(self, messages):
"""
Generate a response from the language model, supporting image update triggers.
Args:
messages (List[Message]): The chat history/messages.
Returns:
Tuple[str|dict, Any]: The response content (str or dict if image update) and metadata.
"""
chain = self.assembled_system_chat_template | self.language_model_interface
with get_openai_callback() as response_meta:
response = chain.invoke({"messages": messages})
# If the response contains an image update, encode as dict
# Convention: If response has 'image_update' attribute, return dict
if hasattr(response, "image_update") and response.image_update is not None:
return {
"text": response.content,
"image_update": response.image_update
}, response_meta
return response.content, response_meta
|