ORromu commited on
Commit
8286586
·
verified ·
1 Parent(s): 3cf184e

Adding an empty retriever. Next, we'll add more tools.

Browse files
Files changed (1) hide show
  1. agent.py +16 -9
agent.py CHANGED
@@ -12,17 +12,17 @@ from langchain_groq import ChatGroq
12
 
13
  HUGGINGFACEHUB_API_TOKEN = getenv("HUGGINGFACEHUB_API_TOKEN")
14
 
15
- # Making the agent
16
- #llm = HuggingFaceEndpoint(
17
- # repo_id="Qwen/Qwen2.5-Coder-32B-Instruct",
18
- # huggingfacehub_api_token=HUGGINGFACEHUB_API_TOKEN,
19
- #)
20
 
21
- #chat = ChatHuggingFace(llm=llm, verbose=True)
 
 
22
 
 
 
 
 
23
  chat = ChatGoogleGenerativeAI(model="gemini-2.0-flash", temperature=0)
24
 
25
- #chat = ChatGroq(model="qwen-qwq-32b", temperature=0)
26
  tools = [add,
27
  substract,
28
  multiply,
@@ -40,15 +40,22 @@ def simple_graph():
40
  ## Defining our nodes
41
  def assistant(state: MessagesState):
42
  """Assistant node"""
43
- return {"messages": state["messages"] + [chat_with_tools.invoke(state["messages"])]}
 
 
 
 
 
44
 
45
  # Build graph / nodes
46
  builder = StateGraph(MessagesState)
 
47
  builder.add_node("assistant", assistant) # Assistant
48
  builder.add_node("tools", ToolNode(tools)) # Tools
49
 
50
  # Logic / edges
51
- builder.add_edge(START, "assistant")
 
52
  builder.add_conditional_edges("assistant", tools_condition)
53
  builder.add_edge("tools", "assistant")
54
 
 
12
 
13
  HUGGINGFACEHUB_API_TOKEN = getenv("HUGGINGFACEHUB_API_TOKEN")
14
 
 
 
 
 
 
15
 
16
+ # load the system prompt from the file
17
+ with open("prompt.txt", "r", encoding="utf-8") as f:
18
+ system_prompt = f.read()
19
 
20
+ # System message
21
+ sys_msg = SystemMessage(content=system_prompt)
22
+
23
+ # Loading the assistant
24
  chat = ChatGoogleGenerativeAI(model="gemini-2.0-flash", temperature=0)
25
 
 
26
  tools = [add,
27
  substract,
28
  multiply,
 
40
  ## Defining our nodes
41
  def assistant(state: MessagesState):
42
  """Assistant node"""
43
+ return {"messages": [chat_with_tools.invoke(state["messages"])]}
44
+
45
+ def retriever(state: MessagesState):
46
+ """Retriever node"""
47
+ # I don't want to use a Retriever / Using similar questions.
48
+ return {"messages": [sys_msg] + state["messages"]}
49
 
50
  # Build graph / nodes
51
  builder = StateGraph(MessagesState)
52
+ builder.add_node("retriever", retriever) # Assistant
53
  builder.add_node("assistant", assistant) # Assistant
54
  builder.add_node("tools", ToolNode(tools)) # Tools
55
 
56
  # Logic / edges
57
+ builder.add_edge(START, "retriever")
58
+ builder.add_edge("retriever", "assistant")
59
  builder.add_conditional_edges("assistant", tools_condition)
60
  builder.add_edge("tools", "assistant")
61