chinesemusk commited on
Commit
e43240b
·
verified ·
1 Parent(s): d1e236b

Update agent.py

Browse files
Files changed (1) hide show
  1. agent.py +22 -1
agent.py CHANGED
@@ -7,9 +7,23 @@ GEMINI_API_KEY = os.environ.get("GEMINI_API_KEY")
7
  genai.configure(api_key=GEMINI_API_KEY)
8
  model = genai.GenerativeModel('models/gemini-1.5-flash-latest')
9
 
 
 
 
 
 
 
 
 
10
  def handle_user_query(query):
11
  lowered = query.lower()
12
 
 
 
 
 
 
 
13
  if "fetch" in lowered and "http" in lowered:
14
  url = query.split()[-1]
15
  return fetch_website(url)
@@ -22,7 +36,14 @@ def handle_user_query(query):
22
 
23
  def call_gemini(prompt):
24
  try:
25
- response = model.generate_content(prompt)
 
 
 
 
 
 
 
26
  return response.text
27
  except Exception as e:
28
  return f"Error from Gemini: {e}"
 
7
  genai.configure(api_key=GEMINI_API_KEY)
8
  model = genai.GenerativeModel('models/gemini-1.5-flash-latest')
9
 
10
+ # ✅ System instructions / known facts:
11
+ background_knowledge = {
12
+ "who built this": "This Stellar Knowledge Agent was built by Chinese.",
13
+ "who is the stellar east africa president": "The current Stellar East Africa President is Sarah Wahinya.",
14
+ "stellar east africa twitter": "You can follow Stellar East Africa on Twitter: https://x.com/StellarEastAfri",
15
+ "stellar east africa website": "Visit https://stellarea.org to learn more about Stellar East Africa.",
16
+ }
17
+
18
  def handle_user_query(query):
19
  lowered = query.lower()
20
 
21
+ # ✅ Check if query is directly about known background info
22
+ for known_q, answer in background_knowledge.items():
23
+ if known_q in lowered:
24
+ return answer
25
+
26
+ # ✅ Check if query is about tools
27
  if "fetch" in lowered and "http" in lowered:
28
  url = query.split()[-1]
29
  return fetch_website(url)
 
36
 
37
  def call_gemini(prompt):
38
  try:
39
+ # Add system instructions / context as part of prompt
40
+ context = """
41
+ You are Stellar Knowledge Agent built by Deon Chinese for Stellar East Africa.
42
+ The current Stellar East Africa President is Sarah Wahinya The famous sonnie.
43
+ Twitter: https://x.com/StellarEastAfri
44
+ Website: https://stellarea.org
45
+ """
46
+ response = model.generate_content(context + "\nUser: " + prompt)
47
  return response.text
48
  except Exception as e:
49
  return f"Error from Gemini: {e}"