Update agent.py
Browse files
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
|
| 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
|
| 18 |
-
llm =
|
| 19 |
repo_id="mistralai/Mistral-7B-Instruct-v0.3",
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 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) -
|
| 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,8 +48,10 @@ def build_graph():
|
|
| 48 |
"- Never justify or explain"
|
| 49 |
)
|
| 50 |
|
| 51 |
-
# Format prompt for
|
| 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
|