refactor: Add config for init, app and query (#158)
This commit is contained in:
8
embedchain/config/AddConfig.py
Normal file
8
embedchain/config/AddConfig.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from embedchain.config.BaseConfig import BaseConfig
|
||||
|
||||
class AddConfig(BaseConfig):
|
||||
"""
|
||||
Config for the `add` method.
|
||||
"""
|
||||
def __init__(self):
|
||||
pass
|
||||
9
embedchain/config/BaseConfig.py
Normal file
9
embedchain/config/BaseConfig.py
Normal file
@@ -0,0 +1,9 @@
|
||||
class BaseConfig:
|
||||
"""
|
||||
Base config.
|
||||
"""
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def as_dict(self):
|
||||
return vars(self)
|
||||
8
embedchain/config/ChatConfig.py
Normal file
8
embedchain/config/ChatConfig.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from embedchain.config.QueryConfig import QueryConfig
|
||||
|
||||
class ChatConfig(QueryConfig):
|
||||
"""
|
||||
Config for the `chat` method, inherits from `QueryConfig`.
|
||||
"""
|
||||
def __init__(self):
|
||||
pass
|
||||
36
embedchain/config/InitConfig.py
Normal file
36
embedchain/config/InitConfig.py
Normal file
@@ -0,0 +1,36 @@
|
||||
import os
|
||||
|
||||
from embedchain.config.BaseConfig import BaseConfig
|
||||
|
||||
class InitConfig(BaseConfig):
|
||||
"""
|
||||
Config to initialize an embedchain `App` instance.
|
||||
"""
|
||||
def __init__(self, ef=None, db=None):
|
||||
"""
|
||||
:param ef: Optional. Embedding function to use.
|
||||
:param db: Optional. (Vector) database to use for embeddings.
|
||||
"""
|
||||
# Embedding Function
|
||||
if ef is None:
|
||||
from chromadb.utils import embedding_functions
|
||||
self.ef = embedding_functions.OpenAIEmbeddingFunction(
|
||||
api_key=os.getenv("OPENAI_API_KEY"),
|
||||
organization_id=os.getenv("OPENAI_ORGANIZATION"),
|
||||
model_name="text-embedding-ada-002"
|
||||
)
|
||||
else:
|
||||
self.ef = ef
|
||||
|
||||
if db is None:
|
||||
from embedchain.vectordb.chroma_db import ChromaDB
|
||||
self.db = ChromaDB(ef=self.ef)
|
||||
else:
|
||||
self.db = db
|
||||
|
||||
return
|
||||
|
||||
|
||||
def _set_embedding_function(self, ef):
|
||||
self.ef = ef
|
||||
return
|
||||
8
embedchain/config/QueryConfig.py
Normal file
8
embedchain/config/QueryConfig.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from embedchain.config.BaseConfig import BaseConfig
|
||||
|
||||
class QueryConfig(BaseConfig):
|
||||
"""
|
||||
Config for the `query` method.
|
||||
"""
|
||||
def __init__(self):
|
||||
pass
|
||||
5
embedchain/config/__init__.py
Normal file
5
embedchain/config/__init__.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from .BaseConfig import BaseConfig
|
||||
from .AddConfig import AddConfig
|
||||
from .ChatConfig import ChatConfig
|
||||
from .InitConfig import InitConfig
|
||||
from .QueryConfig import QueryConfig
|
||||
Reference in New Issue
Block a user