Spaces:
Build error
Build error
Commit
·
587a001
1
Parent(s):
f3fc704
Enhance query pipeline
Browse files
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(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
|
| 102 |
|
| 103 |
def search(question: str) -> GeneratedAnswer:
|
| 104 |
retriever = MemoryBM25Retriever(document_store=document_store(), top_k=5)
|
| 105 |
|
| 106 |
-
template =
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 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 |
-
|
| 118 |
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
res =
|
| 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},
|