Add documentation about adding reasoning and indexing pipelines to the application (#138)

This commit is contained in:
Duc Nguyen (john)
2024-01-26 22:31:52 +07:00
committed by GitHub
parent 757aabca4d
commit 22c646e5c4
6 changed files with 257 additions and 10 deletions

View File

@@ -73,11 +73,12 @@ class BaseApp:
if getattr(settings, "KH_REASONINGS", None) is None:
return
for name, value in settings.KH_REASONINGS.items():
for value in settings.KH_REASONINGS:
reasoning_cls = import_dotted_string(value, safe=False)
reasonings[name] = reasoning_cls
rid = reasoning_cls.get_info()["id"]
reasonings[rid] = reasoning_cls
options = reasoning_cls().get_user_settings()
self.default_settings.reasoning.options[name] = BaseSettingGroup(
self.default_settings.reasoning.options[rid] = BaseSettingGroup(
settings=options
)

View File

@@ -128,7 +128,7 @@ async def chat_fn(chat_history, files, settings):
pipeline = create_pipeline(settings, files)
pipeline.set_output_queue(queue)
asyncio.create_task(pipeline(chat_input))
asyncio.create_task(pipeline(chat_input, chat_history))
text, refs = "", ""
while True:

View File

@@ -3,7 +3,7 @@ import logging
import warnings
from collections import defaultdict
from functools import partial
from typing import Iterator, Optional
from typing import Optional
import tiktoken
from ktem.components import embeddings, get_docstore, get_vectorstore, llms
@@ -278,7 +278,7 @@ class AnswerWithContextPipeline(BaseComponent):
async def run( # type: ignore
self, question: str, evidence: str, evidence_mode: int = 0
) -> Document | Iterator[Document]:
) -> Document:
"""Answer the question based on the evidence
In addition to the question and the evidence, this method also take into
@@ -342,7 +342,9 @@ class FullQAPipeline(BaseComponent):
evidence_pipeline: PrepareEvidencePipeline = PrepareEvidencePipeline.withx()
answering_pipeline: AnswerWithContextPipeline = AnswerWithContextPipeline.withx()
async def run(self, question: str, **kwargs) -> Document: # type: ignore
async def run( # type: ignore
self, question: str, history: list, **kwargs # type: ignore
) -> Document: # type: ignore
docs = self.retrieval_pipeline(text=question)
evidence_mode, evidence = self.evidence_pipeline(docs).content
answer = await self.answering_pipeline(
@@ -455,3 +457,11 @@ class FullQAPipeline(BaseComponent):
"choices": main_llm_choices,
},
}
@classmethod
def get_info(cls) -> dict:
return {
"id": "simple",
"name": "Simple QA",
"description": "Simple QA pipeline",
}