Spaces:
Sleeping
Sleeping
Delete geminisearch.py
Browse files- geminisearch.py +0 -42
geminisearch.py
DELETED
@@ -1,42 +0,0 @@
|
|
1 |
-
from google import genai
|
2 |
-
from google.genai.types import Tool, GenerateContentConfig, GoogleSearch
|
3 |
-
import time
|
4 |
-
import os
|
5 |
-
|
6 |
-
api_key = os.getenv("GEMINI_API_KEY")
|
7 |
-
client = genai.Client(api_key=api_key)
|
8 |
-
|
9 |
-
model_id = "gemini-2.0-flash"
|
10 |
-
|
11 |
-
google_search_tool = Tool(
|
12 |
-
google_search = GoogleSearch()
|
13 |
-
)
|
14 |
-
|
15 |
-
def webSearch(prompt,history):
|
16 |
-
"""
|
17 |
-
Searches the web using Google Search.
|
18 |
-
|
19 |
-
Args:
|
20 |
-
prompt: A string representing the search query
|
21 |
-
history: A placeholder representing query history
|
22 |
-
|
23 |
-
Returns:
|
24 |
-
Search results in natural language.
|
25 |
-
"""
|
26 |
-
|
27 |
-
combined_prompt = f"Current information: \n\nQuestion: {prompt}"
|
28 |
-
|
29 |
-
response = client.models.generate_content(
|
30 |
-
model=model_id,
|
31 |
-
contents=combined_prompt,
|
32 |
-
config=GenerateContentConfig(
|
33 |
-
tools=[google_search_tool],
|
34 |
-
response_modalities=["TEXT"],
|
35 |
-
)
|
36 |
-
)
|
37 |
-
|
38 |
-
# stream response
|
39 |
-
for each in response.candidates[0].content.parts:
|
40 |
-
for i in range(len(each.text)):
|
41 |
-
time.sleep(0.001)
|
42 |
-
yield each.text[: i+1]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|