Merge pull request #1 from Cinnamon/misc/config-model-from-file
Misc/config model from file
This commit is contained in:
commit
b2089245f2
18
.env
Normal file
18
.env
Normal file
|
@ -0,0 +1,18 @@
|
|||
# settings for OpenAI
|
||||
OPENAI_API_BASE=https://api.openai.com/v1
|
||||
OPENAI_API_KEY=
|
||||
OPENAI_CHAT_MODEL=gpt-3.5-turbo
|
||||
OPENAI_EMBEDDINGS_MODEL=text-embedding-ada-002
|
||||
|
||||
# settings for Azure OpenAI
|
||||
AZURE_OPENAI_ENDPOINT=
|
||||
AZURE_OPENAI_API_KEY=
|
||||
OPENAI_API_VERSION=2024-02-15-preview
|
||||
AZURE_OPENAI_CHAT_DEPLOYMENT=gpt-35-turbo
|
||||
AZURE_OPENAI_EMBEDDINGS_DEPLOYMENT=text-embedding-ada-002
|
||||
|
||||
# settings for Cohere
|
||||
COHERE_API_KEY=
|
||||
|
||||
# settings for local models
|
||||
LOCAL_MODEL=
|
BIN
.env.secret
BIN
.env.secret
Binary file not shown.
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -332,7 +332,6 @@ celerybeat.pid
|
|||
*.sage.py
|
||||
|
||||
# Environments
|
||||
.env
|
||||
.venv
|
||||
env/
|
||||
venv/
|
||||
|
@ -457,7 +456,6 @@ $RECYCLE.BIN/
|
|||
logs/
|
||||
.gitsecret/keys/random_seed
|
||||
!*.secret
|
||||
.env
|
||||
.envrc
|
||||
|
||||
S.gpg-agent*
|
||||
|
@ -467,4 +465,4 @@ storage/*
|
|||
|
||||
# Conda and env storages
|
||||
*install_dir/
|
||||
doc_env
|
||||
doc_env/
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -1 +0,0 @@
|
|||
.env:555d804179d7207ad6784a84afb88d2ec44f90ea3b7a061d0e38f9dd53fe7211
|
|
@ -137,14 +137,14 @@ class AzureOpenAIEmbeddings(LCEmbeddingMixin, BaseEmbeddings):
|
|||
azure_endpoint: Optional[str] = None,
|
||||
deployment: Optional[str] = None,
|
||||
openai_api_key: Optional[str] = None,
|
||||
openai_api_version: Optional[str] = None,
|
||||
api_version: Optional[str] = None,
|
||||
request_timeout: Optional[float] = None,
|
||||
**params,
|
||||
):
|
||||
super().__init__(
|
||||
azure_endpoint=azure_endpoint,
|
||||
deployment=deployment,
|
||||
openai_api_version=openai_api_version,
|
||||
api_version=api_version,
|
||||
openai_api_key=openai_api_key,
|
||||
request_timeout=request_timeout,
|
||||
**params,
|
||||
|
|
|
@ -2,7 +2,7 @@ from kotaemon.base.schema import AIMessage, BaseMessage, HumanMessage, SystemMes
|
|||
|
||||
from .base import BaseLLM
|
||||
from .branching import GatedBranchingPipeline, SimpleBranchingPipeline
|
||||
from .chats import AzureChatOpenAI, ChatLLM, EndpointChatLLM, LlamaCppChat
|
||||
from .chats import AzureChatOpenAI, ChatLLM, ChatOpenAI, EndpointChatLLM, LlamaCppChat
|
||||
from .completions import LLM, AzureOpenAI, LlamaCpp, OpenAI
|
||||
from .cot import ManualSequentialChainOfThought, Thought
|
||||
from .linear import GatedLinearPipeline, SimpleLinearPipeline
|
||||
|
@ -17,6 +17,7 @@ __all__ = [
|
|||
"HumanMessage",
|
||||
"AIMessage",
|
||||
"SystemMessage",
|
||||
"ChatOpenAI",
|
||||
"AzureChatOpenAI",
|
||||
"LlamaCppChat",
|
||||
# completion-specific components
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
from .base import ChatLLM
|
||||
from .endpoint_based import EndpointChatLLM
|
||||
from .langchain_based import AzureChatOpenAI, LCChatMixin
|
||||
from .langchain_based import AzureChatOpenAI, ChatOpenAI, LCChatMixin
|
||||
from .llamacpp import LlamaCppChat
|
||||
|
||||
__all__ = [
|
||||
"ChatLLM",
|
||||
"EndpointChatLLM",
|
||||
"ChatOpenAI",
|
||||
"AzureChatOpenAI",
|
||||
"LCChatMixin",
|
||||
"LlamaCppChat",
|
||||
|
|
|
@ -165,7 +165,36 @@ class LCChatMixin:
|
|||
raise ValueError(f"Invalid param {path}")
|
||||
|
||||
|
||||
class ChatOpenAI(LCChatMixin, ChatLLM): # type: ignore
|
||||
def __init__(
|
||||
self,
|
||||
openai_api_base: str | None = None,
|
||||
openai_api_key: str | None = None,
|
||||
model: str | None = None,
|
||||
temperature: float = 0.7,
|
||||
request_timeout: float | None = None,
|
||||
**params,
|
||||
):
|
||||
super().__init__(
|
||||
openai_api_base=openai_api_base,
|
||||
openai_api_key=openai_api_key,
|
||||
model=model,
|
||||
temperature=temperature,
|
||||
request_timeout=request_timeout,
|
||||
**params,
|
||||
)
|
||||
|
||||
def _get_lc_class(self):
|
||||
try:
|
||||
from langchain_openai import ChatOpenAI
|
||||
except ImportError:
|
||||
from langchain.chat_models import ChatOpenAI
|
||||
|
||||
return ChatOpenAI
|
||||
|
||||
|
||||
class AzureChatOpenAI(LCChatMixin, ChatLLM): # type: ignore
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
azure_endpoint: str | None = None,
|
||||
|
|
|
@ -31,70 +31,98 @@ KH_VECTORSTORE = {
|
|||
"__type__": "kotaemon.storages.ChromaVectorStore",
|
||||
"path": str(user_cache_dir / "vectorstore"),
|
||||
}
|
||||
KH_LLMS = {
|
||||
# example for using Azure OpenAI, the config variables can set as environment
|
||||
# variables or in the .env file
|
||||
# "gpt4": {
|
||||
# "def": {
|
||||
# "__type__": "kotaemon.llms.AzureChatOpenAI",
|
||||
# "temperature": 0,
|
||||
# "azure_endpoint": config("AZURE_OPENAI_ENDPOINT", default=""),
|
||||
# "openai_api_key": config("AZURE_OPENAI_API_KEY", default=""),
|
||||
# "openai_api_version": config("OPENAI_API_VERSION", default=""),
|
||||
# "deployment_name": "<your deployment name>",
|
||||
# "stream": True,
|
||||
# },
|
||||
# "accuracy": 10,
|
||||
# "cost": 10,
|
||||
# "default": False,
|
||||
# },
|
||||
# "gpt35": {
|
||||
# "def": {
|
||||
# "__type__": "kotaemon.llms.AzureChatOpenAI",
|
||||
# "temperature": 0,
|
||||
# "azure_endpoint": config("AZURE_OPENAI_ENDPOINT", default=""),
|
||||
# "openai_api_key": config("AZURE_OPENAI_API_KEY", default=""),
|
||||
# "openai_api_version": config("OPENAI_API_VERSION", default=""),
|
||||
# "deployment_name": "<your deployment name>",
|
||||
# "request_timeout": 10,
|
||||
# "stream": False,
|
||||
# },
|
||||
# "accuracy": 5,
|
||||
# "cost": 5,
|
||||
# "default": False,
|
||||
# },
|
||||
"local": {
|
||||
KH_LLMS = {}
|
||||
KH_EMBEDDINGS = {}
|
||||
|
||||
# populate options from config
|
||||
if config("AZURE_OPENAI_API_KEY", default="") and config(
|
||||
"AZURE_OPENAI_ENDPOINT", default=""
|
||||
):
|
||||
if config("AZURE_OPENAI_CHAT_DEPLOYMENT", default=""):
|
||||
KH_LLMS["azure"] = {
|
||||
"def": {
|
||||
"__type__": "kotaemon.llms.AzureChatOpenAI",
|
||||
"temperature": 0,
|
||||
"azure_endpoint": config("AZURE_OPENAI_ENDPOINT", default=""),
|
||||
"openai_api_key": config("AZURE_OPENAI_API_KEY", default=""),
|
||||
"api_version": config("OPENAI_API_VERSION", default="")
|
||||
or "2024-02-15-preview",
|
||||
"deployment_name": config("AZURE_OPENAI_CHAT_DEPLOYMENT", default=""),
|
||||
"request_timeout": 10,
|
||||
"stream": False,
|
||||
},
|
||||
"default": False,
|
||||
"accuracy": 5,
|
||||
"cost": 5,
|
||||
}
|
||||
if config("AZURE_OPENAI_EMBEDDINGS_DEPLOYMENT", default=""):
|
||||
KH_EMBEDDINGS["azure"] = {
|
||||
"def": {
|
||||
"__type__": "kotaemon.embeddings.AzureOpenAIEmbeddings",
|
||||
"azure_endpoint": config("AZURE_OPENAI_ENDPOINT", default=""),
|
||||
"openai_api_key": config("AZURE_OPENAI_API_KEY", default=""),
|
||||
"api_version": config("OPENAI_API_VERSION", default="")
|
||||
or "2024-02-15-preview",
|
||||
"deployment": config("AZURE_OPENAI_EMBEDDINGS_DEPLOYMENT", default=""),
|
||||
"request_timeout": 10,
|
||||
"chunk_size": 16,
|
||||
},
|
||||
"default": False,
|
||||
"accuracy": 5,
|
||||
"cost": 5,
|
||||
}
|
||||
|
||||
if config("OPENAI_API_KEY", default=""):
|
||||
KH_LLMS["openai"] = {
|
||||
"def": {
|
||||
"__type__": "kotaemon.llms.ChatOpenAI",
|
||||
"temperature": 0,
|
||||
"openai_api_base": config("OPENAI_API_BASE", default="")
|
||||
or "https://api.openai.com/v1",
|
||||
"openai_api_key": config("OPENAI_API_KEY", default=""),
|
||||
"model": config("OPENAI_CHAT_MODEL", default="") or "gpt-3.5-turbo",
|
||||
"request_timeout": 10,
|
||||
"stream": False,
|
||||
},
|
||||
"default": False,
|
||||
}
|
||||
if len(KH_EMBEDDINGS) < 1:
|
||||
KH_EMBEDDINGS["openai"] = {
|
||||
"def": {
|
||||
"__type__": "kotaemon.embeddings.OpenAIEmbeddings",
|
||||
"openai_api_base": config("OPENAI_API_BASE", default="")
|
||||
or "https://api.openai.com/v1",
|
||||
"openai_api_key": config("OPENAI_API_KEY", default=""),
|
||||
"model": config(
|
||||
"OPENAI_EMBEDDINGS_MODEL", default="text-embedding-ada-002"
|
||||
)
|
||||
or "text-embedding-ada-002",
|
||||
"request_timeout": 10,
|
||||
"chunk_size": 16,
|
||||
},
|
||||
"default": False,
|
||||
}
|
||||
|
||||
if config("LOCAL_MODEL", default=""):
|
||||
KH_LLMS["local"] = {
|
||||
"def": {
|
||||
"__type__": "kotaemon.llms.EndpointChatLLM",
|
||||
"endpoint_url": "http://localhost:31415/v1/chat/completions",
|
||||
},
|
||||
"default": False,
|
||||
},
|
||||
}
|
||||
KH_EMBEDDINGS = {
|
||||
# example for using Azure OpenAI, the config variables can set as environment
|
||||
# variables or in the .env file
|
||||
# "ada": {
|
||||
# "def": {
|
||||
# "__type__": "kotaemon.embeddings.AzureOpenAIEmbeddings",
|
||||
# "model": "text-embedding-ada-002",
|
||||
# "azure_endpoint": config("AZURE_OPENAI_ENDPOINT", default=""),
|
||||
# "openai_api_key": config("AZURE_OPENAI_API_KEY", default=""),
|
||||
# "deployment": "<your deployment name>",
|
||||
# "chunk_size": 16,
|
||||
# },
|
||||
# "accuracy": 5,
|
||||
# "cost": 5,
|
||||
# "default": True,
|
||||
# },
|
||||
"local": {
|
||||
"def": {
|
||||
"__type__": "kotaemon.embeddings.EndpointEmbeddings",
|
||||
"endpoint_url": "http://localhost:31415/v1/embeddings",
|
||||
},
|
||||
"default": False,
|
||||
},
|
||||
}
|
||||
"cost": 0,
|
||||
}
|
||||
if len(KH_EMBEDDINGS) < 1:
|
||||
KH_EMBEDDINGS["local"] = {
|
||||
"def": {
|
||||
"__type__": "kotaemon.embeddings.EndpointEmbeddings",
|
||||
"endpoint_url": "http://localhost:31415/v1/embeddings",
|
||||
},
|
||||
"default": False,
|
||||
"cost": 0,
|
||||
}
|
||||
|
||||
|
||||
KH_REASONINGS = ["ktem.reasoning.simple.FullQAPipeline"]
|
||||
|
||||
|
||||
|
|
|
@ -3,9 +3,7 @@ import subprocess
|
|||
from inspect import currentframe, getframeinfo
|
||||
from pathlib import Path
|
||||
|
||||
import dotenv
|
||||
|
||||
configs = dotenv.dotenv_values(".env")
|
||||
from decouple import config
|
||||
|
||||
system_name = platform.system()
|
||||
|
||||
|
@ -53,7 +51,7 @@ def serve_llamacpp_python(local_model_file: Path, **kwargs):
|
|||
|
||||
|
||||
def main():
|
||||
local_model_file = configs.get("LOCAL_MODEL", "")
|
||||
local_model_file = config("LOCAL_MODEL", default="")
|
||||
|
||||
if not local_model_file:
|
||||
print("LOCAL_MODEL not set in the `.env` file.")
|
||||
|
|
|
@ -87,7 +87,7 @@ activate_environment
|
|||
|
||||
# install dependencies
|
||||
# ver 0.2.56 produces segment error for /embeddings on MacOS
|
||||
python -m pip install llama-cpp-python[server]!=0.2.56
|
||||
python -m pip install llama-cpp-python[server]==0.2.55
|
||||
|
||||
# start the server with passed params
|
||||
python -m llama_cpp.server $@
|
||||
|
|
|
@ -88,7 +88,7 @@ activate_environment
|
|||
|
||||
# install dependencies
|
||||
# ver 0.2.56 produces segment error for /embeddings on MacOS
|
||||
python -m pip install llama-cpp-python[server]!=0.2.56
|
||||
python -m pip install llama-cpp-python[server]==0.2.55
|
||||
|
||||
# start the server with passed params
|
||||
python -m llama_cpp.server $@
|
||||
|
|
|
@ -28,7 +28,7 @@ call :activate_environment
|
|||
|
||||
@rem install dependencies
|
||||
@rem ver 0.2.56 produces segment error for /embeddings on MacOS
|
||||
call python -m pip install llama-cpp-python[server]!=0.2.56
|
||||
call python -m pip install llama-cpp-python[server]==0.2.55
|
||||
|
||||
@REM @rem start the server with passed params
|
||||
call python -m llama_cpp.server %*
|
||||
|
|
Loading…
Reference in New Issue
Block a user