ekkasilina commited on
Commit
b21adef
·
verified ·
1 Parent(s): 3b4de4f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -31
app.py CHANGED
@@ -24,43 +24,32 @@ class BasicAgent:
24
 
25
 
26
  @tool
27
- # this tool allow web search on a local SearXNG instance
28
- def search_web(query: str, num_results: int = 5) -> list:
29
  """
30
- Perform a web search using local SearXNG instance.
31
  Args:
32
- query (str): The search query.
33
- num_results (int): The number of results to return.
34
- Returns:
35
- list: A list of search results sorted by score with {url, title, content, score} for each result.
36
  """
37
- # local metaserach engine searxng, run on localhost:8888
38
- searxng_url = "http://localhost:8888/search"
39
- params = {"q": query, "format": 'json'}
40
- response = requests.get(searxng_url, params=params)
41
- if response.status_code == 200:
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
- "url": result.get("url"),
51
- "title": result.get("title"),
52
- "content": result.get("content"),
53
- "score": result.get("score"),
 
 
 
 
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"],