File size: 865 Bytes
345eb49
 
 
 
 
 
 
 
b3acff8
345eb49
 
 
 
 
7565387
2e6e1f3
015f0e3
2e6e1f3
 
015f0e3
2e6e1f3
 
015f0e3
2e6e1f3
345eb49
 
 
7565387
345eb49
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from google import genai
from google.genai.types import Tool, GenerateContentConfig, GoogleSearch
import time
import os

api_key = os.getenv("GEMINI_API_KEY")
client = genai.Client(api_key=api_key)

model_id = "gemini-2.0-flash"

google_search_tool = Tool(
    google_search = GoogleSearch()
)

def webSearch(prompt):
  """
  Searches the web using Google Search.

  Args:
      prompt: A string representing the search query
      
  Returns:
      Search results in natural language.
  """  

  response = client.models.generate_content(
    model=model_id,
    contents=prompt,
    config=GenerateContentConfig(
        tools=[google_search_tool],
        response_modalities=["TEXT"],
    )
)
  
  # stream response
  for each in response.candidates[0].content.parts:
    for i in range(len(each.text)):
        time.sleep(0.001)
        yield each.text[: i+1]