File size: 1,189 Bytes
26a7e64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from google import genai
from google.genai import types
import gradio as gr
import time
import os

api_key = os.getenv("GEMINI_API_KEY")

client = genai.Client(api_key=api_key)

grounding_tool = types.Tool(
    google_search=types.GoogleSearch()
)


def nodexlSearch(prompt, history):
  """
  Responds to questions about NodeXL.
  Args:
      prompt: A string representing the search query
      history: A placeholder representing query history

  Returns:
      Search results in natural language.
  """

  # combined_prompt = f"Current information: \n\nQuestion: {prompt}"

  response = client.models.generate_content(
    model="gemini-2.5-flash",
    config=types.GenerateContentConfig(
        system_instruction="""
        You are a very experienced and knowlegdeable NodeXL expert. Answer only questions about NodeXL. 
        If a question is not about NodeXL, give the following response:'Sorry, I can only assist you with NodeXL questions.'
        """,
        tools=[grounding_tool]),
    contents=prompt
  )

  # 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]