From 59273f91502e054497f87de623755ac274932662 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D0=B5=D0=BC=20=D0=92=D0=BB=D0=B0=D0=B4?= =?UTF-8?q?=D0=B8=D0=BC=D0=B8=D1=80=D0=BE=D0=B2=D0=B8=D1=87=20=D0=91=D0=B0?= =?UTF-8?q?=D0=B1=D0=B0=D0=B9=D0=BA=D0=B8=D0=BD?= Date: Thu, 28 May 2026 17:04:06 +0000 Subject: [PATCH] feat: solution for 6a047c6ca6fe2e4ac16b35b0 --- .../6a047c6ca6fe2e4ac16b35b0/solution.py | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 solutions/6a047c6ca6fe2e4ac16b35b0/solution.py diff --git a/solutions/6a047c6ca6fe2e4ac16b35b0/solution.py b/solutions/6a047c6ca6fe2e4ac16b35b0/solution.py new file mode 100644 index 0000000..2674186 --- /dev/null +++ b/solutions/6a047c6ca6fe2e4ac16b35b0/solution.py @@ -0,0 +1,74 @@ +from typing import TypedDict, Optional + +from langgraph.graph import StateGraph, START, END +from langgraph.checkpoint.memory import InMemorySaver +from langgraph.types import Command, interrupt +from langchain_openai import ChatOpenAI +from pydantic import SecretStr + + +class GraphState(TypedDict): + human_value: Optional[str] = None + + +llm = ChatOpenAI( + model="openai/gpt-oss-20b", + base_url='https://platform.brojs.ru/jrnl-bh/api/inference/v1', + api_key=SecretStr("jrnl_30283ab953615cbb6846ff9940a1eedce0b76d7b2f59a2394f29e74643e6a90d"), + temperature=0.7, +) + + +def ask(state: GraphState) -> Command: + # Trigger an interrupt with a question and options + return interrupt( + type="question", + question="Choose your favorite color:", + options=["red", "green", "blue"], + ) + + +# Build the graph +builder = StateGraph(GraphState) +builder.add_node("ask", ask) + +# Set entry point correctly (only one argument – node name) +builder.set_entry_point("ask") + +# Define edges +builder.add_edge(START, "ask") +builder.add_edge("ask", END) + +# Add a checkpoint +checkpoint = InMemorySaver() +graph = builder.compile(checkpointer=checkpoint) + + +def main(): + state: GraphState = {"human_value": None} + while True: + result = graph.invoke(state) + # If the graph finished without interruption + if "messages" in result and not any( + getattr(msg, "type", "") == "__interrupt__" for msg in result["messages"] + ): + print("Graph finished. Result:", state) + break + + # Handle interrupt + for msg in result["messages"]: + if getattr(msg, "type", "") == "__interrupt__": + question = msg.content.get("question") + options = msg.content.get("options") + print(question) + for i, opt in enumerate(options, 1): + print(f"{i}. {opt}") + choice_idx = int(input("Select option number: ")) - 1 + state["human_value"] = options[choice_idx] + # Resume the graph with updated state + # The resume is implicit by invoking again after setting the value + break + + +if __name__ == "__main__": + main() \ No newline at end of file