Rahatara commited on
Commit
ff304ae
·
verified ·
1 Parent(s): 2aefee2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -2
app.py CHANGED
@@ -18,8 +18,15 @@ def google_search_query(question, use_web_search):
18
  config=GenerateContentConfig(tools=[google_search_tool]),
19
  )
20
  ai_response = response.text # AI response as plain text
21
- link_list = "\n".join([f"<a href='{entry.url}' target='_blank'>{entry.title}</a>" for entry in response.candidates[0].grounding_metadata.search_entry_point.entries])
22
- return ai_response, link_list
 
 
 
 
 
 
 
23
  else:
24
  # Return response without web search
25
  response = client.models.generate_content(
 
18
  config=GenerateContentConfig(tools=[google_search_tool]),
19
  )
20
  ai_response = response.text # AI response as plain text
21
+
22
+ # Check if search results are available and extract them
23
+ if hasattr(response.candidates[0].grounding_metadata, 'search_entry_point'):
24
+ search_results = response.candidates[0].grounding_metadata.search_entry_point
25
+ links_html = "\n".join([f"<a href='{result.url}' target='_blank'>{result.title}</a>" for result in search_results.results])
26
+ else:
27
+ links_html = "No search results found."
28
+
29
+ return ai_response, links_html
30
  else:
31
  # Return response without web search
32
  response = client.models.generate_content(