Yongkang ZOU
commited on
Commit
Β·
a16bb01
1
Parent(s):
b758f5a
update tools
Browse files
agent.py
CHANGED
|
@@ -21,8 +21,9 @@ import pandas as pd
|
|
| 21 |
from transformers import BlipProcessor, BlipForConditionalGeneration
|
| 22 |
from PIL import Image
|
| 23 |
import torch
|
|
|
|
| 24 |
import cmath
|
| 25 |
-
from code_interpreter import CodeInterpreter
|
| 26 |
import uuid
|
| 27 |
import tempfile
|
| 28 |
import requests
|
|
@@ -147,69 +148,69 @@ def blip_image_caption(image_path: str) -> str:
|
|
| 147 |
except Exception as e:
|
| 148 |
return f"Failed to process image with BLIP: {str(e)}"
|
| 149 |
|
| 150 |
-
@tool
|
| 151 |
-
def execute_code_multilang(code: str, language: str = "python") -> str:
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
|
| 214 |
@tool
|
| 215 |
def save_and_read_file(content: str, filename: Optional[str] = None) -> str:
|
|
@@ -291,7 +292,7 @@ def analyze_csv_file(file_path: str, query: str) -> str:
|
|
| 291 |
return f"Error analyzing CSV file: {str(e)}"
|
| 292 |
tools = [multiply, add, subtract, divide, modulus,
|
| 293 |
wiki_search, web_search, arvix_search, read_excel_file, extract_text_from_pdf,
|
| 294 |
-
blip_image_caption,
|
| 295 |
|
| 296 |
# ------------------- SYSTEM PROMPT -------------------
|
| 297 |
system_prompt_path = "system_prompt.txt"
|
|
|
|
| 21 |
from transformers import BlipProcessor, BlipForConditionalGeneration
|
| 22 |
from PIL import Image
|
| 23 |
import torch
|
| 24 |
+
import matplotlib.pyplot as plt
|
| 25 |
import cmath
|
| 26 |
+
# from code_interpreter import CodeInterpreter
|
| 27 |
import uuid
|
| 28 |
import tempfile
|
| 29 |
import requests
|
|
|
|
| 148 |
except Exception as e:
|
| 149 |
return f"Failed to process image with BLIP: {str(e)}"
|
| 150 |
|
| 151 |
+
# @tool
|
| 152 |
+
# def execute_code_multilang(code: str, language: str = "python") -> str:
|
| 153 |
+
# """Execute code in multiple languages (Python, Bash, SQL, C, Java) and return results.
|
| 154 |
+
# Args:
|
| 155 |
+
# code (str): The source code to execute.
|
| 156 |
+
# language (str): The language of the code. Supported: "python", "bash", "sql", "c", "java".
|
| 157 |
+
# Returns:
|
| 158 |
+
# A string summarizing the execution results (stdout, stderr, errors, plots, dataframes if any).
|
| 159 |
+
# """
|
| 160 |
+
# supported_languages = ["python", "bash", "sql", "c", "java"]
|
| 161 |
+
# language = language.lower()
|
| 162 |
+
# interpreter_instance = CodeInterpreter()
|
| 163 |
+
|
| 164 |
+
# if language not in supported_languages:
|
| 165 |
+
# return f"β Unsupported language: {language}. Supported languages are: {', '.join(supported_languages)}"
|
| 166 |
+
|
| 167 |
+
# result = interpreter_instance.execute_code(code, language=language)
|
| 168 |
+
|
| 169 |
+
# response = []
|
| 170 |
+
|
| 171 |
+
# if result["status"] == "success":
|
| 172 |
+
# response.append(f"β
Code executed successfully in **{language.upper()}**")
|
| 173 |
+
|
| 174 |
+
# if result.get("stdout"):
|
| 175 |
+
# response.append(
|
| 176 |
+
# "\n**Standard Output:**\n```\n" + result["stdout"].strip() + "\n```"
|
| 177 |
+
# )
|
| 178 |
+
|
| 179 |
+
# if result.get("stderr"):
|
| 180 |
+
# response.append(
|
| 181 |
+
# "\n**Standard Error (if any):**\n```\n"
|
| 182 |
+
# + result["stderr"].strip()
|
| 183 |
+
# + "\n```"
|
| 184 |
+
# )
|
| 185 |
+
|
| 186 |
+
# if result.get("result") is not None:
|
| 187 |
+
# response.append(
|
| 188 |
+
# "\n**Execution Result:**\n```\n"
|
| 189 |
+
# + str(result["result"]).strip()
|
| 190 |
+
# + "\n```"
|
| 191 |
+
# )
|
| 192 |
+
|
| 193 |
+
# if result.get("dataframes"):
|
| 194 |
+
# for df_info in result["dataframes"]:
|
| 195 |
+
# response.append(
|
| 196 |
+
# f"\n**DataFrame `{df_info['name']}` (Shape: {df_info['shape']})**"
|
| 197 |
+
# )
|
| 198 |
+
# df_preview = pd.DataFrame(df_info["head"])
|
| 199 |
+
# response.append("First 5 rows:\n```\n" + str(df_preview) + "\n```")
|
| 200 |
+
|
| 201 |
+
# if result.get("plots"):
|
| 202 |
+
# response.append(
|
| 203 |
+
# f"\n**Generated {len(result['plots'])} plot(s)** (Image data returned separately)"
|
| 204 |
+
# )
|
| 205 |
+
|
| 206 |
+
# else:
|
| 207 |
+
# response.append(f"β Code execution failed in **{language.upper()}**")
|
| 208 |
+
# if result.get("stderr"):
|
| 209 |
+
# response.append(
|
| 210 |
+
# "\n**Error Log:**\n```\n" + result["stderr"].strip() + "\n```"
|
| 211 |
+
# )
|
| 212 |
+
|
| 213 |
+
# return "\n".join(response)
|
| 214 |
|
| 215 |
@tool
|
| 216 |
def save_and_read_file(content: str, filename: Optional[str] = None) -> str:
|
|
|
|
| 292 |
return f"Error analyzing CSV file: {str(e)}"
|
| 293 |
tools = [multiply, add, subtract, divide, modulus,
|
| 294 |
wiki_search, web_search, arvix_search, read_excel_file, extract_text_from_pdf,
|
| 295 |
+
blip_image_caption, save_and_read_file, download_file_from_url, analyze_csv_file]
|
| 296 |
|
| 297 |
# ------------------- SYSTEM PROMPT -------------------
|
| 298 |
system_prompt_path = "system_prompt.txt"
|