[AUR-338, AUR-406, AUR-407] Export pipeline to config for PromptUI. Construct PromptUI dynamically based on config. (#16)

From pipeline > config > UI. Provide example project for promptui

- Pipeline to config: `kotaemon.contribs.promptui.config.export_pipeline_to_config`. The config follows schema specified in this document: https://cinnamon-ai.atlassian.net/wiki/spaces/ATM/pages/2748711193/Technical+Detail. Note: this implementation exclude the logs, which will be handled in AUR-408.
- Config to UI: `kotaemon.contribs.promptui.build_from_yaml`
- Example project is located at `examples/promptui/`
This commit is contained in:
Nguyen Trung Duc (john)
2023-09-21 14:27:23 +07:00
committed by GitHub
parent c329c4c03f
commit c6dd01e820
18 changed files with 503 additions and 46 deletions

View File

@@ -1,4 +1,4 @@
from .base import BaseDocumentStore
from .simple import InMemoryDocumentStore
from .in_memory import InMemoryDocumentStore
__all__ = ["BaseDocumentStore", "InMemoryDocumentStore"]

View File

@@ -10,7 +10,7 @@ class InMemoryDocumentStore(BaseDocumentStore):
"""Simple memory document store that store document in a dictionary"""
def __init__(self):
self.store = {}
self._store = {}
def add(
self,
@@ -32,20 +32,20 @@ class InMemoryDocumentStore(BaseDocumentStore):
docs = [docs]
for doc_id, doc in zip(doc_ids, docs):
if doc_id in self.store and not exist_ok:
if doc_id in self._store and not exist_ok:
raise ValueError(f"Document with id {doc_id} already exist")
self.store[doc_id] = doc
self._store[doc_id] = doc
def get(self, ids: Union[List[str], str]) -> List[Document]:
"""Get document by id"""
if not isinstance(ids, list):
ids = [ids]
return [self.store[doc_id] for doc_id in ids]
return [self._store[doc_id] for doc_id in ids]
def get_all(self) -> dict:
"""Get all documents"""
return self.store
return self._store
def delete(self, ids: Union[List[str], str]):
"""Delete document by id"""
@@ -53,11 +53,11 @@ class InMemoryDocumentStore(BaseDocumentStore):
ids = [ids]
for doc_id in ids:
del self.store[doc_id]
del self._store[doc_id]
def save(self, path: Union[str, Path]):
"""Save document to path"""
store = {key: value.to_dict() for key, value in self.store.items()}
store = {key: value.to_dict() for key, value in self._store.items()}
with open(path, "w") as f:
json.dump(store, f)
@@ -65,4 +65,4 @@ class InMemoryDocumentStore(BaseDocumentStore):
"""Load document store from path"""
with open(path) as f:
store = json.load(f)
self.store = {key: Document.from_dict(value) for key, value in store.items()}
self._store = {key: Document.from_dict(value) for key, value in store.items()}