silvanocerza commited on
Commit
587a001
1 Parent(s): f3fc704

Enhance query pipeline

Browse files
Files changed (1) hide show
  1. main.py +24 -16
main.py CHANGED
@@ -97,35 +97,43 @@ def index_files(files):
97
  for f in files:
98
  paths.append(f["path"])
99
  metadata.append(f["metadata"])
100
- indexing_pipeline.run({"converter": {"paths": paths, "metadata": metadata}})
 
 
 
 
 
 
 
101
 
102
 
103
  def search(question: str) -> GeneratedAnswer:
104
  retriever = MemoryBM25Retriever(document_store=document_store(), top_k=5)
105
 
106
- template = """Take a deep breath and think then answer given the context
107
- Context: {{ documents|map(attribute='text')|replace('\n', ' ')|join(';') }}
108
- Question: {{ query }}
109
- Answer:
110
- """
 
111
  prompt_builder = PromptBuilder(template)
112
 
113
  OPENAI_API_KEY = os.getenv("OPENAI_API_KEY", "")
114
  generator = GPTGenerator(api_key=OPENAI_API_KEY)
115
  answer_builder = AnswerBuilder()
116
 
117
- pipe = Pipeline()
118
 
119
- pipe.add_component("docs_retriever", retriever)
120
- pipe.add_component("prompt_builder", prompt_builder)
121
- pipe.add_component("gpt35", generator)
122
- pipe.add_component("answer_builder", answer_builder)
123
 
124
- pipe.connect("docs_retriever.documents", "prompt_builder.documents")
125
- pipe.connect("prompt_builder.prompt", "gpt35.prompt")
126
- pipe.connect("docs_retriever.documents", "answer_builder.documents")
127
- pipe.connect("gpt35.replies", "answer_builder.replies")
128
- res = pipe.run(
129
  {
130
  "docs_retriever": {"query": question},
131
  "prompt_builder": {"query": question},
 
97
  for f in files:
98
  paths.append(f["path"])
99
  metadata.append(f["metadata"])
100
+ indexing_pipeline.run(
101
+ {
102
+ "converter": {
103
+ "paths": paths,
104
+ "metadata": metadata,
105
+ }
106
+ }
107
+ )
108
 
109
 
110
  def search(question: str) -> GeneratedAnswer:
111
  retriever = MemoryBM25Retriever(document_store=document_store(), top_k=5)
112
 
113
+ template = (
114
+ "Take a deep breath and think then answer given the context"
115
+ "Context: {{ documents|map(attribute='text')|replace('\n', ' ')|join(';') }}"
116
+ "Question: {{ query }}"
117
+ "Answer:"
118
+ )
119
  prompt_builder = PromptBuilder(template)
120
 
121
  OPENAI_API_KEY = os.getenv("OPENAI_API_KEY", "")
122
  generator = GPTGenerator(api_key=OPENAI_API_KEY)
123
  answer_builder = AnswerBuilder()
124
 
125
+ query_pipeline = Pipeline()
126
 
127
+ query_pipeline.add_component("docs_retriever", retriever)
128
+ query_pipeline.add_component("prompt_builder", prompt_builder)
129
+ query_pipeline.add_component("gpt35", generator)
130
+ query_pipeline.add_component("answer_builder", answer_builder)
131
 
132
+ query_pipeline.connect("docs_retriever.documents", "prompt_builder.documents")
133
+ query_pipeline.connect("prompt_builder.prompt", "gpt35.prompt")
134
+ query_pipeline.connect("docs_retriever.documents", "answer_builder.documents")
135
+ query_pipeline.connect("gpt35.replies", "answer_builder.replies")
136
+ res = query_pipeline.run(
137
  {
138
  "docs_retriever": {"query": question},
139
  "prompt_builder": {"query": question},