mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-28 09:28:48 +00:00
community: fix CI (#21766)
This commit is contained in:
parent
dda5a9c97a
commit
19e6bf814b
@ -119,7 +119,7 @@ def convert_dict_to_message(
|
|||||||
AIMessageChunk(
|
AIMessageChunk(
|
||||||
content=content,
|
content=content,
|
||||||
additional_kwargs=additional_kwargs,
|
additional_kwargs=additional_kwargs,
|
||||||
tool_call_chunks=tool_calls,
|
tool_call_chunks=tool_calls, # type: ignore[arg-type]
|
||||||
id=_dict.get("id"),
|
id=_dict.get("id"),
|
||||||
)
|
)
|
||||||
if is_chunk
|
if is_chunk
|
||||||
@ -143,13 +143,13 @@ def convert_dict_to_message(
|
|||||||
return (
|
return (
|
||||||
ToolMessageChunk(
|
ToolMessageChunk(
|
||||||
content=_dict.get("content", ""),
|
content=_dict.get("content", ""),
|
||||||
tool_call_id=_dict.get("tool_call_id"),
|
tool_call_id=_dict.get("tool_call_id"), # type: ignore[arg-type]
|
||||||
additional_kwargs=additional_kwargs,
|
additional_kwargs=additional_kwargs,
|
||||||
)
|
)
|
||||||
if is_chunk
|
if is_chunk
|
||||||
else ToolMessage(
|
else ToolMessage(
|
||||||
content=_dict.get("content", ""),
|
content=_dict.get("content", ""),
|
||||||
tool_call_id=_dict.get("tool_call_id"),
|
tool_call_id=_dict.get("tool_call_id"), # type: ignore[arg-type]
|
||||||
additional_kwargs=additional_kwargs,
|
additional_kwargs=additional_kwargs,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -151,9 +151,11 @@ class GenerateUsername(BaseModel):
|
|||||||
|
|
||||||
|
|
||||||
def test_tool_use() -> None:
|
def test_tool_use() -> None:
|
||||||
llm = ChatTongyi(model="qwen-turbo", temperature=0)
|
llm = ChatTongyi(model="qwen-turbo", temperature=0) # type: ignore
|
||||||
llm_with_tool = llm.bind_tools(tools=[GenerateUsername])
|
llm_with_tool = llm.bind_tools(tools=[GenerateUsername])
|
||||||
msgs: List = [HumanMessage("Sally has green hair, what would her username be?")]
|
msgs: List = [
|
||||||
|
HumanMessage(content="Sally has green hair, what would her username be?")
|
||||||
|
]
|
||||||
ai_msg = llm_with_tool.invoke(msgs)
|
ai_msg = llm_with_tool.invoke(msgs)
|
||||||
# assert ai_msg is None
|
# assert ai_msg is None
|
||||||
# ai_msg.content = " "
|
# ai_msg.content = " "
|
||||||
@ -165,8 +167,8 @@ def test_tool_use() -> None:
|
|||||||
assert "args" in tool_call
|
assert "args" in tool_call
|
||||||
|
|
||||||
tool_msg = ToolMessage(
|
tool_msg = ToolMessage(
|
||||||
"sally_green_hair",
|
content="sally_green_hair",
|
||||||
tool_call_id=ai_msg.tool_calls[0]["id"],
|
tool_call_id=ai_msg.tool_calls[0]["id"], # type: ignore
|
||||||
name=ai_msg.tool_calls[0]["name"],
|
name=ai_msg.tool_calls[0]["name"],
|
||||||
)
|
)
|
||||||
msgs.extend([ai_msg, tool_msg])
|
msgs.extend([ai_msg, tool_msg])
|
||||||
@ -184,7 +186,7 @@ def test_tool_use() -> None:
|
|||||||
assert isinstance(gathered, AIMessageChunk)
|
assert isinstance(gathered, AIMessageChunk)
|
||||||
|
|
||||||
streaming_tool_msg = ToolMessage(
|
streaming_tool_msg = ToolMessage(
|
||||||
"sally_green_hair",
|
content="sally_green_hair",
|
||||||
name=tool_call["name"],
|
name=tool_call["name"],
|
||||||
tool_call_id=tool_call["id"] if tool_call["id"] else " ",
|
tool_call_id=tool_call["id"] if tool_call["id"] else " ",
|
||||||
)
|
)
|
||||||
@ -194,10 +196,10 @@ def test_tool_use() -> None:
|
|||||||
|
|
||||||
def test_manual_tool_call_msg() -> None:
|
def test_manual_tool_call_msg() -> None:
|
||||||
"""Test passing in manually construct tool call message."""
|
"""Test passing in manually construct tool call message."""
|
||||||
llm = ChatTongyi(model="qwen-turbo", temperature=0)
|
llm = ChatTongyi(model="qwen-turbo", temperature=0) # type: ignore
|
||||||
llm_with_tool = llm.bind_tools(tools=[GenerateUsername])
|
llm_with_tool = llm.bind_tools(tools=[GenerateUsername])
|
||||||
msgs: List = [
|
msgs: List = [
|
||||||
HumanMessage("Sally has green hair, what would her username be?"),
|
HumanMessage(content="Sally has green hair, what would her username be?"),
|
||||||
AIMessage(
|
AIMessage(
|
||||||
content=" ",
|
content=" ",
|
||||||
tool_calls=[
|
tool_calls=[
|
||||||
@ -208,7 +210,7 @@ def test_manual_tool_call_msg() -> None:
|
|||||||
)
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
ToolMessage("sally_green_hair", tool_call_id="foo"),
|
ToolMessage(content="sally_green_hair", tool_call_id="foo"),
|
||||||
]
|
]
|
||||||
output: AIMessage = cast(AIMessage, llm_with_tool.invoke(msgs))
|
output: AIMessage = cast(AIMessage, llm_with_tool.invoke(msgs))
|
||||||
assert output.content
|
assert output.content
|
||||||
|
Loading…
Reference in New Issue
Block a user