mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-10-01 22:15:11 +02:00
Update notebooks to use bind_tools (#394)
This commit is contained in:
@@ -83,6 +83,7 @@
|
||||
"\n",
|
||||
"class PromptInstructions(BaseModel):\n",
|
||||
" \"\"\"Instructions on how to prompt the LLM.\"\"\"\n",
|
||||
"\n",
|
||||
" objective: str\n",
|
||||
" variables: List[str]\n",
|
||||
" constraints: List[str]\n",
|
||||
@@ -121,7 +122,7 @@
|
||||
"source": [
|
||||
"# Helper function for determining if tool was called\n",
|
||||
"def _is_tool_call(msg):\n",
|
||||
" return hasattr(msg, \"additional_kwargs\") and 'tool_calls' in msg.additional_kwargs"
|
||||
" return hasattr(msg, \"additional_kwargs\") and \"tool_calls\" in msg.additional_kwargs"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -136,6 +137,7 @@
|
||||
"\n",
|
||||
"{reqs}\"\"\"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# Function to get the messages for the prompt\n",
|
||||
"# Will only get messages AFTER the tool call\n",
|
||||
"def get_prompt_messages(messages):\n",
|
||||
@@ -143,11 +145,10 @@
|
||||
" other_msgs = []\n",
|
||||
" for m in messages:\n",
|
||||
" if _is_tool_call(m):\n",
|
||||
" tool_call = m.additional_kwargs['tool_calls'][0]['function']['arguments']\n",
|
||||
" tool_call = m.additional_kwargs[\"tool_calls\"][0][\"function\"][\"arguments\"]\n",
|
||||
" elif tool_call is not None:\n",
|
||||
" other_msgs.append(m)\n",
|
||||
" return [SystemMessage(content=prompt_system.format(reqs=tool_call))] + other_msgs\n",
|
||||
" "
|
||||
" return [SystemMessage(content=prompt_system.format(reqs=tool_call))] + other_msgs"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -215,7 +216,7 @@
|
||||
"\n",
|
||||
"memory = SqliteSaver.from_conn_string(\":memory:\")\n",
|
||||
"\n",
|
||||
"nodes = {k:k for k in ['info', 'prompt', END]}\n",
|
||||
"nodes = {k: k for k in [\"info\", \"prompt\", END]}\n",
|
||||
"workflow = MessageGraph()\n",
|
||||
"workflow.add_node(\"info\", chain)\n",
|
||||
"workflow.add_node(\"prompt\", prompt_gen_chain)\n",
|
||||
@@ -401,9 +402,9 @@
|
||||
"\n",
|
||||
"config = {\"configurable\": {\"thread_id\": str(uuid.uuid4())}}\n",
|
||||
"while True:\n",
|
||||
" user = input('User (q/Q to quit): ')\n",
|
||||
" if user in {'q', 'Q'}:\n",
|
||||
" print('AI: Byebye')\n",
|
||||
" user = input(\"User (q/Q to quit): \")\n",
|
||||
" if user in {\"q\", \"Q\"}:\n",
|
||||
" print(\"AI: Byebye\")\n",
|
||||
" break\n",
|
||||
" for output in graph.stream([HumanMessage(content=user)], config=config):\n",
|
||||
" if \"__end__\" in output:\n",
|
||||
|
||||
Reference in New Issue
Block a user