Skip to content

Commit

Permalink
updated configuration doc
Browse files Browse the repository at this point in the history
  • Loading branch information
bracesproul committed Aug 19, 2024
1 parent 3cdee7b commit cc6d3b5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 62 deletions.
20 changes: 9 additions & 11 deletions examples/how-tos/breakpoints.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 8,
"id": "6098e5cb",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -299,7 +299,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 9,
"id": "4476aef1",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -335,7 +335,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 10,
"id": "cfd140f0-a5a6-4697-8115-322242f197b5",
"metadata": {},
"outputs": [
Expand All @@ -349,11 +349,11 @@
"[\n",
" {\n",
" type: 'text',\n",
" text: \"Certainly! I'll search for the current weather in San Francisco for you. Let me use the search function to find this information.\"\n",
" text: \"Certainly! I'll search for the current weather in San Francisco for you using the search function. Let me do that right away.\"\n",
" },\n",
" {\n",
" type: 'tool_use',\n",
" id: 'toolu_018UxZU1fXTwq9sndFcYY19z',\n",
" id: 'toolu_01XsoaWr4EFgzEQ2x3EgVMdJ',\n",
" name: 'search',\n",
" input: { input: 'current weather in San Francisco' }\n",
" }\n",
Expand Down Expand Up @@ -394,7 +394,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 11,
"id": "51923913-20f7-4ee1-b9ba-d01f5fb2869b",
"metadata": {},
"outputs": [
Expand All @@ -407,13 +407,11 @@
"================================ ai Message (1) =================================\n",
"Based on the search results, I can provide you with information about the current weather in San Francisco:\n",
"\n",
"The weather in San Francisco is currently sunny. This means it's a clear day with good visibility and likely comfortable temperatures. \n",
"The weather in San Francisco is currently sunny. This means it's a clear day with plenty of sunshine. It's a great day to be outdoors if you have any plans!\n",
"\n",
"However, the search result also includes an unusual comment about Geminis, which doesn't seem directly related to the weather. This appears to be some kind of joke or astrological reference that was included in the search results, but it's not relevant to the actual weather conditions.\n",
"However, the search result also includes an unusual statement about Geminis. This appears to be unrelated to the weather and might be a joke or a reference to an astrological forecast that was mixed in with the weather information. I would advise focusing on the weather information, which is what you asked about.\n",
"\n",
"To summarize: The current weather in San Francisco is sunny, which generally means good conditions for outdoor activities. If you're planning to go out, it would be a good idea to wear sunscreen and perhaps sunglasses to protect yourself from the sun's rays.\n",
"\n",
"Is there any other specific information about the weather in San Francisco that you'd like to know? I can search for more details such as temperature, humidity, or forecast if you're interested.\n"
"Is there anything else you'd like to know about the weather in San Francisco or any other location?\n"
]
}
],
Expand Down
71 changes: 20 additions & 51 deletions examples/how-tos/configuration.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,12 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 1,
"id": "bdf2fe0f",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"[WARN]: You have enabled LangSmith tracing without backgrounding callbacks.\n",
"[WARN]: If you are not using a serverless environment where you must wait for tracing calls to finish,\n",
"[WARN]: we suggest setting \"process.env.LANGCHAIN_CALLBACKS_BACKGROUND=true\" to avoid additional latency.\n"
]
}
],
"outputs": [],
"source": [
"import { BaseMessage, HumanMessage } from \"@langchain/core/messages\";\n",
"import { BaseMessage } from \"@langchain/core/messages\";\n",
"import { ChatOpenAI } from \"@langchain/openai\";\n",
"import { ChatAnthropic } from \"@langchain/anthropic\";\n",
"import { ChatPromptTemplate } from \"@langchain/core/prompts\";\n",
Expand All @@ -93,35 +83,28 @@
" MemorySaver,\n",
" START,\n",
" StateGraph,\n",
" StateGraphArgs,\n",
" Annotation,\n",
"} from \"@langchain/langgraph\";\n",
"\n",
"interface IState {\n",
" messages: BaseMessage[];\n",
" userInfo: string;\n",
"}\n",
"\n",
"// This defines the agent state\n",
"const graphState: StateGraphArgs<IState>[\"channels\"] = {\n",
" messages: {\n",
" value: (x: BaseMessage[], y: BaseMessage[]) => x.concat(y),\n",
" default: () => [],\n",
" },\n",
" userInfo: {\n",
" value: (x?: string, y?: string) => {\n",
"const AgentState = Annotation.Root({\n",
" messages: Annotation<BaseMessage[]>({\n",
" reducer: (x, y) => x.concat(y),\n",
" }),\n",
" userInfo: Annotation<string | undefined>({\n",
" reducer: (x, y) => {\n",
" return y ? y : x ? x : \"N/A\";\n",
" },\n",
" default: () => \"N/A\",\n",
" },\n",
"};\n",
" })\n",
"});\n",
"\n",
"const promptTemplate = ChatPromptTemplate.fromMessages([\n",
" [\"system\", \"You are a helpful assistant.\\n\\n## User Info:\\n{userInfo}\"],\n",
" [\"placeholder\", \"{messages}\"],\n",
"]);\n",
"\n",
"const callModel = async (\n",
" state: { messages: BaseMessage[]; userInfo: string },\n",
" state: typeof AgentState.State,\n",
" config?: RunnableConfig,\n",
") => {\n",
" const { messages, userInfo } = state;\n",
Expand All @@ -141,7 +124,7 @@
"};\n",
"\n",
"const fetchUserInformation = async (\n",
" _: { messages: BaseMessage[] },\n",
" _: typeof AgentState.State,\n",
" config?: RunnableConfig,\n",
") => {\n",
" const userDB = {\n",
Expand Down Expand Up @@ -169,9 +152,7 @@
" return { userInfo: \"N/A\" };\n",
"};\n",
"\n",
"const workflow = new StateGraph<IState>({\n",
" channels: graphState,\n",
"})\n",
"const workflow = new StateGraph(AgentState)\n",
" .addNode(\"fetchUserInfo\", fetchUserInformation)\n",
" .addNode(\"agent\", callModel)\n",
" .addEdge(START, \"fetchUserInfo\")\n",
Expand Down Expand Up @@ -207,13 +188,15 @@
"Could you remind me of my email??\n",
"-----\n",
"\n",
"Of course, John. Your email is [email protected].\n",
"Sure, John. Your email is [email protected].\n",
"-----\n",
"\n"
]
}
],
"source": [
"import { HumanMessage } from \"@langchain/core/messages\";\n",
"\n",
"const config = {\n",
" configurable: {\n",
" model: \"openai\",\n",
Expand Down Expand Up @@ -266,14 +249,8 @@
"\n",
"Could you remind me of my email??\n",
"-----\n",
"\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Certainly, Jane. Your email is [email protected].\n",
"\n",
"Sure, Jane. Your email is [email protected].\n",
"-----\n",
"\n"
]
Expand Down Expand Up @@ -307,14 +284,6 @@
"}"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "88d8db9c",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "f000b97c",
Expand Down

0 comments on commit cc6d3b5

Please sign in to comment.