Spaces:
Runtime error
Runtime error
Update agent.py
Browse files
agent.py
CHANGED
@@ -1,18 +1,15 @@
|
|
1 |
import os
|
2 |
-
from langchain import hub
|
3 |
from langchain.agents import initialize_agent, AgentType, Tool
|
4 |
-
from
|
5 |
from langchain_community.tools import DuckDuckGoSearchResults
|
6 |
from langchain_experimental.tools import PythonREPLTool
|
7 |
from huggingface_hub import login
|
8 |
|
9 |
-
# Lade dein Hugging Face Token (falls benötigt)
|
10 |
-
# login(token="your-huggingface-token-here") # Optional, falls dein Space das braucht
|
11 |
-
|
12 |
# LLM: Mistral-7B-Instruct über Hugging Face Inference API
|
13 |
-
llm =
|
14 |
repo_id="mistralai/Mistral-7B-Instruct-v0.2",
|
15 |
-
|
|
|
16 |
)
|
17 |
|
18 |
# Tools definieren
|
@@ -32,6 +29,23 @@ tools = [
|
|
32 |
),
|
33 |
]
|
34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
# Agent initialisieren
|
36 |
agent_executor = initialize_agent(
|
37 |
tools,
|
@@ -39,4 +53,6 @@ agent_executor = initialize_agent(
|
|
39 |
agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
|
40 |
verbose=True,
|
41 |
handle_parsing_errors=True,
|
|
|
42 |
)
|
|
|
|
1 |
import os
|
|
|
2 |
from langchain.agents import initialize_agent, AgentType, Tool
|
3 |
+
from langchain_huggingface import HuggingFaceEndpoint
|
4 |
from langchain_community.tools import DuckDuckGoSearchResults
|
5 |
from langchain_experimental.tools import PythonREPLTool
|
6 |
from huggingface_hub import login
|
7 |
|
|
|
|
|
|
|
8 |
# LLM: Mistral-7B-Instruct über Hugging Face Inference API
|
9 |
+
llm = HuggingFaceEndpoint(
|
10 |
repo_id="mistralai/Mistral-7B-Instruct-v0.2",
|
11 |
+
temperature=0.2,
|
12 |
+
max_new_tokens=512,
|
13 |
)
|
14 |
|
15 |
# Tools definieren
|
|
|
29 |
),
|
30 |
]
|
31 |
|
32 |
+
from langchain_core.prompts import SystemMessagePromptTemplate
|
33 |
+
|
34 |
+
system_prompt = """You are an expert AI assistant specialized in answering exam-style factual questions.
|
35 |
+
Follow these guidelines:
|
36 |
+
|
37 |
+
- Use the Search tool when external knowledge is needed (especially about recent events or niche topics).
|
38 |
+
- Use the Python_REPL tool for any math calculations, even if simple.
|
39 |
+
- Always attempt to provide a direct and concise answer without extra commentary.
|
40 |
+
- Do not apologize or state limitations.
|
41 |
+
- If a file is attached, explain how you would process it or the key steps to extract an answer.
|
42 |
+
- When dates are mentioned, be very precise and double-check calculations using the appropriate tools.
|
43 |
+
- If unsure, use the Search tool before responding.
|
44 |
+
|
45 |
+
Respond directly to the user’s question based solely on facts and without unnecessary elaboration.
|
46 |
+
Only provide what is explicitly asked for.
|
47 |
+
"""
|
48 |
+
|
49 |
# Agent initialisieren
|
50 |
agent_executor = initialize_agent(
|
51 |
tools,
|
|
|
53 |
agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
|
54 |
verbose=True,
|
55 |
handle_parsing_errors=True,
|
56 |
+
system_message=SystemMessagePromptTemplate.from_template(system_prompt),
|
57 |
)
|
58 |
+
|