ABVM commited on
Commit
2d54bed
·
verified ·
1 Parent(s): a7fbbfc

Delete multi_agent.py

Browse files
Files changed (1) hide show
  1. multi_agent.py +0 -146
multi_agent.py DELETED
@@ -1,146 +0,0 @@
1
-
2
- from smolagents import (
3
- CodeAgent,
4
- InferenceClientModel,
5
- VisitWebpageTool,
6
- WebSearchTool,
7
- WikipediaSearchTool,
8
- PythonInterpreterTool,
9
- FinalAnswerTool,
10
- tool
11
- )
12
- from groq import Groq
13
- from typing import Dict, Any
14
- import os
15
-
16
- # ---- TOOLS ----
17
- @tool
18
- def image_process(image_file: str) -> Dict[str, str]:
19
- """
20
- Extract text from an image file using OCR and return OCR text and base64 encoding.
21
-
22
- Args:
23
- image_file: Path to the image file
24
-
25
- Returns:
26
- Dict with keys 'ocr_text' and 'base64_image'
27
- """
28
- try:
29
- import pytesseract
30
- from PIL import Image
31
- from smolagents.utils import encode_image_base64
32
- image = Image.open(image_file)
33
- base64_img = encode_image_base64(image) # <<<< CORRECT VARIABLE
34
- text = pytesseract.image_to_string(image)
35
- return {
36
- "ocr_text": text,
37
- "base64_image": base64_img
38
- }
39
- except Exception as e:
40
- return {
41
- "ocr_text": "",
42
- "base64_image": "",
43
- "error": str(e)
44
- }
45
-
46
- # ---- GROQ MODEL WRAPPER ----
47
- class LLMResponse:
48
- def __init__(self, content):
49
- self.content = content
50
-
51
- class GroqModel:
52
- def __init__(self, model_name=""):
53
- self.model_name = model_name
54
- self.client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
55
-
56
- def __call__(self, prompt, max_tokens=8096):
57
- if isinstance(prompt, str):
58
- messages = [{"role": "user", "content": prompt}]
59
- else:
60
- messages = prompt
61
- response = self.client.chat.completions.create(
62
- messages=messages,
63
- model=self.model_name,
64
- stream=False,
65
- max_tokens=max_tokens,
66
- )
67
- return LLMResponse(response.choices[0].message.content)
68
-
69
- def generate(self, prompt, max_tokens=8096, **kwargs):
70
- # For compatibility with agent frameworks
71
- return self.__call__(prompt, max_tokens=max_tokens)
72
-
73
-
74
- # ---- MULTI-AGENT SYSTEM ----
75
- class MultyAgentSystem:
76
- def __init__(self):
77
- deepseek_model = GroqModel("deepseek-r1-distill-llama-70b")
78
- qwen_model = GroqModel("qwen-qwq-32b")
79
-
80
- # --- Web agent definition ---
81
- self.web_agent = CodeAgent(
82
- model=qwen_model,
83
- tools=[WebSearchTool(), VisitWebpageTool(), WikipediaSearchTool()],
84
- name="web_agent",
85
- description=(
86
- "You are a web browsing agent. Whenever the given {task} involves browsing "
87
- "the web or a specific website such as Wikipedia or YouTube, you will use "
88
- "the provided tools. For web-based factual and retrieval tasks, be as precise and source-reliable as possible."
89
- ),
90
- additional_authorized_imports=[
91
- "markdownify",
92
- "json",
93
- "requests",
94
- "urllib.request",
95
- "urllib.parse",
96
- "wikipedia-api",
97
- ],
98
- verbosity_level=0,
99
- max_steps=10,
100
- )
101
-
102
- # --- Info agent definition ---
103
- self.info_agent = CodeAgent(
104
- model=qwen_model,
105
- tools=[PythonInterpreterTool(), image_process],
106
- name="info_agent",
107
- description=(
108
- "You are an agent tasked with cleaning, parsing, calculating information, and performing OCR if images are provided in the {task}. "
109
- "You handle all math, code, and data manipulation. Use numpy, math, and available libraries. For image or chess tasks, use pytesseract, PIL, or chess as required."
110
- ),
111
- additional_authorized_imports=[
112
- "numpy",
113
- "math",
114
- "pytesseract",
115
- "PIL",
116
- "chess",
117
- ],
118
- )
119
-
120
- # --- Manager agent definition ---
121
- self.manager_agent = CodeAgent(
122
- model=deepseek_model,
123
- tools=[FinalAnswerTool()],
124
- managed_agents=[self.web_agent, self.info_agent],
125
- name="manager_agent",
126
- description=(
127
- "You are the manager. Given a {task}, plan which agent to use: "
128
- "If web data is needed, delegate to web_agent. If math, parsing, or code is needed, use info_agent. "
129
- "After collecting outputs, optionally cross-validate and check correctness, then finalize and submit the best answer using FinalAnswerTool. "
130
- "For each task, explicitly explain your planning steps and reasons for choosing which agent, and always prefer the most accurate and complete answer possible."
131
- ),
132
- additional_authorized_imports=[
133
- "json",
134
- "pandas",
135
- "numpy",
136
- ],
137
- planning_interval=5,
138
- verbosity_level=2,
139
- max_steps=20,
140
- )
141
-
142
- def __call__(self, question, **kwargs):
143
-
144
- return self.manager_agent(question, **kwargs)
145
-
146
-