Spaces:
Sleeping
Sleeping
Commit
·
77e0ca9
1
Parent(s):
07c1285
Update app.py
Browse files
app.py
CHANGED
@@ -76,9 +76,11 @@ class SemanticSearch:
|
|
76 |
self.fitted = True
|
77 |
|
78 |
def call(self, text, return_data=True):
|
|
|
|
|
79 |
inp_emb = self.use([text])
|
80 |
neighbors = self.nn.kneighbors(inp_emb, return_distance=False)[0]
|
81 |
-
|
82 |
if return_data:
|
83 |
return [self.data[i] for i in neighbors]
|
84 |
else:
|
@@ -115,6 +117,9 @@ def generate_text(openAI_key,prompt, engine="text-davinci-003"):
|
|
115 |
|
116 |
def generate_answer(question,openAI_key):
|
117 |
topn_chunks = recommender.call(question)
|
|
|
|
|
|
|
118 |
prompt = ""
|
119 |
prompt += 'search results:\n\n'
|
120 |
for c in topn_chunks:
|
|
|
76 |
self.fitted = True
|
77 |
|
78 |
def call(self, text, return_data=True):
|
79 |
+
if not self.fitted:
|
80 |
+
raise Exception("The fit method must be called before the call method.")
|
81 |
inp_emb = self.use([text])
|
82 |
neighbors = self.nn.kneighbors(inp_emb, return_distance=False)[0]
|
83 |
+
|
84 |
if return_data:
|
85 |
return [self.data[i] for i in neighbors]
|
86 |
else:
|
|
|
117 |
|
118 |
def generate_answer(question,openAI_key):
|
119 |
topn_chunks = recommender.call(question)
|
120 |
+
if not recommender.fitted:
|
121 |
+
st.error('The recommender is not fitted yet.')
|
122 |
+
return
|
123 |
prompt = ""
|
124 |
prompt += 'search results:\n\n'
|
125 |
for c in topn_chunks:
|