-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction_call.py
More file actions
63 lines (51 loc) · 2.26 KB
/
function_call.py
File metadata and controls
63 lines (51 loc) · 2.26 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import json
import pandas as pd
from pandasql import sqldf
from google import genai
import os
import sys
import functions
from functions import write_to_html, get_data_by_attribute_function, early_stage_investment_volume, get_deal_data_by_attribute
# Configuration for the client; your functions are provided as tools.
config = {
"tools": [get_data_by_attribute_function, write_to_html, early_stage_investment_volume, get_deal_data_by_attribute]
}
client = genai.Client(api_key="AIzaSyB57DPx67DwuoetWePSm7eabr5Rw7U-RPE")
# Get user query from stdin or command line or environment variable
user_prompt = ""
if not sys.stdin.isatty(): # Check if data is being piped in
user_prompt = sys.stdin.read().strip()
else:
user_prompt = os.environ.get('USER_QUERY', '')
if not user_prompt:
user_prompt = input("Put in your question: ")
try:
# Get current script directory
script_dir = os.path.dirname(os.path.abspath(__file__))
system_prompt_path = os.path.join(script_dir, "alt_prompt.txt")
# Check if file exists in current directory
if not os.path.exists(system_prompt_path):
print(f"System prompt not found at {system_prompt_path}, checking react-ui directory...")
# Try react-ui directory as fallback
system_prompt_path = os.path.join(script_dir, "react-ui", "system_prompt.txt")
# If still not found, try absolute path
if not os.path.exists(system_prompt_path):
print(f"System prompt not found at {system_prompt_path}, trying one more location...")
# Try one more location
system_prompt_path = os.path.abspath("system_prompt.txt")
# Final check
if not os.path.exists(system_prompt_path):
print(f"Error: System prompt file not found at any location. Last tried: {system_prompt_path}")
sys.exit(1)
print(f"Using system prompt from: {system_prompt_path}")
with open(system_prompt_path, "r", encoding="utf-8") as file:
system_prompt = file.read()
response = client.models.generate_content(
model="gemini-2.0-flash",
contents=system_prompt +"\n \n \n and now comes the user prompt: \n" + user_prompt,
config=config
)
print(response.text)
except Exception as e:
print(f"Error: {str(e)}")
sys.exit(1)