crewaiongemini / crewai /tools /gemini_tools.py
eaglelandsonce's picture
Update crewai/tools/gemini_tools.py
aa910e9
raw
history blame
1.5 kB
# tools created using gemini
import json
import os
import google.generativeai as genai
from google.api_core import exceptions
# Retrieve API Key from Environment Variable
GOOGLE_AI_STUDIO = os.environ.get('GOOGLE_AI_STUDIO2')
# Ensure the API key is available
if not GOOGLE_AI_STUDIO:
raise ValueError("API key not found. Please set the GOOGLE_AI_STUDIO2 environment variable.")
import requests
from langchain.tools import tool
# Rest of your code remains the same
genai.configure(api_key=GOOGLE_AI_STUDIO)
model = genai.GenerativeModel('gemini-pro')
class GeminiSearchTools():
@tool("Gemini search the internet")
def gemini_search(query):
try:
response = model.generate_content(query)
return response.text
except exceptions.DeadlineExceeded as e:
# Handle the DeadlineExceeded exception here
print("Error: Deadline Exceeded -", str(e))
# You can return a custom message or take other appropriate actions
return "Error: The request timed out. Please try again later."
@tool("Gemini search news on the internet")
def gemini_search_news(query):
try:
response = model.generate_content(query)
return response.text
except exceptions.DeadlineExceeded as e:
# Handle the DeadlineExceeded exception here
print("Error: Deadline Exceeded -", str(e))
# You can return a custom message or take other appropriate actions
return "Error: The request timed out. Please try again later."