File size: 1,503 Bytes
4e6748b
 
 
 
 
 
aa910e9
4e6748b
 
 
 
 
 
 
 
 
 
 
fb84bde
 
 
4e6748b
 
 
282d4a3
aa910e9
 
 
 
 
 
 
 
 
4e6748b
 
 
aa910e9
 
 
 
 
 
 
 
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
41
42
43
44
45
# 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."