Update app.py
Browse files
app.py
CHANGED
|
@@ -24,43 +24,32 @@ class BasicAgent:
|
|
| 24 |
|
| 25 |
|
| 26 |
@tool
|
| 27 |
-
|
| 28 |
-
def search_web(query: str, num_results: int = 5) -> list:
|
| 29 |
"""
|
| 30 |
-
|
| 31 |
Args:
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
Returns:
|
| 35 |
-
list: A list of search results sorted by score with {url, title, content, score} for each result.
|
| 36 |
"""
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
ret = response.json()
|
| 43 |
-
# keep only the response'results' array
|
| 44 |
-
results = ret.get("results", [])
|
| 45 |
-
# keep only the first num_results
|
| 46 |
-
results = results[:num_results]
|
| 47 |
-
# for each result keep only the url, title and content ans score
|
| 48 |
-
results = [
|
| 49 |
{
|
| 50 |
-
"
|
| 51 |
-
"
|
| 52 |
-
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
}
|
| 55 |
-
for result in results
|
| 56 |
]
|
| 57 |
-
|
| 58 |
-
return results
|
| 59 |
-
|
| 60 |
-
else:
|
| 61 |
-
print(f"Error: {response.status_code}")
|
| 62 |
-
return []
|
| 63 |
|
|
|
|
| 64 |
|
| 65 |
|
| 66 |
|
|
@@ -94,7 +83,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 94 |
search_tool = DuckDuckGoSearchTool()
|
| 95 |
my_small_agent = CodeAgent(
|
| 96 |
model=openai_41mini_model,
|
| 97 |
-
tools=[search_tool],
|
| 98 |
name="web_agent",
|
| 99 |
description="Use search engine to find webpages related to a subject and get the page content",
|
| 100 |
#additional_authorized_imports=["pandas", "numpy","bs4"],
|
|
|
|
| 24 |
|
| 25 |
|
| 26 |
@tool
|
| 27 |
+
def analyze_image(question: str, image_url: str) -> str:
|
|
|
|
| 28 |
"""
|
| 29 |
+
Analyze an image using OpenAI's API.
|
| 30 |
Args:
|
| 31 |
+
question (str): The question to ask about the image. eg. "What is in this image?"
|
| 32 |
+
image_url (str): The URL of the image to analyze.
|
|
|
|
|
|
|
| 33 |
"""
|
| 34 |
+
client = OpenAI()
|
| 35 |
+
|
| 36 |
+
response = client.responses.create(
|
| 37 |
+
model="gpt-4o-mini",
|
| 38 |
+
input=[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
{
|
| 40 |
+
"role": "user",
|
| 41 |
+
"content": [
|
| 42 |
+
{ "type": "input_text", "text": f"{question}" },
|
| 43 |
+
{
|
| 44 |
+
"type": "input_image",
|
| 45 |
+
"image_url": f"{image_url}",
|
| 46 |
+
}
|
| 47 |
+
]
|
| 48 |
}
|
|
|
|
| 49 |
]
|
| 50 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
+
return response
|
| 53 |
|
| 54 |
|
| 55 |
|
|
|
|
| 83 |
search_tool = DuckDuckGoSearchTool()
|
| 84 |
my_small_agent = CodeAgent(
|
| 85 |
model=openai_41mini_model,
|
| 86 |
+
tools=[search_tool, analyze_image],
|
| 87 |
name="web_agent",
|
| 88 |
description="Use search engine to find webpages related to a subject and get the page content",
|
| 89 |
#additional_authorized_imports=["pandas", "numpy","bs4"],
|