1
有用LangChain/LangGraph集成的例子么?
大模型开发/互助问答
- LLM
- 文心大模型
5月23日991看过
from langchain_core.messages import AnyMessagefrom langgraph.errors import GraphRecursionErrorfrom langgraph.prebuilt import create_react_agentfrom langchain.tools import toolfrom langchain_community.chat_models import QianfanChatEndpointchat = QianfanChatEndpoint(model="ERNIE-3.5-8K", stream=False)magic_step_num = 1@tooldef magic_function(input: int) -> int:"""Applies a magic function to an input."""global magic_step_numprint(f"Call number: {magic_step_num}")magic_step_num += 1return input + magic_step_numtools = [magic_function]def _modify_messages(messages: list[AnyMessage]):# Give the agent amnesia, only keeping the original user queryreturn [("system", "You are a helpful assistant"), messages[0]]app = create_react_agent(model=chat, tools=tools, messages_modifier=_modify_messages)#%%query = "Call the magic function 4 times in sequence with the value 3. You cannot call it multiple times at once."try:for step in app.stream({"messages": [("human", query)]}, stream_mode="updates"):print(step)except GraphRecursionError as e:print("Stopping agent prematurely due to triggering stop condition")
上面代码照着官网照葫芦画瓢的,跑不通哇
tool_call_id
none is not an allowed value (type=type_error.none.not_allowed)
有没有现成跑得通的Function Call例子
评论