rsobieski commited on
Commit
0c774c2
·
verified ·
1 Parent(s): f0db1d6

Update agent.py

Browse files
Files changed (1) hide show
  1. agent.py +14 -12
agent.py CHANGED
@@ -2,7 +2,7 @@ import os
2
  import pandas as pd
3
  from langchain_core.messages import HumanMessage, AIMessage
4
  from langgraph.graph import StateGraph, MessagesState
5
- from langchain_community.llms import HuggingFaceEndpoint
6
  from tools import TOOLS
7
 
8
  # --- Read local QA data for retriever ---
@@ -14,15 +14,15 @@ qa_dict = {
14
  }
15
 
16
  def build_graph():
17
- # Initialize Mistral model - CORRECTED CONFIGURATION
18
- llm = HuggingFaceEndpoint(
19
  repo_id="mistralai/Mistral-7B-Instruct-v0.3",
20
- task="text-generation",
21
- huggingfacehub_api_token=os.environ["HF_TOKEN"],
22
- # model_kwargs={
23
- # "max_new_tokens": 512,
24
- # "temperature": 0.1
25
- # }
26
  )
27
 
28
  # Retriever node (unchanged)
@@ -34,11 +34,11 @@ def build_graph():
34
  print("🔍 No match. Sending to LLM.")
35
  return {"messages": state["messages"]}
36
 
37
- # Assistant node (LLM) - UPDATED FOR TEXT-GENERATION
38
  def assistant_node(state: MessagesState):
39
  query = state["messages"][-1].content.strip()
40
 
41
- # Format system prompt for text-generation
42
  system_prompt = (
43
  "You are a helpful assistant evaluated by the GAIA benchmark. "
44
  "Only return the final answer, with no explanations. "
@@ -48,8 +48,10 @@ def build_graph():
48
  "- Never justify or explain"
49
  )
50
 
51
- # Format prompt for text-generation model
52
  prompt = f"<s>[INST] {system_prompt}\n\n{query} [/INST]"
 
 
53
  response = llm.invoke(prompt).strip()
54
 
55
  # Clean up response
 
2
  import pandas as pd
3
  from langchain_core.messages import HumanMessage, AIMessage
4
  from langgraph.graph import StateGraph, MessagesState
5
+ from langchain_community.llms import HuggingFaceHub
6
  from tools import TOOLS
7
 
8
  # --- Read local QA data for retriever ---
 
14
  }
15
 
16
  def build_graph():
17
+ # Initialize Mistral model using HuggingFaceHub
18
+ llm = HuggingFaceHub(
19
  repo_id="mistralai/Mistral-7B-Instruct-v0.3",
20
+ model_kwargs={
21
+ "max_new_tokens": 512,
22
+ "temperature": 0.1,
23
+ "do_sample": False
24
+ },
25
+ huggingfacehub_api_token=os.environ["HF_TOKEN"]
26
  )
27
 
28
  # Retriever node (unchanged)
 
34
  print("🔍 No match. Sending to LLM.")
35
  return {"messages": state["messages"]}
36
 
37
+ # Assistant node (LLM) - updated for HuggingFaceHub
38
  def assistant_node(state: MessagesState):
39
  query = state["messages"][-1].content.strip()
40
 
41
+ # Format system prompt
42
  system_prompt = (
43
  "You are a helpful assistant evaluated by the GAIA benchmark. "
44
  "Only return the final answer, with no explanations. "
 
48
  "- Never justify or explain"
49
  )
50
 
51
+ # Format prompt for Mistral model
52
  prompt = f"<s>[INST] {system_prompt}\n\n{query} [/INST]"
53
+
54
+ # Generate response
55
  response = llm.invoke(prompt).strip()
56
 
57
  # Clean up response