tykiww commited on
Commit
b579ccf
·
verified ·
1 Parent(s): 515b5a9

Update services/qa_service/qna.py

Browse files
Files changed (1) hide show
  1. 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
- level_1 = i['matches']
28
- level_2 = level_1['metadata']['_node_content']
29
- collect = json.loads(level_2)["text"]
30
- parsed.append(collect)
 
31
 
32
- return collect
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
- print(self.retrieve_context())
52
- context = '\n'.join(self.retrieve_context())
 
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