Update agent.py
Browse files
agent.py
CHANGED
|
@@ -17,7 +17,7 @@ def build_graph():
|
|
| 17 |
# Initialize Mistral model
|
| 18 |
llm = HuggingFaceEndpoint(
|
| 19 |
repo_id="mistralai/Mistral-7B-Instruct-v0.3",
|
| 20 |
-
|
| 21 |
huggingfacehub_api_token=os.environ["HF_TOKEN"]
|
| 22 |
)
|
| 23 |
|
|
@@ -43,12 +43,20 @@ def build_graph():
|
|
| 43 |
"- Never justify or explain"
|
| 44 |
)
|
| 45 |
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
]
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
-
response = llm.invoke(messages)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
return {"messages": [AIMessage(content=response.strip())]}
|
| 53 |
|
| 54 |
# Tool node
|
|
|
|
| 17 |
# Initialize Mistral model
|
| 18 |
llm = HuggingFaceEndpoint(
|
| 19 |
repo_id="mistralai/Mistral-7B-Instruct-v0.3",
|
| 20 |
+
task="conversational",
|
| 21 |
huggingfacehub_api_token=os.environ["HF_TOKEN"]
|
| 22 |
)
|
| 23 |
|
|
|
|
| 43 |
"- Never justify or explain"
|
| 44 |
)
|
| 45 |
|
| 46 |
+
# prompt = [
|
| 47 |
+
# {"role": "system", "content": system_prompt},
|
| 48 |
+
# {"role": "user", "content": query},
|
| 49 |
+
# ]
|
| 50 |
+
|
| 51 |
+
prompt = f"{system_prompt}\n\nUser: {query}\nAssistant:"
|
| 52 |
+
response = llm.invoke(prompt).strip()
|
| 53 |
|
| 54 |
+
# response = llm.invoke(messages)
|
| 55 |
+
|
| 56 |
+
for tag in ("Final answer:", "Answer:", "assistant:"):
|
| 57 |
+
if response.lower().startswith(tag.lower()):
|
| 58 |
+
response = response[len(tag):].strip()
|
| 59 |
+
|
| 60 |
return {"messages": [AIMessage(content=response.strip())]}
|
| 61 |
|
| 62 |
# Tool node
|