Spaces:
Runtime error
Runtime error
Create nodexl.py
Browse files
nodexl.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from google import genai
|
| 2 |
+
from google.colab import userdata
|
| 3 |
+
from google.genai import types
|
| 4 |
+
from dotenv import load_env
|
| 5 |
+
import gradio as gr
|
| 6 |
+
import time
|
| 7 |
+
import os
|
| 8 |
+
|
| 9 |
+
load_env()
|
| 10 |
+
|
| 11 |
+
api_key = os.getenv("GEMINI_API_KEY")
|
| 12 |
+
|
| 13 |
+
client = genai.Client(api_key=api_key)
|
| 14 |
+
|
| 15 |
+
grounding_tool = types.Tool(
|
| 16 |
+
google_search=types.GoogleSearch()
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def nodexlSearch(prompt, history):
|
| 21 |
+
"""
|
| 22 |
+
Responds to questions about NodeXL.
|
| 23 |
+
Args:
|
| 24 |
+
prompt: A string representing the search query
|
| 25 |
+
history: A placeholder representing query history
|
| 26 |
+
|
| 27 |
+
Returns:
|
| 28 |
+
Search results in natural language.
|
| 29 |
+
"""
|
| 30 |
+
|
| 31 |
+
# combined_prompt = f"Current information: \n\nQuestion: {prompt}"
|
| 32 |
+
|
| 33 |
+
response = client.models.generate_content(
|
| 34 |
+
model="gemini-2.5-flash",
|
| 35 |
+
config=types.GenerateContentConfig(
|
| 36 |
+
system_instruction="""
|
| 37 |
+
You are a very experienced and knowlegdeable NodeXL expert. Answer only questions about NodeXL.
|
| 38 |
+
If a question is not about NodeXL, give the following response:'Sorry, I can only assist you with NodeXL questions.'
|
| 39 |
+
""",
|
| 40 |
+
tools=[grounding_tool]),
|
| 41 |
+
contents=prompt
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
# stream response
|
| 45 |
+
for each in response.candidates[0].content.parts:
|
| 46 |
+
for i in range(len(each.text)):
|
| 47 |
+
time.sleep(0.001)
|
| 48 |
+
yield each.text[: i+1]
|