mirror of
https://github.com/langchain-ai/control-plane-api-demo.git
synced 2026-07-01 20:44:05 -04:00
28 lines
811 B
Python
28 lines
811 B
Python
from typing import Annotated
|
|
|
|
from typing_extensions import TypedDict
|
|
|
|
from langgraph.graph import StateGraph, START, END
|
|
from langgraph.graph.message import add_messages
|
|
|
|
class State(TypedDict):
|
|
# Messages have the type "list". The `add_messages` function
|
|
# in the annotation defines how this state key should be updated
|
|
# (in this case, it appends messages to the list, rather than overwriting them)
|
|
messages: Annotated[list, add_messages]
|
|
|
|
graph_builder = StateGraph(State)
|
|
|
|
from langchain_openai import ChatOpenAI
|
|
|
|
llm = ChatOpenAI(model="o3-mini")
|
|
|
|
def chatbot(state: State):
|
|
return {"messages": [llm.invoke(state["messages"])]}
|
|
|
|
graph_builder.add_node("chatbot", chatbot)
|
|
|
|
graph_builder.add_edge(START, "chatbot")
|
|
graph_builder.add_edge("chatbot", END)
|
|
|
|
graph = graph_builder.compile() |