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

set baseURL for text2vec-openai schema config #148

Merged
merged 4 commits into from
May 18, 2024
Merged
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
22 changes: 18 additions & 4 deletions goldenverba/components/schema/schema_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ def verify_vectorizer(
skip_properties = []
modified_schema = schema.copy()

# adding specific config for Azure OpenAI
vectorizer_config = None
if os.getenv("OPENAI_API_TYPE") == "azure" and vectorizer == "text2vec-openai":
#adding specific config for Azure OpenAI
vectorizer_config = {}
if os.getenv("OPENAI_API_TYPE") == "azure" and vectorizer=="text2vec-openai":
resourceName = os.getenv("AZURE_OPENAI_RESOURCE_NAME")
model = os.getenv("AZURE_OPENAI_EMBEDDING_MODEL")
if resourceName is None or model is None:
Expand All @@ -47,6 +47,20 @@ def verify_vectorizer(
"text2vec-openai": {"deploymentId": model, "resourceName": resourceName}
}

base_url = os.getenv("OPENAI_BASE_URL", "")
if vectorizer == "text2vec-openai" and base_url:
# check if base_url ends with v1 and strip it since Weaviate automatically adds v1
if base_url.endswith("v1"):
base_url = base_url[:-2]
if vectorizer_config == {}:
vectorizer_config = {
"text2vec-openai": {
"baseURL": base_url,
}
}
else:
vectorizer_config["text2vec-openai"]["baseURL"] = base_url

# adding specific config for Google
if vectorizer == "text2vec-palm":
if google_project is not None:
Expand All @@ -59,7 +73,7 @@ def verify_vectorizer(
# Verify Vectorizer
if vectorizer in VECTORIZERS:
modified_schema["classes"][0]["vectorizer"] = vectorizer
if vectorizer_config is not None:
if vectorizer_config != {}:
modified_schema["classes"][0]["moduleConfig"] = vectorizer_config
for property in modified_schema["classes"][0]["properties"]:
if property["name"] in skip_properties:
Expand Down