Spaces:
Sleeping
Sleeping
Update services/qa_service/qna.py
Browse files- services/qa_service/qna.py +13 -9
services/qa_service/qna.py
CHANGED
@@ -2,6 +2,8 @@ import json
|
|
2 |
|
3 |
from services.qa_service.utils import format_prompt
|
4 |
|
|
|
|
|
5 |
class QAService:
|
6 |
def __init__(self, conf, pinecone, model_pipeline, question, goals):
|
7 |
self.conf = conf
|
@@ -22,14 +24,15 @@ class QAService:
|
|
22 |
def parse_results(self, result):
|
23 |
|
24 |
parsed = []
|
25 |
-
for i in result:
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
31 |
|
32 |
-
return
|
33 |
|
34 |
def retrieve_context(self):
|
35 |
"""Pass embedded question into pinecone"""
|
@@ -48,8 +51,9 @@ class QAService:
|
|
48 |
|
49 |
def run(self):
|
50 |
"""Query pinecone outputs and infer results"""
|
51 |
-
|
52 |
-
|
|
|
53 |
prompt = format_prompt(self.question, context)
|
54 |
output = self.model_pipeline.infer(prompt)
|
55 |
|
|
|
2 |
|
3 |
from services.qa_service.utils import format_prompt
|
4 |
|
5 |
+
|
6 |
+
|
7 |
class QAService:
|
8 |
def __init__(self, conf, pinecone, model_pipeline, question, goals):
|
9 |
self.conf = conf
|
|
|
24 |
def parse_results(self, result):
|
25 |
|
26 |
parsed = []
|
27 |
+
for i in result['matches']:
|
28 |
+
collect = i['metadata']['_node_content']
|
29 |
+
content = json.loads(collect)
|
30 |
+
parsed.append({
|
31 |
+
"speakers": content["speakers"],
|
32 |
+
"text": content["text"]
|
33 |
+
})
|
34 |
|
35 |
+
return parsed
|
36 |
|
37 |
def retrieve_context(self):
|
38 |
"""Pass embedded question into pinecone"""
|
|
|
51 |
|
52 |
def run(self):
|
53 |
"""Query pinecone outputs and infer results"""
|
54 |
+
full_context = self.retrieve_context()
|
55 |
+
print(full_context)
|
56 |
+
context = '\n'.join([i["text"] for i in full_context])
|
57 |
prompt = format_prompt(self.question, context)
|
58 |
output = self.model_pipeline.infer(prompt)
|
59 |
|