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

Define a model cascade, use another model if it fails because of length #22

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 8 additions & 1 deletion easycompletion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
text_completion,
text_completion_async,
chat_completion,
chat_completion_async
chat_completion_async,
build_model_info,
)

openai_function_call = function_completion
Expand All @@ -21,13 +22,17 @@

from .constants import (
TEXT_MODEL,
LONG_TEXT_MODEL,
DEFAULT_CHUNK_LENGTH,
)

__all__ = [
"function_completion",
"text_completion",
"chat_completion",
"function_completion_async",
"text_completion_async",
"chat_completion_async",
"openai_function_call",
"openai_text_call",
"compose_prompt",
Expand All @@ -36,6 +41,8 @@
"chunk_prompt",
"count_tokens",
"get_tokens",
"build_model_info",
"TEXT_MODEL",
"LONG_TEXT_MODEL",
"DEFAULT_CHUNK_LENGTH",
]
25 changes: 14 additions & 11 deletions easycompletion/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@

load_dotenv() # take environment variables from .env.

TEXT_MODEL = os.getenv("EASYCOMPLETION_TEXT_MODEL")
if TEXT_MODEL == None or TEXT_MODEL == "":
TEXT_MODEL = "gpt-3.5-turbo-0613"
LONG_TEXT_MODEL = os.getenv("EASYCOMPLETION_LONG_TEXT_MODEL")
if LONG_TEXT_MODEL == None or LONG_TEXT_MODEL == "":
LONG_TEXT_MODEL = "gpt-3.5-turbo-16k"
TEXT_MODEL = os.getenv("EASYCOMPLETION_TEXT_MODEL") or "gpt-3.5-turbo-0613"
TEXT_MODEL_WINDOW = os.getenv("EASYCOMPLETION_TEXT_MODEL_WINDOW") or 4096
LONG_TEXT_MODEL = os.getenv("EASYCOMPLETION_LONG_TEXT_MODEL") or "gpt-3.5-turbo-16k"
LONG_TEXT_MODEL_WINDOW = os.getenv("EASYCOMPLETION_LONG_TEXT_MODEL_WINDOW") or 16*1024

EASYCOMPLETION_API_KEY = os.getenv("OPENAI_API_KEY")
if EASYCOMPLETION_API_KEY is None:
EASYCOMPLETION_API_KEY = os.getenv("EASYCOMPLETION_API_KEY")
EASYCOMPLETION_API_KEY = os.getenv("OPENAI_API_KEY") or os.getenv("EASYCOMPLETION_API_KEY")

EASYCOMPLETION_API_ENDPOINT = os.getenv("EASYCOMPLETION_API_ENDPOINT") or "https://api.openai.com/v1"

DEBUG = os.environ.get("EASYCOMPLETION_DEBUG") == "true" or os.environ.get("EASYCOMPLETION_DEBUG") == "True"
DEBUG = (os.environ.get("EASYCOMPLETION_DEBUG") or '').lower() == "true"
SUPPRESS_WARNINGS = (os.environ.get("SUPPRESS_WARNINGS") or '').lower() == "true"

DEFAULT_CHUNK_LENGTH = 4096 * 3 / 4 # 3/4ths of the context window size
DEFAULT_CHUNK_LENGTH = os.getenv("DEFAULT_CHUNK_LENGTH") or (TEXT_MODEL_WINDOW * 3 // 4) # 3/4ths of the context window size

DEFAULT_MODEL_INFO = [
(TEXT_MODEL, DEFAULT_CHUNK_LENGTH),
(LONG_TEXT_MODEL, LONG_TEXT_MODEL_WINDOW - DEFAULT_CHUNK_LENGTH)
# In the second case, DEFAULT_CHUNK_LENGTH is used as buffer
]
Loading