mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-08-31 20:29:46 +02:00
[Docs] use END instead of set_finish_point (#903)
This commit is contained in:
@@ -129,6 +129,7 @@
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from langchain_openai import ChatOpenAI\n",
|
||||
"\n",
|
||||
"model_tested = \"gpt-4o\"\n",
|
||||
"metadata = \"CRAG, gpt-4o\"\n",
|
||||
"llm = ChatOpenAI(model_name=model_tested, temperature=0)"
|
||||
@@ -150,6 +151,7 @@
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from langchain_fireworks import ChatFireworks\n",
|
||||
"\n",
|
||||
"model_tested = \"firefunction-v2\"\n",
|
||||
"metadata = \"CRAG, firefunction-v\"\n",
|
||||
"llm = ChatFireworks(model=\"accounts/fireworks/models/firefunction-v2\", temperature=0)"
|
||||
@@ -344,9 +346,9 @@
|
||||
"source": [
|
||||
"@tool\n",
|
||||
"def generate_answer(answer: str) -> str:\n",
|
||||
" \"\"\"You are an assistant for question-answering tasks. \n",
|
||||
" Use the retrieved documents to answer the user question. \n",
|
||||
" If you don't know the answer, just say that you don't know. \n",
|
||||
" \"\"\"You are an assistant for question-answering tasks.\n",
|
||||
" Use the retrieved documents to answer the user question.\n",
|
||||
" If you don't know the answer, just say that you don't know.\n",
|
||||
" Use three sentences maximum and keep the answer concise\"\"\"\n",
|
||||
" return f\"Here is the answer to the user question: {answer}\""
|
||||
]
|
||||
@@ -439,7 +441,7 @@
|
||||
" (\n",
|
||||
" \"system\",\n",
|
||||
" \" You are a helpful assistant tasked with answering user questions using the provided vector store. \"\n",
|
||||
" \" Use the provided vector store to retrieve documents. Then grade them to ensure they are relevant before answering the question. \"\n",
|
||||
" \" Use the provided vector store to retrieve documents. Then grade them to ensure they are relevant before answering the question. \",\n",
|
||||
" ),\n",
|
||||
" (\"placeholder\", \"{messages}\"),\n",
|
||||
" ]\n",
|
||||
@@ -629,7 +631,8 @@
|
||||
" ]\n",
|
||||
" return tool_calls\n",
|
||||
"\n",
|
||||
"find_tool_calls_react(response['messages'])"
|
||||
"\n",
|
||||
"find_tool_calls_react(response[\"messages\"])"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -1080,6 +1083,7 @@
|
||||
"# Grade prompt\n",
|
||||
"grade_prompt_answer_accuracy = hub.pull(\"langchain-ai/rag-answer-vs-reference\")\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def answer_evaluator(run, example) -> dict:\n",
|
||||
" \"\"\"\n",
|
||||
" A simple evaluator for RAG answer accuracy\n",
|
||||
@@ -1140,6 +1144,7 @@
|
||||
" \"generate_answer\",\n",
|
||||
"]\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def check_trajectory_react(root_run: Run, example: Example) -> dict:\n",
|
||||
" \"\"\"\n",
|
||||
" Check if all expected tools are called in exact order and without any additional tool calls.\n",
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -190,7 +190,7 @@
|
||||
"id": "f1f97ea4-53e5-4f55-8d73-b5b2234a47d9",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": ["from langgraph.graph import StateGraph, START\n\ngraph = StateGraph(TaxonomyGenerationState)\ngraph.add_node(\"summarize\", map_reduce_chain)\ngraph.add_node(\"get_minibatches\", get_minibatches)\ngraph.add_node(\"generate_taxonomy\", generate_taxonomy)\ngraph.add_node(\"update_taxonomy\", update_taxonomy)\ngraph.add_node(\"review_taxonomy\", review_taxonomy)\n\ngraph.add_edge(\"summarize\", \"get_minibatches\")\ngraph.add_edge(\"get_minibatches\", \"generate_taxonomy\")\ngraph.add_edge(\"generate_taxonomy\", \"update_taxonomy\")\n\n\ndef should_review(state: TaxonomyGenerationState) -> str:\n num_minibatches = len(state[\"minibatches\"])\n num_revisions = len(state[\"clusters\"])\n if num_revisions < num_minibatches:\n return \"update_taxonomy\"\n return \"review_taxonomy\"\n\n\ngraph.add_conditional_edges(\n \"update_taxonomy\",\n should_review,\n # Optional (but required for the diagram to be drawn correctly below)\n {\"update_taxonomy\": \"update_taxonomy\", \"review_taxonomy\": \"review_taxonomy\"},\n)\ngraph.set_finish_point(\"review_taxonomy\")\n\ngraph.add_edge(START, \"summarize\")\napp = graph.compile()"]
|
||||
"source": ["from langgraph.graph import StateGraph, START, END\n\ngraph = StateGraph(TaxonomyGenerationState)\ngraph.add_node(\"summarize\", map_reduce_chain)\ngraph.add_node(\"get_minibatches\", get_minibatches)\ngraph.add_node(\"generate_taxonomy\", generate_taxonomy)\ngraph.add_node(\"update_taxonomy\", update_taxonomy)\ngraph.add_node(\"review_taxonomy\", review_taxonomy)\n\ngraph.add_edge(\"summarize\", \"get_minibatches\")\ngraph.add_edge(\"get_minibatches\", \"generate_taxonomy\")\ngraph.add_edge(\"generate_taxonomy\", \"update_taxonomy\")\n\n\ndef should_review(state: TaxonomyGenerationState) -> str:\n num_minibatches = len(state[\"minibatches\"])\n num_revisions = len(state[\"clusters\"])\n if num_revisions < num_minibatches:\n return \"update_taxonomy\"\n return \"review_taxonomy\"\n\n\ngraph.add_conditional_edges(\n \"update_taxonomy\",\n should_review,\n # Optional (but required for the diagram to be drawn correctly below)\n {\"update_taxonomy\": \"update_taxonomy\", \"review_taxonomy\": \"review_taxonomy\"},\n)\ngraph.add_edge(\"review_taxonomy\", END)\n\ngraph.add_edge(START, \"summarize\")\napp = graph.compile()"]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
|
||||
Reference in New Issue
Block a user