Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sqlite Changes #472

Merged
merged 23 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
64956e3
Adding confidence score to entities and topic responses (#460)
dristysrivastava Aug 7, 2024
c0cc455
Sqlite implementation initial code (#467)
shreyas-damle Aug 8, 2024
e3ffe54
Adding confidence score to entities and topic responses (#460)
dristysrivastava Aug 7, 2024
9d596a5
Added DB implementation for /prompt API (#468)
dristysrivastava Aug 12, 2024
add7a7a
Discovery API (#471)
shreyas-damle Aug 12, 2024
e4418f8
Confidence score changes in Entity Classifier (#473)
gr8nishan Aug 13, 2024
06e8557
Added changes for prompt group (#466)
gr8nishan Aug 14, 2024
55a7d98
Loader Doc API DB Implementation (#478)
shreyas-damle Aug 16, 2024
29e441b
confidence score UI (#480)
rutujaac Aug 20, 2024
dff1c6c
Changes for confidence score in /loader/doc as well as UI API (#470)
dristysrivastava Aug 20, 2024
2fe2294
Local UI API changes (SafeRetriever for Local UI Dashboard) (#479)
dristysrivastava Aug 20, 2024
a8796fb
Loader doc db changes and fixes (#481)
shreyas-damle Aug 20, 2024
2506711
added fix for entity classification happening in prompt api for promp…
gr8nishan Aug 20, 2024
1e7c334
Merge branch 'pebblo-0.1.18' into sqlite-changes
shreyas-damle Aug 20, 2024
e5693dd
Sqlite Fixes (#483)
shreyas-damle Aug 20, 2024
0d79d1d
Adding details as well as delete APIs for Retriever DB Apps (#484)
dristysrivastava Aug 21, 2024
66cd405
Added local-ui utils file (#488)
dristysrivastava Aug 21, 2024
7283538
Sqlite local UI (#485)
shreyas-damle Aug 22, 2024
f53a509
Updating /prompt/ as well as /delete API (#491)
dristysrivastava Aug 22, 2024
c2e2c9e
Merge branch 'main' into sqlite-changes
dristysrivastava Aug 22, 2024
0ad250f
Loader App Delete and PDF generation (#492)
shreyas-damle Aug 22, 2024
4fb17dc
Fixed issue due to conflict resolution (#493)
dristysrivastava Aug 22, 2024
19859f3
Make sqlite table creational conditional (#494)
shreyas-damle Aug 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions pebblo/app/api/api.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from fastapi import APIRouter
from fastapi import APIRouter, Depends

from pebblo.app.service.discovery_service import AppDiscover
from pebblo.app.config.config import var_server_config_dict
from pebblo.app.service.prompt_gov import PromptGov
from pebblo.app.service.prompt_service import Prompt
from pebblo.app.service.service import AppLoaderDoc
from pebblo.app.utils.handler_mapper import get_handler

config_details = var_server_config_dict.get()


class App:
Expand All @@ -15,24 +16,30 @@ def __init__(self, prefix: str):
self.router = APIRouter(prefix=prefix)

@staticmethod
def discover(data: dict):
def discover(
data: dict, discover_obj=Depends(lambda: get_handler(handler_name="discover"))
):
# "/app/discover" API entrypoint
discovery_obj = AppDiscover(data=data)
response = discovery_obj.process_request()
# Execute discover object based on a storage type
response = discover_obj.process_request(data)
return response

@staticmethod
def loader_doc(data: dict):
def loader_doc(
data: dict, loader_doc_obj=Depends(lambda: get_handler(handler_name="loader"))
):
# "/loader/doc" API entrypoint
loader_doc_obj = AppLoaderDoc(data=data)
response = loader_doc_obj.process_request()
# Execute loader doc object based on a storage type
response = loader_doc_obj.process_request(data)
return response

@staticmethod
def prompt(data: dict):
def prompt(
data: dict, prompt_obj=Depends(lambda: get_handler(handler_name="prompt"))
):
# "/prompt" API entrypoint
prompt_obj = Prompt(data=data)
response = prompt_obj.process_request()
# Execute a prompt object based on a storage type
response = prompt_obj.process_request(data)
return response

@staticmethod
Expand Down
16 changes: 14 additions & 2 deletions pebblo/app/config/config.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import pathlib
from contextvars import ContextVar
from typing import Tuple
from typing import Tuple, Union

import yaml
from pydantic import BaseSettings, Field

from pebblo.app.config.config_validation import validate_config, validate_input
from pebblo.app.enums.common import DBStorageTypes, StorageTypes

# Default config value
dir_path = pathlib.Path().absolute()
Expand Down Expand Up @@ -45,12 +46,21 @@ class ClassifierConfig(BaseSettings):
anonymizeSnippets: bool = Field(default=True)


class StorageConfig(BaseSettings):
type: str = Field(default=StorageTypes.FILE.value)
db: Union[str, None] = Field(default=DBStorageTypes.SQLITE.value)
location: Union[str, None] = Field(default=str(dir_path))
name: Union[str, None] = Field(default=str("pebblo"))
# This is default value for current version(0.1.18), it needs to be changed in next version to db.


# ConfigFile BaseModel
class Config(BaseSettings):
daemon: PortConfig
reports: ReportConfig
logging: LoggingConfig
classifier: ClassifierConfig
storage: StorageConfig


var_server_config: ContextVar[Config] = ContextVar("server_config", default=None)
Expand All @@ -67,6 +77,8 @@ def load_config(path: str) -> Tuple[dict, Config]:
),
logging=LoggingConfig(),
classifier=ClassifierConfig(anonymizeSnippets=False),
storage=StorageConfig(type="file", db=None),
shreyas-damle marked this conversation as resolved.
Show resolved Hide resolved
# for now, a default storage type is FILE, but in the next release DB will be the default storage type.
)
if not path:
# Setting Default config details
Expand Down Expand Up @@ -95,4 +107,4 @@ def load_config(path: str) -> Tuple[dict, Config]:

except Exception as err:
print(f"Error while loading config details, err: {err}")
return {}
return {}, {}
2 changes: 2 additions & 0 deletions pebblo/app/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ reports:
cacheDir: ~/.pebblo
classifier:
anonymizeSnippets: False
storage:
type: file
42 changes: 42 additions & 0 deletions pebblo/app/config/config_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import sys
from abc import ABC, abstractmethod

from pebblo.app.enums.common import DBStorageTypes, StorageTypes


class ConfigValidator(ABC):
def __init__(self, config):
Expand Down Expand Up @@ -42,6 +44,45 @@ def validate(self):
)


class StorageConfig(ConfigValidator):
def validate(self):
shreyas-damle marked this conversation as resolved.
Show resolved Hide resolved
storage_type = self.config.get("type")
valid_storage_types = [storage_type.value for storage_type in StorageTypes]
if storage_type not in valid_storage_types:
self.errors.append(
f"Error: Unsupported storage type '{storage_type}' specified in the configuration."
f"Valid values are {valid_storage_types}"
)

# Set deprecated warning message for file storage type
if storage_type == StorageTypes.FILE.value:
deprecate_error = f"DeprecationWarning: '{storage_type}' Storage Type will be deprecated starting from Pebblo version 0.0.19, use '{StorageTypes.DATABASE.value}' instead"
print(deprecate_error)
shreyas-damle marked this conversation as resolved.
Show resolved Hide resolved

if storage_type == StorageTypes.DATABASE.value:
db_type = self.config.get("db")
default_location = self.config.get("location")
db_name = self.config.get("name")

valid_db_types = [storage_type.value for storage_type in DBStorageTypes]
if db_type not in valid_db_types:
self.errors.append(
f"Error: Unsupported db type '{db_type}' specified in the configuration."
f"Valid values are {valid_db_types}"
)

# db_name should be in string
if not isinstance(db_name, str):
self.errors.append(
f"Error: Unsupported db name '{db_name} specified in the configuration"
f"String values are allowed only"
)

# Check if the output directory exists, create if it doesn't
if not os.path.exists(expand_path(str(default_location))):
os.makedirs(expand_path(str(default_location)), exist_ok=True)


def expand_path(file_path: str) -> str:
# Expand user (~) and environment variables
expanded_path = os.path.expanduser(file_path)
Expand Down Expand Up @@ -102,6 +143,7 @@ def validate_config(config_dict):
"logging": LoggingConfig,
"reports": ReportsConfig,
"classifier": ClassifierConfig,
"storage": StorageConfig,
}

validation_errors = []
Expand Down
2 changes: 1 addition & 1 deletion pebblo/app/config/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
from pebblo.app.exceptions.exception_handler import exception_handlers
from pebblo.app.routers.local_ui_routers import local_ui_router_instance
from pebblo.app.routers.redirection_router import redirect_router_instance
from pebblo.log import get_logger, get_uvicorn_logconfig

with redirect_stdout(StringIO()), redirect_stderr(StringIO()):
from pebblo.app.routers.routers import router_instance
from pebblo.log import get_logger, get_uvicorn_logconfig

logger = get_logger(__name__)

Expand Down
11 changes: 11 additions & 0 deletions pebblo/app/enums/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from enum import Enum


class StorageTypes(Enum):
FILE = "file"
DATABASE = "db"


class DBStorageTypes(Enum):
SQLITE = "sqlite"
MONGODB = "mongodb"
5 changes: 5 additions & 0 deletions pebblo/app/enums/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ class CacheDir(Enum):
f"http://{config_details.get('daemon', {}).get('host')}:"
f"{config_details.get('daemon', {}).get('port')}"
)
DB_NAME = config_details.get("storage", {}).get("name")
DB_LOCATION = config_details.get("storage", {}).get("location")

SQLITE_ENGINE = "sqlite:///{}/pebblo.db"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make the path/location to this .db file configurable with a proper default location

# SQLITE_ENGINE = f"sqlite:///{DB_LOCATION}/{DB_NAME}.db"


class ReportConstants(Enum):
Expand Down
Loading