eaglelandsonce commited on
Commit
282d4a3
1 Parent(s): efe7912

Update crewai/tools/gemini_tools.py

Browse files
Files changed (1) hide show
  1. crewai/tools/gemini_tools.py +5 -43
crewai/tools/gemini_tools.py CHANGED
@@ -12,59 +12,21 @@ GOOGLE_AI_STUDIO = os.environ.get('GOOGLE_AI_STUDIO2')
12
  if not GOOGLE_AI_STUDIO:
13
  raise ValueError("API key not found. Please set the GOOGLE_AI_STUDIO2 environment variable.")
14
 
15
-
16
-
17
  import requests
18
  from langchain.tools import tool
19
 
20
 
21
  class GeminiSearchTools():
22
  @tool("Gemini search the internet")
23
- def gemini_search_internet(query):
24
  """Useful to search the internet
25
  about a a given topic and return relevant results"""
26
- top_result_to_return = 4
27
- url = "https://google.serper.dev/search"
28
- payload = json.dumps({"q": query})
29
- headers = {
30
- 'X-API-KEY': os.environ['SERPER_API_KEY'],
31
- 'content-type': 'application/json'
32
- }
33
- response = requests.request("POST", url, headers=headers, data=payload)
34
- results = response.json()['organic']
35
- string = []
36
- for result in results[:top_result_to_return]:
37
- try:
38
- string.append('\n'.join([
39
- f"Title: {result['title']}", f"Link: {result['link']}",
40
- f"Snippet: {result['snippet']}", "\n-----------------"
41
- ]))
42
- except KeyError:
43
- next
44
-
45
- return '\n'.join(string)
46
 
47
  @tool("Gemini search news on the internet")
48
  def gemini_search_news(query):
49
  """Useful to search news about a company, stock or any other
50
  topic and return relevant results"""""
51
- top_result_to_return = 4
52
- url = "https://google.serper.dev/news"
53
- payload = json.dumps({"q": query})
54
- headers = {
55
- 'X-API-KEY': os.environ['SERPER_API_KEY'],
56
- 'content-type': 'application/json'
57
- }
58
- response = requests.request("POST", url, headers=headers, data=payload)
59
- results = response.json()['news']
60
- string = []
61
- for result in results[:top_result_to_return]:
62
- try:
63
- string.append('\n'.join([
64
- f"Title: {result['title']}", f"Link: {result['link']}",
65
- f"Snippet: {result['snippet']}", "\n-----------------"
66
- ]))
67
- except KeyError:
68
- next
69
-
70
- return '\n'.join(string)
 
12
  if not GOOGLE_AI_STUDIO:
13
  raise ValueError("API key not found. Please set the GOOGLE_AI_STUDIO2 environment variable.")
14
 
 
 
15
  import requests
16
  from langchain.tools import tool
17
 
18
 
19
  class GeminiSearchTools():
20
  @tool("Gemini search the internet")
21
+ def gemini_search(query):
22
  """Useful to search the internet
23
  about a a given topic and return relevant results"""
24
+ response = model.generate_content(query)
25
+ return response.text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
 
27
  @tool("Gemini search news on the internet")
28
  def gemini_search_news(query):
29
  """Useful to search news about a company, stock or any other
30
  topic and return relevant results"""""
31
+ response = model.generate_content(query)
32
+ return response.text