thatting commited on
Commit
cf8515b
·
verified ·
1 Parent(s): d4c33f8

Create agent.py

Browse files
Files changed (1) hide show
  1. agent.py +62 -0
agent.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import dotenv
3
+ import yaml
4
+ from smolagents import CodeAgent, LiteLLMModel, OpenAIServerModel
5
+ from tools import tool_read_files, tool_reverse_string, tool_download_image
6
+
7
+ dotenv.load_dotenv()
8
+
9
+ HF_TOKEN = os.getenv("HF_TOKEN")
10
+ OPENAI_KEY = os.getenv("OPEN_AI_KEY")
11
+
12
+
13
+ class Agent:
14
+ def __init__(self):
15
+ self.hf_token = os.getenv("HF_TOKEN")
16
+
17
+ # self.model = InferenceClientModel(
18
+ # model_id="Qwen/Qwen3-235B-A22B",
19
+ # token=HF_TOKEN
20
+ # )
21
+
22
+ self.model = OpenAIServerModel(
23
+ model_id="gpt-4o-mini-2024-07-18",
24
+ api_key=OPENAI_KEY
25
+ )
26
+
27
+ self.model_local = LiteLLMModel(
28
+ model_id="ollama/qwen3:8b",
29
+ api_base="http://localhost:11434",
30
+ num_ctx=40000, # Context set for Mistral Nemo
31
+ )
32
+
33
+
34
+
35
+ self.agent = CodeAgent(
36
+ model=self.model,
37
+ add_base_tools=True,
38
+ tools=[tool_read_files, tool_reverse_string, tool_download_image],
39
+ max_steps=10,
40
+ additional_authorized_imports=['numpy','beautifulsoup4','wiki','re','pandas']
41
+ )
42
+
43
+ def __call__(self, query:str, file:str) -> str:
44
+ if file != "":
45
+ query = f"{query} [FILE] {file}"
46
+ return self.ask(query)
47
+
48
+ def ask(self, query:str) -> str:
49
+ result = self.agent.run(query)
50
+ return result
51
+
52
+
53
+
54
+ if __name__ == "__main__":
55
+ otto = Agent()
56
+ response = otto.ask("Who was President of the United States in 1957?")
57
+ print(response)
58
+
59
+ # response = agent.run("Where were the Vietnamese specimens described by Kuznetzov in Nedoshivina's 2010 paper eventually deposited? Just give me the city name without abbreviations.")
60
+ # print(response)
61
+
62
+ # response = model(messages)