Karim0111 commited on
Commit
eca273b
·
verified ·
1 Parent(s): 81aba7c

Update agents.py

Browse files
Files changed (1) hide show
  1. agents.py +78 -0
agents.py CHANGED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from smolagents import (CodeAgent,
2
+ GradioUI,
3
+ LiteLLMModel,
4
+ OpenAIServerModel,
5
+ ChatMessage,
6
+ ToolCallingAgent)
7
+ from smolagents.default_tools import (DuckDuckGoSearchTool,
8
+ VisitWebpageTool,
9
+ WikipediaSearchTool,
10
+ SpeechToTextTool,
11
+ PythonInterpreterTool)
12
+ import yaml
13
+ from final_answer import FinalAnswerTool, check_reasoning, ensure_formatting
14
+ from tools import (youtube_frames_to_images, use_vision_model,
15
+ read_file, download_file_from_url,
16
+ extract_text_from_image, analyze_csv_file,
17
+ analyze_excel_file, youtube_transcribe,
18
+ transcribe_audio, review_youtube_video)
19
+ import os
20
+ from dotenv import load_dotenv
21
+ import time
22
+
23
+ load_dotenv()
24
+
25
+ # Load prompts from YAML file
26
+ with open("prompts.yaml", 'r') as stream:
27
+ prompt_templates = yaml.safe_load(stream)
28
+
29
+
30
+
31
+ class SlowLiteLLMModel(LiteLLMModel):
32
+ def __init__(self, *args, **kwargs):
33
+ super().__init__(*args, **kwargs)
34
+
35
+ def __call__(self, messages, **kwargs) -> ChatMessage:
36
+ time.sleep(15)
37
+ # prepend onto whatever messages the Agent built
38
+ return super().__call__(messages, **kwargs)
39
+
40
+
41
+ react_model_name = "gemini/gemini-2.5-flash-preview-04-17"
42
+ react_model = LiteLLMModel(model_id=react_model_name,
43
+ api_key=os.getenv("GEMINI_KEY"),
44
+ temperature=0.2
45
+ )
46
+
47
+
48
+ manager_agent = CodeAgent(
49
+ model=react_model,
50
+ tools=[FinalAnswerTool(),
51
+ DuckDuckGoSearchTool(),
52
+ VisitWebpageTool(max_output_length=500000),
53
+ WikipediaSearchTool(extract_format='HTML'),
54
+ SpeechToTextTool(),
55
+ youtube_frames_to_images,
56
+ youtube_transcribe,
57
+ use_vision_model,
58
+ read_file, download_file_from_url,
59
+ extract_text_from_image,
60
+ analyze_csv_file, analyze_excel_file,
61
+ transcribe_audio,
62
+ review_youtube_video
63
+ ],
64
+ managed_agents=[],
65
+ additional_authorized_imports=['os', 'pandas', 'numpy', 'PIL', 'tempfile', 'PIL.Image'],
66
+ max_steps=20,
67
+ verbosity_level=1,
68
+ planning_interval=6,
69
+ name="Manager",
70
+ description="The manager of the team, responsible for overseeing and guiding the team's work.",
71
+ final_answer_checks=[check_reasoning, ensure_formatting],
72
+ prompt_templates=prompt_templates
73
+ )
74
+
75
+
76
+
77
+ if __name__ == "__main__":
78
+ GradioUI(manager_agent).launch()