mirror of
https://github.com/hwchase17/langchain.git
synced 2025-08-10 05:20:39 +00:00
cr
This commit is contained in:
parent
7e740e5e1f
commit
3460c48af6
@ -213,31 +213,23 @@ class AIMessage(BaseMessage):
|
|||||||
otherwise, does best-effort parsing to standard types.
|
otherwise, does best-effort parsing to standard types.
|
||||||
"""
|
"""
|
||||||
blocks: list[types.ContentBlock] = []
|
blocks: list[types.ContentBlock] = []
|
||||||
if isinstance(self.content, str):
|
content = [self.content] if isinstance(self.content, str) else self.content
|
||||||
if self.content:
|
for item in content:
|
||||||
blocks.append({"type": "text", "text": self.content})
|
if isinstance(item, str):
|
||||||
|
blocks.append({"type": "text", "text": item})
|
||||||
|
|
||||||
|
elif isinstance(item, dict):
|
||||||
|
item_type = item.get("type")
|
||||||
|
if item_type not in types.KNOWN_BLOCK_TYPES:
|
||||||
|
msg = (
|
||||||
|
f"Non-standard content block type '{item_type}'. Ensure "
|
||||||
|
"the model supports `output_version='v1'` or higher and "
|
||||||
|
"that this attribute is set on initialization."
|
||||||
|
)
|
||||||
|
raise ValueError(msg)
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
elif isinstance(self.content, list):
|
|
||||||
for item in self.content:
|
|
||||||
if isinstance(item, str):
|
|
||||||
blocks.append({"type": "text", "text": item})
|
|
||||||
|
|
||||||
elif isinstance(item, dict):
|
|
||||||
item_type = item.get("type")
|
|
||||||
if item_type not in types.KNOWN_BLOCK_TYPES:
|
|
||||||
msg = (
|
|
||||||
f"Non-standard content block type '{item_type}'. Ensure "
|
|
||||||
"the model supports `output_version='v1'` or higher and "
|
|
||||||
"that this attribute is set on initialization."
|
|
||||||
)
|
|
||||||
raise ValueError(msg)
|
|
||||||
else:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
pass
|
|
||||||
|
|
||||||
# Add from tool_calls if missing from content
|
# Add from tool_calls if missing from content
|
||||||
content_tool_call_ids = {
|
content_tool_call_ids = {
|
||||||
block.get("id")
|
block.get("id")
|
||||||
|
@ -156,7 +156,7 @@ _DataContentBlockAdapter: TypeAdapter[DataContentBlock] = TypeAdapter(DataConten
|
|||||||
|
|
||||||
|
|
||||||
# Non-standard
|
# Non-standard
|
||||||
class NonStandardContentBlock(TypedDict, total=False):
|
class NonStandardContentBlock(TypedDict):
|
||||||
"""Content block provider-specific data.
|
"""Content block provider-specific data.
|
||||||
|
|
||||||
This block contains data for which there is not yet a standard type.
|
This block contains data for which there is not yet a standard type.
|
||||||
|
Loading…
Reference in New Issue
Block a user