File size: 1,362 Bytes
beb1eb8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import os
from langchain import hub
from langchain.agents import initialize_agent, AgentType, Tool
from langchain.llms import HuggingFaceHub
from langchain_community.tools import DuckDuckGoSearchResults
from langchain_experimental.tools import PythonREPLTool
from langchain.agents.agent_toolkits import create_python_agent
from langchain.agents import load_tools

# Lade dein Hugging Face Token (falls benötigt)
from huggingface_hub import login
# login(token="your-huggingface-token-here")  # Optional, falls dein Space das braucht

# LLM: Mistral-7B-Instruct über Hugging Face Inference API
llm = HuggingFaceHub(
    repo_id="mistralai/Mistral-7B-Instruct-v0.2",
    model_kwargs={"temperature": 0.2, "max_new_tokens": 512}
)

# Tools definieren
search_tool = DuckDuckGoSearchResults()
python_tool = PythonREPLTool()

tools = [
    Tool(
        name="Search",
        func=search_tool.run,
        description="Useful for when you need to answer questions about current events or look up information online."
    ),
    Tool(
        name="Python_REPL",
        func=python_tool.run,
        description="Useful for math, calculations, or running simple python code."
    ),
]

# Agent initialisieren
agent_executor = initialize_agent(
    tools,
    llm,
    agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
    verbose=True,
    handle_parsing_errors=True,
)