Don't create collection if it already exists + fix OpenAI API Key name (#66)

* Don't create collection if it already exists

* Fix openai api key name
This commit is contained in:
Chris Weaver 2023-05-17 17:12:00 -07:00 committed by GitHub
parent 8685beceb2
commit 0b46ea76e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 17 additions and 8 deletions

View File

@ -21,5 +21,5 @@ BATCH_SIZE_ENCODE_CHUNKS = 8
# QA Model API Configs
# https://platform.openai.com/docs/models/model-endpoint-compatibility
INTERNAL_MODEL_VERSION = os.environ.get("INTERNAL_MODEL", "openai-chat-completion")
OPENAPI_MODEL_VERSION = os.environ.get("OPENAI_MODEL_VERSION", "gpt-4")
OPENAI_MODEL_VERSION = os.environ.get("OPENAI_MODEL_VERSION", "gpt-4")
OPENAI_MAX_OUTPUT_TOKENS = 512

View File

@ -18,6 +18,7 @@ from qdrant_client import QdrantClient
from qdrant_client.http.exceptions import ResponseHandlingException
from qdrant_client.http.models.models import UpdateResult
from qdrant_client.http.models.models import UpdateStatus
from qdrant_client.models import CollectionsResponse
from qdrant_client.models import Distance
from qdrant_client.models import PointStruct
from qdrant_client.models import VectorParams
@ -27,6 +28,10 @@ logger = setup_logger()
DEFAULT_BATCH_SIZE = 30
def list_collections() -> CollectionsResponse:
return get_qdrant_client().get_collections()
def create_collection(
collection_name: str, embedding_dim: int = DOC_EMBEDDING_DIM
) -> None:

View File

@ -21,7 +21,7 @@ from danswer.configs.constants import SEMANTIC_IDENTIFIER
from danswer.configs.constants import SOURCE_LINK
from danswer.configs.constants import SOURCE_TYPE
from danswer.configs.model_configs import OPENAI_MAX_OUTPUT_TOKENS
from danswer.configs.model_configs import OPENAPI_MODEL_VERSION
from danswer.configs.model_configs import OPENAI_MODEL_VERSION
from danswer.direct_qa.interfaces import QAModel
from danswer.direct_qa.qa_prompts import ANSWER_PAT
from danswer.direct_qa.qa_prompts import get_chat_reflexion_msg
@ -185,7 +185,7 @@ class OpenAICompletionQA(QAModel):
def __init__(
self,
prompt_processor: Callable[[str, list[str]], str] = json_processor,
model_version: str = OPENAPI_MODEL_VERSION,
model_version: str = OPENAI_MODEL_VERSION,
max_output_tokens: int = OPENAI_MAX_OUTPUT_TOKENS,
) -> None:
self.prompt_processor = prompt_processor
@ -282,7 +282,7 @@ class OpenAIChatCompletionQA(QAModel):
prompt_processor: Callable[
[str, list[str]], list[dict[str, str]]
] = json_chat_processor,
model_version: str = OPENAPI_MODEL_VERSION,
model_version: str = OPENAI_MODEL_VERSION,
max_output_tokens: int = OPENAI_MAX_OUTPUT_TOKENS,
reflexion_try_count: int = 0,
) -> None:

View File

@ -10,6 +10,7 @@ from danswer.configs.app_configs import APP_PORT
from danswer.configs.app_configs import ENABLE_OAUTH
from danswer.configs.app_configs import SECRET
from danswer.configs.app_configs import WEB_DOMAIN
from danswer.datastores.qdrant.indexing import list_collections
from danswer.server.admin import router as admin_router
from danswer.server.event_loading import router as event_processing_router
from danswer.server.search_backend import router as backend_router
@ -100,8 +101,11 @@ def get_application() -> FastAPI:
from danswer.datastores.qdrant.indexing import create_collection
from danswer.configs.app_configs import QDRANT_DEFAULT_COLLECTION
create_collection(collection_name=QDRANT_DEFAULT_COLLECTION)
logger.info("Collection ready")
if QDRANT_DEFAULT_COLLECTION not in {
collection.name for collection in list_collections().collections
}:
logger.info(f"Creating collection with name: {QDRANT_DEFAULT_COLLECTION}")
create_collection(collection_name=QDRANT_DEFAULT_COLLECTION)
warm_up_models()
logger.info("Semantic Search models are ready.")

View File

@ -9,7 +9,7 @@ OPENAI_API_KEY=
INTERNAL_MODEL_VERSION=openai-chat-completion
# Use a valid model for the choice above, consult https://platform.openai.com/docs/models/model-endpoint-compatibility
OPENAPI_MODEL_VERSION=gpt-3.5-turbo
OPENAI_MODEL_VERSION=gpt-3.5-turbo
# Can leave these as defaults

View File

@ -8,7 +8,7 @@ OPENAI_API_KEY=
# Choose between "openai-chat-completion" and "openai-completion"
INTERNAL_MODEL_VERSION=openai-chat-completion
# Use a valid model for the choice above, consult https://platform.openai.com/docs/models/model-endpoint-compatibility
OPENAPI_MODEL_VERSION=gpt-4
OPENAI_MODEL_VERSION=gpt-4
# Could be something like danswer.companyname.com. Requires additional setup if not localhost
WEB_DOMAIN=http://localhost:3000