-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent.py
More file actions
40 lines (30 loc) · 970 Bytes
/
Copy pathagent.py
File metadata and controls
40 lines (30 loc) · 970 Bytes
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
import os
import joblib
from dotenv import load_dotenv
from supabase import create_client
import warnings
load_dotenv()
warnings.filterwarnings("ignore", category=UserWarning)
warnings.filterwarnings("ignore", category=FutureWarning)
model = joblib.load("query_intent_model.pkl")
vectorizer = joblib.load("tfidf_vectorizer.pkl")
# supabase client
url = os.getenv("SUPABASE_URL")
key = os.getenv("SUPABASE_KEY")
supabase = create_client(url, key)
def agent(user_query):
vec = vectorizer.transform([user_query])
intent = model.predict(vec)[0]
if intent == "AGGREGATION":
response = supabase.table("employees") \
.select("name, salary") \
.order("salary", desc=True) \
.limit(1) \
.execute()
else:
response = supabase.table("employees") \
.select("*") \
.limit(5) \
.execute()
return response.data
print(agent("Show highest salary employee"))