mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-09-10 03:37:51 +02:00
Update, clean, normalize langgraph RAG ntbks
This commit is contained in:
@@ -22,7 +22,9 @@
|
||||
"* Single-shot RAG\n",
|
||||
"* Iterative RAG\n",
|
||||
"\n",
|
||||
"Let's build on this to perform query analysis to route across some more interesting cases:\n",
|
||||
"Let's build on this using LangGraph. \n",
|
||||
"\n",
|
||||
"In our implementation, we will route between:\n",
|
||||
"\n",
|
||||
"* Web search: for questions related to recent events\n",
|
||||
"* Self-corrective RAG: for questions related to our index\n",
|
||||
@@ -58,7 +60,18 @@
|
||||
"### LLMs\n",
|
||||
"import os\n",
|
||||
"os.environ['OPENAI_API_KEY'] = <your-api-key>\n",
|
||||
"os.environ['COHERE_API_KEY'] = <your-api-key>"
|
||||
"os.environ['COHERE_API_KEY'] = <your-api-key>\n",
|
||||
"os.environ['TAVILY_API_KEY'] = <your-api-key>"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "018c9e9f-8199-4f33-b5b4-7adfb66d6219",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Tracing\n",
|
||||
"\n",
|
||||
"* Optionally, use [LangSmith](https://docs.smith.langchain.com/) for tracing (shown at bottom) by setting: "
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -157,7 +170,6 @@
|
||||
"from langchain_core.prompts import ChatPromptTemplate\n",
|
||||
"from langchain_core.pydantic_v1 import BaseModel, Field\n",
|
||||
"from langchain_openai import ChatOpenAI\n",
|
||||
"### from langchain_cohere import ChatCohere\n",
|
||||
"\n",
|
||||
"# Data model\n",
|
||||
"class RouteQuery(BaseModel):\n",
|
||||
@@ -218,6 +230,7 @@
|
||||
"# Prompt \n",
|
||||
"system = \"\"\"You are a grader assessing relevance of a retrieved document to a user question. \\n \n",
|
||||
" If the document contains keyword(s) or semantic meaning related to the user question, grade it as relevant. \\n\n",
|
||||
" It does not need to be a stringent test. The goal is to filter out erroneous retrievals. \\n\n",
|
||||
" Give a binary score 'yes' or 'no' score to indicate whether the document is relevant to the question.\"\"\"\n",
|
||||
"grade_prompt = ChatPromptTemplate.from_messages(\n",
|
||||
" [\n",
|
||||
@@ -440,7 +453,7 @@
|
||||
"from typing import List\n",
|
||||
"\n",
|
||||
"class GraphState(TypedDict):\n",
|
||||
" \"\"\"|\n",
|
||||
" \"\"\"\n",
|
||||
" Represents the state of our graph.\n",
|
||||
"\n",
|
||||
" Attributes:\n",
|
||||
@@ -673,8 +686,6 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from pprint import pprint\n",
|
||||
"\n",
|
||||
"from langgraph.graph import END, StateGraph\n",
|
||||
"\n",
|
||||
"workflow = StateGraph(GraphState)\n",
|
||||
+363
-271
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user