Spaces:
Sleeping
Sleeping
Update query.py
Browse files
query.py
CHANGED
@@ -1,6 +1,5 @@
|
|
1 |
import requests
|
2 |
import json
|
3 |
-
import re
|
4 |
|
5 |
class VectaraQuery():
|
6 |
def __init__(self, api_key: str, customer_id: str, corpus_id: str, prompt_name: str = None):
|
@@ -92,18 +91,18 @@ class VectaraQuery():
|
|
92 |
text = result['text']
|
93 |
print(f"Processing text: {text}") # Debugging line
|
94 |
|
95 |
-
#
|
96 |
-
reason = self.
|
97 |
-
alternative = self.
|
98 |
-
notes = self.
|
99 |
|
100 |
-
response = f"Reason: {reason
|
101 |
print(f"Generated response: {response}") # Debugging line
|
102 |
return response
|
103 |
|
104 |
return "No relevant information found."
|
105 |
|
106 |
-
def
|
107 |
start_idx = text.find(start_keyword)
|
108 |
if start_idx == -1:
|
109 |
return "Not available"
|
|
|
1 |
import requests
|
2 |
import json
|
|
|
3 |
|
4 |
class VectaraQuery():
|
5 |
def __init__(self, api_key: str, customer_id: str, corpus_id: str, prompt_name: str = None):
|
|
|
91 |
text = result['text']
|
92 |
print(f"Processing text: {text}") # Debugging line
|
93 |
|
94 |
+
# Improved keyword-based extraction
|
95 |
+
reason = self.extract_text(text, "Reason:", "Alternative:")
|
96 |
+
alternative = self.extract_text(text, "Alternative:", "Notes:")
|
97 |
+
notes = self.extract_text(text, "Notes:", "")
|
98 |
|
99 |
+
response = f"Reason: {reason}\nAlternative: {alternative}\nNotes: {notes}"
|
100 |
print(f"Generated response: {response}") # Debugging line
|
101 |
return response
|
102 |
|
103 |
return "No relevant information found."
|
104 |
|
105 |
+
def extract_text(self, text, start_keyword, end_keyword):
|
106 |
start_idx = text.find(start_keyword)
|
107 |
if start_idx == -1:
|
108 |
return "Not available"
|