junaid17 commited on
Commit
3b889ac
·
verified ·
1 Parent(s): 5d5440b

Delete chatbot.py

Browse files
Files changed (1) hide show
  1. chatbot.py +0 -88
chatbot.py DELETED
@@ -1,88 +0,0 @@
1
-
2
- from typing import TypedDict, Annotated
3
- from langchain_core.messages import BaseMessage, SystemMessage
4
- from langgraph.checkpoint.memory import MemorySaver
5
- from langgraph.graph import StateGraph, START, END
6
- from langgraph.graph.message import add_messages
7
- from langgraph.prebuilt import ToolNode, tools_condition
8
- from langchain_openai import ChatOpenAI
9
- from dotenv import load_dotenv
10
-
11
- from tools import (
12
- create_rag_tool,
13
- arxiv_search,
14
- wikipedia_search,
15
- tavily_search,
16
- )
17
-
18
- load_dotenv()
19
-
20
- # ===============================
21
- # SYSTEM PROMPT
22
- # ===============================
23
- SYSTEM_PROMPT = SystemMessage(
24
- content="""
25
- You are an AI assistant using Retrieval-Augmented Generation.
26
-
27
- If a document is uploaded, you MUST answer using it.
28
- If no relevant info exists, clearly say so.
29
- Never hallucinate document content.
30
- """
31
- )
32
-
33
- # ===============================
34
- # STATE
35
- # ===============================
36
- class ChatState(TypedDict):
37
- messages: Annotated[list[BaseMessage], add_messages]
38
-
39
-
40
- # ===============================
41
- # LLM
42
- # ===============================
43
- llm = ChatOpenAI(
44
- model="gpt-4.1-nano",
45
- temperature=0.3,
46
- streaming=True
47
- )
48
-
49
- # ===============================
50
- # TOOLS
51
- # ===============================
52
- rag_tool = create_rag_tool()
53
-
54
- tools = [
55
- rag_tool,
56
- wikipedia_search,
57
- arxiv_search,
58
- tavily_search,
59
- ]
60
-
61
- llm = llm.bind_tools(tools)
62
- tool_node = ToolNode(tools)
63
-
64
-
65
- # ===============================
66
- # CHAT NODE
67
- # ===============================
68
- def chatbot(state: ChatState):
69
- messages = [SYSTEM_PROMPT] + state["messages"]
70
- response = llm.invoke(messages)
71
- return {"messages": [response]}
72
-
73
-
74
- # ===============================
75
- # GRAPH
76
- # ===============================
77
- memory = MemorySaver()
78
- graph = StateGraph(ChatState)
79
-
80
- graph.add_node("chat", chatbot)
81
- graph.add_node("tools", tool_node)
82
-
83
- graph.add_edge(START, "chat")
84
- graph.add_conditional_edges("chat", tools_condition)
85
- graph.add_edge("tools", "chat")
86
- graph.add_edge("chat", END)
87
-
88
- app = graph.compile(checkpointer=memory)