Spaces:
Sleeping
Sleeping
Jialun He
commited on
Commit
·
733b76c
1
Parent(s):
9a1e75b
update test
Browse files
agent.py
CHANGED
@@ -107,6 +107,24 @@ def arvix_search(query: str) -> str:
|
|
107 |
return {"arvix_results": formatted_search_docs}
|
108 |
|
109 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
|
111 |
# load the system prompt from the file
|
112 |
with open("system_prompt.txt", "r", encoding="utf-8") as f:
|
@@ -132,7 +150,7 @@ create_retriever_tool = create_retriever_tool(
|
|
132 |
description="A tool to retrieve similar questions from a vector store.",
|
133 |
)
|
134 |
|
135 |
-
|
136 |
|
137 |
tools = [
|
138 |
multiply,
|
@@ -196,4 +214,4 @@ def build_graph(provider: str = "google"):
|
|
196 |
builder.add_edge("tools", "assistant")
|
197 |
|
198 |
# Compile graph
|
199 |
-
return builder.compile()
|
|
|
107 |
return {"arvix_results": formatted_search_docs}
|
108 |
|
109 |
|
110 |
+
def test_supabase_connection():
|
111 |
+
load_dotenv()
|
112 |
+
|
113 |
+
try:
|
114 |
+
supabase = create_client(
|
115 |
+
os.environ.get("SUPABASE_URL"),
|
116 |
+
os.environ.get("SUPABASE_SERVICE_KEY")
|
117 |
+
)
|
118 |
+
|
119 |
+
# Test query
|
120 |
+
result = supabase.table('documents').select("*").limit(1).execute()
|
121 |
+
print("Connection successful!")
|
122 |
+
return True
|
123 |
+
|
124 |
+
except Exception as e:
|
125 |
+
print(f"Connection failed: {e}")
|
126 |
+
return False
|
127 |
+
|
128 |
|
129 |
# load the system prompt from the file
|
130 |
with open("system_prompt.txt", "r", encoding="utf-8") as f:
|
|
|
150 |
description="A tool to retrieve similar questions from a vector store.",
|
151 |
)
|
152 |
|
153 |
+
test_supabase_connection()
|
154 |
|
155 |
tools = [
|
156 |
multiply,
|
|
|
214 |
builder.add_edge("tools", "assistant")
|
215 |
|
216 |
# Compile graph
|
217 |
+
return builder.compile()
|
app.py
CHANGED
@@ -25,28 +25,26 @@ class BasicAgent:
|
|
25 |
|
26 |
def __call__(self, question: str) -> str:
|
27 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
|
|
28 |
messages = [HumanMessage(content=question)]
|
29 |
print(f"messages: {messages}")
|
30 |
-
|
31 |
try:
|
32 |
messages = self.graph.invoke({"messages": messages})
|
33 |
print(f"Returned from graph.invoke(): {messages}")
|
34 |
-
|
35 |
-
# Add validation
|
36 |
-
if not messages or 'messages' not in messages:
|
37 |
-
return "Error: No response received from the agent"
|
38 |
-
|
39 |
-
message_list = messages['messages']
|
40 |
-
if not message_list:
|
41 |
-
return "Error: Empty response from the agent"
|
42 |
-
|
43 |
-
answer = message_list[-1].content
|
44 |
-
# Only slice if the answer is long enough
|
45 |
-
return answer[14:] if len(answer) > 14 else answer
|
46 |
-
|
47 |
except Exception as e:
|
48 |
print(f"Exception during graph.invoke: {e}")
|
49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
|
51 |
|
52 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
|
25 |
|
26 |
def __call__(self, question: str) -> str:
|
27 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
28 |
+
# Wrap the question in a HumanMessage from langchain_core
|
29 |
messages = [HumanMessage(content=question)]
|
30 |
print(f"messages: {messages}")
|
|
|
31 |
try:
|
32 |
messages = self.graph.invoke({"messages": messages})
|
33 |
print(f"Returned from graph.invoke(): {messages}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
except Exception as e:
|
35 |
print(f"Exception during graph.invoke: {e}")
|
36 |
+
raise
|
37 |
+
|
38 |
+
# Add validation
|
39 |
+
if not messages or 'messages' not in messages:
|
40 |
+
print(f"Error: No response received from the agent")
|
41 |
+
|
42 |
+
message_list = messages['messages']
|
43 |
+
if not message_list:
|
44 |
+
print(f"Error: Empty response from the agent")
|
45 |
+
answer = messages['messages'][-1].content
|
46 |
+
return answer[14:]
|
47 |
+
|
48 |
|
49 |
|
50 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|