AC-Angelo93 commited on
Commit
7ff1ac7
·
verified ·
1 Parent(s): 3daadb9

Update agent.py

Browse files
Files changed (1) hide show
  1. agent.py +18 -0
agent.py CHANGED
@@ -2,6 +2,7 @@
2
  import os
3
  from supabase import create_client
4
  from sentence_transformers import SentenceTransformers
 
5
  from langgraph import Graph, LLM, tool #or other graph library
6
 
7
  # ----Supabase setup----
@@ -9,6 +10,7 @@ SUPABASE_URL = os.getenv("SUPABASE_URL")
9
  SUPABASE_KEY = os.getenv("SUPABASE_SERVICE_KEY")
10
  EMBED_MODEL_ID = os.getenv("HF_EMBEDDING_MODEL")
11
 
 
12
  sb_client = create_client(SUPABASE_URL, SUPABASE_KEY)
13
  embedder = SentenceTransformers(EMBED_MODEL_ID)
14
 
@@ -46,6 +48,22 @@ def retrieve_docs(query: str, k: int = 3) -> str:
46
  docs = [row["content"] for row in rows]
47
  return "\n\n---\n\n".join(docs)
48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
 
50
  # 2) Build your graph
51
  def build_graph(provider: str = "huggingface") -> Graph:
 
2
  import os
3
  from supabase import create_client
4
  from sentence_transformers import SentenceTransformers
5
+ from serpapi import GoogleSearch
6
  from langgraph import Graph, LLM, tool #or other graph library
7
 
8
  # ----Supabase setup----
 
10
  SUPABASE_KEY = os.getenv("SUPABASE_SERVICE_KEY")
11
  EMBED_MODEL_ID = os.getenv("HF_EMBEDDING_MODEL")
12
 
13
+
14
  sb_client = create_client(SUPABASE_URL, SUPABASE_KEY)
15
  embedder = SentenceTransformers(EMBED_MODEL_ID)
16
 
 
48
  docs = [row["content"] for row in rows]
49
  return "\n\n---\n\n".join(docs)
50
 
51
+ SERPAPI_KEY = os.getenv("SERPAPY_KEY")
52
+ # ---- web_search tool
53
+ @tool
54
+ def web_search(query: str, num_results: int = 5) -> str:
55
+ """ Return top-5 snippets from Google search via SerpAPI."""
56
+ params = {
57
+ "engine": "google",
58
+ "q": query,
59
+ "num": num_results,
60
+ "api_key": SERPAPI_KEY,
61
+ }
62
+ search = GoogleSearch(params)
63
+ results = search.get_dict().get("organic_results", [])
64
+ snippets = [r.get("snippet","")for r in results]
65
+ return "\n".join(f"- {s}" for s in snippets)
66
+
67
 
68
  # 2) Build your graph
69
  def build_graph(provider: str = "huggingface") -> Graph: