Chatbot / chatbot.py
yashAI007's picture
first commt
2bd81f8
raw
history blame contribute delete
958 Bytes
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)