mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-09-06 17:57:49 +02:00
release(sdk-py): use v0.2.0a1 for testing with sdk (#5621)
This commit is contained in:
@@ -313,19 +313,21 @@
|
||||
" k: int\n",
|
||||
" beam_size: int\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"class EnsuredContext(TypedDict):\n",
|
||||
" max_depth: int\n",
|
||||
" threshold: float\n",
|
||||
" k: int\n",
|
||||
" beam_size: int\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def _ensure_context(ctx: Context) -> EnsuredContext:\n",
|
||||
" \"\"\"Get params that configure the search algorithm.\"\"\"\n",
|
||||
" return {\n",
|
||||
" \"max_depth\": ctx.get(\"max_depth\", 10),\n",
|
||||
" \"threshold\": ctx.get(\"threshold\", 0.9),\n",
|
||||
" \"k\": ctx.get(\"k\", 5),\n",
|
||||
" \"beam_size\": ctx.get(\"beam_size\", 3)\n",
|
||||
" \"beam_size\": ctx.get(\"beam_size\", 3),\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
"\n",
|
||||
@@ -333,7 +335,9 @@
|
||||
" seed: Optional[Candidate]\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def expand(state: ExpansionState, *, runtime: Runtime[Context]) -> Dict[str, List[Candidate]]:\n",
|
||||
"def expand(\n",
|
||||
" state: ExpansionState, *, runtime: Runtime[Context]\n",
|
||||
") -> Dict[str, List[Candidate]]:\n",
|
||||
" \"\"\"Generate the next state.\"\"\"\n",
|
||||
" ctx = _ensure_context(runtime.context)\n",
|
||||
" if not state.get(\"seed\"):\n",
|
||||
@@ -365,9 +369,7 @@
|
||||
" return {\"scored_candidates\": scored, \"candidates\": \"clear\"}\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def prune(\n",
|
||||
" state: ToTState, *, runtime: Runtime[Context]\n",
|
||||
") -> Dict[str, Any]:\n",
|
||||
"def prune(state: ToTState, *, runtime: Runtime[Context]) -> Dict[str, Any]:\n",
|
||||
" scored_candidates = state[\"scored_candidates\"]\n",
|
||||
" beam_size = _ensure_context(runtime.context)[\"beam_size\"]\n",
|
||||
" organized = sorted(\n",
|
||||
@@ -469,7 +471,11 @@
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"for step in graph.stream({\"problem\": puzzles[42]}, config={\"configurable\": {\"thread_id\": \"test_1\"}}, context={\"depth\": 10}):\n",
|
||||
"for step in graph.stream(\n",
|
||||
" {\"problem\": puzzles[42]},\n",
|
||||
" config={\"configurable\": {\"thread_id\": \"test_1\"}},\n",
|
||||
" context={\"depth\": 10},\n",
|
||||
"):\n",
|
||||
" print(step)"
|
||||
]
|
||||
},
|
||||
@@ -487,7 +493,7 @@
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"final_state = graph.get_state({'configurable': {'thread_id': 'test_1'}})\n",
|
||||
"final_state = graph.get_state({\"configurable\": {\"thread_id\": \"test_1\"}})\n",
|
||||
"winning_solution = final_state.values[\"candidates\"][0]\n",
|
||||
"search_depth = final_state.values[\"depth\"]\n",
|
||||
"if winning_solution[1] == 1:\n",
|
||||
|
||||
Reference in New Issue
Block a user