-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathli_deepseek_agent.py
59 lines (39 loc) · 1.3 KB
/
li_deepseek_agent.py
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# %%
from llama_index.core.agent import ReActAgent
from llama_index.core.tools import FunctionTool
from llama_index.llms.ollama import Ollama
# %%
LARGE_MODEL = "deepseek-r1:14b"
TIMEOUT = 120.0
# %% Tools
def naming_generator_from_int(x: int) -> str:
"""Generate a artificial name from an integer."""
return f"Mustermann {x}"
naming_tool = FunctionTool.from_defaults(fn=naming_generator_from_int)
def multiply(x: float, y: float) -> float:
"""Multiply two numbers"""
return x * y
def addition(x: float, y: float) -> float:
"""Add two numbers"""
return x + y
def subtraction(x: float, y: float) -> float:
"""Subtract two numbers"""
return x - y
def division(x: float, y: float) -> float:
"""Divide two numbers"""
return x / y
math_tools = [
FunctionTool.from_defaults(fn=multiply),
FunctionTool.from_defaults(fn=addition),
FunctionTool.from_defaults(fn=subtraction),
FunctionTool.from_defaults(fn=division),
]
# %%
usr_msg = "Generate a name from an integer, if a number is 11 and what is the result of 3 + 4 * 9 -65 / 4?"
# %% Agent and model
model = Ollama(model=LARGE_MODEL,request_timeout=TIMEOUT)
agent = ReActAgent.from_tools([naming_tool] + math_tools, llm=model, verbose=True)
# %%
answer = agent.chat(usr_msg)
print("answer: ", answer)
# %%