Budlee commited on
Commit
8edcd84
·
1 Parent(s): 314fc0f

Set Provider

Browse files
Files changed (1) hide show
  1. agent.py +25 -18
agent.py CHANGED
@@ -19,6 +19,7 @@ class CodingAgent:
19
  def __init__(self):
20
  model = InferenceClientModel(
21
  model_id="Qwen/Qwen2.5-Coder-32B-Instruct",
 
22
  )
23
  self._c_agent = CodeAgent(
24
  model=model,
@@ -43,6 +44,7 @@ class WebAgent:
43
  def __init__(self):
44
  model = InferenceClientModel(
45
  model_id="Qwen/Qwen2.5-Coder-32B-Instruct",
 
46
  )
47
  self._w_agent = CodeAgent(
48
  model=model,
@@ -91,6 +93,7 @@ class BudleeAgent:
91
  temperature=0.2,
92
  model_id="deepseek-ai/DeepSeek-R1", # it is possible that this model may be overloaded
93
  custom_role_conversions=None,
 
94
  )
95
  agent_web = WebAgent().agent
96
  agent_coding = CodingAgent().agent
@@ -121,16 +124,18 @@ class BudleeAgent:
121
  Try to solve the task as an Agent using the information
122
  """
123
  print(f"Agent received question (first 50 chars): {taskItem.question[:50]}...")
124
- additional_context = ""
125
 
126
  # Check if a file is present by validating the file_name is not empty
127
 
128
  if taskItem.file_name and taskItem.file_name.strip():
129
  print(f"Agent received file: {taskItem.file_name}")
130
- dl_file= self._download_file(taskItem.file_name)
131
- additional_context = f"The question has some additional context from a file that needed to be downloaded. here is the contents of the file\n FILE_CONTENTS: {dl_file}\n"
132
 
133
- prompt = self._PROMPT.format(question=taskItem.question, additional_context=additional_context)
 
 
134
  print(f"Agent prompt {prompt}")
135
  answer = self._manager_agent.run(prompt)
136
  # check the answer is FinalStep
@@ -139,48 +144,50 @@ class BudleeAgent:
139
 
140
  # print(f"Agent returning fixed answer: {answer}")
141
 
142
- return answer # type: ignore
143
-
144
  def _download_file(self, file_name: str) -> str:
145
  """
146
  Download the file from the given task_id and return its contents as a string.
147
  """
148
  print(f"Downloading file for task: {file_name}")
149
-
150
  try:
151
  # Construct the API URL - assuming file_name is the task_id
152
- api_url = f"{self._api_url}/files/{file_name}" # Replace with actual base URL
153
-
 
 
154
  # Download the file
155
  response = requests.get(api_url)
156
  response.raise_for_status() # Raises an HTTPError for bad responses
157
-
158
  # Create a temporary file
159
- with tempfile.NamedTemporaryFile(mode='w+b', delete=False) as temp_file:
160
  temp_file.write(response.content)
161
  temp_file_path = temp_file.name
162
-
163
  try:
164
  # Try to read as text with UTF-8 encoding first
165
- with open(temp_file_path, 'r', encoding='utf-8') as f:
166
  content = f.read()
167
  except UnicodeDecodeError:
168
  # If UTF-8 fails, try with latin-1
169
  try:
170
- with open(temp_file_path, 'r', encoding='latin-1') as f:
171
  content = f.read()
172
  except Exception:
173
  # If all text encodings fail, return binary info
174
- with open(temp_file_path, 'rb') as f:
175
  binary_content = f.read()
176
  content = f"Binary file content (Size: {len(binary_content)} bytes)"
177
  finally:
178
  # Clean up the temporary file
179
  os.unlink(temp_file_path)
180
-
181
  print(f"File downloaded and processed successfully for task: {file_name}")
182
  return content
183
-
184
  except requests.HTTPError as e:
185
  if e.response.status_code == 404:
186
  error_msg = f"No file found for task ID: {file_name}"
@@ -193,4 +200,4 @@ class BudleeAgent:
193
  except Exception as e:
194
  error_msg = f"Error downloading/processing file for task {file_name}: {e}"
195
  print(error_msg)
196
- return error_msg
 
19
  def __init__(self):
20
  model = InferenceClientModel(
21
  model_id="Qwen/Qwen2.5-Coder-32B-Instruct",
22
+ provider="huggingface",
23
  )
24
  self._c_agent = CodeAgent(
25
  model=model,
 
44
  def __init__(self):
45
  model = InferenceClientModel(
46
  model_id="Qwen/Qwen2.5-Coder-32B-Instruct",
47
+ provider="huggingface",
48
  )
49
  self._w_agent = CodeAgent(
50
  model=model,
 
93
  temperature=0.2,
94
  model_id="deepseek-ai/DeepSeek-R1", # it is possible that this model may be overloaded
95
  custom_role_conversions=None,
96
+ provider="huggingface",
97
  )
98
  agent_web = WebAgent().agent
99
  agent_coding = CodingAgent().agent
 
124
  Try to solve the task as an Agent using the information
125
  """
126
  print(f"Agent received question (first 50 chars): {taskItem.question[:50]}...")
127
+ additional_context = ""
128
 
129
  # Check if a file is present by validating the file_name is not empty
130
 
131
  if taskItem.file_name and taskItem.file_name.strip():
132
  print(f"Agent received file: {taskItem.file_name}")
133
+ dl_file = self._download_file(taskItem.file_name)
134
+ additional_context = f"The question has some additional context from a file that needed to be downloaded. here is the contents of the file\n FILE_CONTENTS: {dl_file}\n"
135
 
136
+ prompt = self._PROMPT.format(
137
+ question=taskItem.question, additional_context=additional_context
138
+ )
139
  print(f"Agent prompt {prompt}")
140
  answer = self._manager_agent.run(prompt)
141
  # check the answer is FinalStep
 
144
 
145
  # print(f"Agent returning fixed answer: {answer}")
146
 
147
+ return answer # type: ignore
148
+
149
  def _download_file(self, file_name: str) -> str:
150
  """
151
  Download the file from the given task_id and return its contents as a string.
152
  """
153
  print(f"Downloading file for task: {file_name}")
154
+
155
  try:
156
  # Construct the API URL - assuming file_name is the task_id
157
+ api_url = (
158
+ f"{self._api_url}/files/{file_name}" # Replace with actual base URL
159
+ )
160
+
161
  # Download the file
162
  response = requests.get(api_url)
163
  response.raise_for_status() # Raises an HTTPError for bad responses
164
+
165
  # Create a temporary file
166
+ with tempfile.NamedTemporaryFile(mode="w+b", delete=False) as temp_file:
167
  temp_file.write(response.content)
168
  temp_file_path = temp_file.name
169
+
170
  try:
171
  # Try to read as text with UTF-8 encoding first
172
+ with open(temp_file_path, "r", encoding="utf-8") as f:
173
  content = f.read()
174
  except UnicodeDecodeError:
175
  # If UTF-8 fails, try with latin-1
176
  try:
177
+ with open(temp_file_path, "r", encoding="latin-1") as f:
178
  content = f.read()
179
  except Exception:
180
  # If all text encodings fail, return binary info
181
+ with open(temp_file_path, "rb") as f:
182
  binary_content = f.read()
183
  content = f"Binary file content (Size: {len(binary_content)} bytes)"
184
  finally:
185
  # Clean up the temporary file
186
  os.unlink(temp_file_path)
187
+
188
  print(f"File downloaded and processed successfully for task: {file_name}")
189
  return content
190
+
191
  except requests.HTTPError as e:
192
  if e.response.status_code == 404:
193
  error_msg = f"No file found for task ID: {file_name}"
 
200
  except Exception as e:
201
  error_msg = f"Error downloading/processing file for task {file_name}: {e}"
202
  print(error_msg)
203
+ return error_msg