File size: 958 Bytes
2bd81f8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from langgraph.graph import START,END,StateGraph
from typing import TypedDict, Annotated
from langchain_core.messages import BaseMessage,HumanMessage
from langchain_groq import ChatGroq
from langgraph.graph.message import add_messages
from langgraph.checkpoint.memory import InMemorySaver  
from dotenv import load_dotenv

load_dotenv()

checkpointer= InMemorySaver()

llm = ChatGroq(
    model="qwen/qwen3-32b",
    temperature=0,
    max_tokens=None,
    reasoning_format="parsed",
    timeout=None,
    max_retries=2,
    # other params...
)


class ChatStat(TypedDict):
    messages: Annotated[list[BaseMessage],add_messages]


def chat_node(state : ChatStat):
    messages = state['messages']
    response = llm.invoke(messages)
    return {'messages': [response]}


graph = StateGraph(ChatStat)

graph.add_node("chat_node",chat_node)

graph.add_edge(START,'chat_node')
graph.add_edge("chat_node",END)

chatbot = graph.compile(checkpointer=checkpointer)