Ensure deployment_id is set to provided deployment, required for Azure OpenAI. (#5002)

# Ensure deployment_id is set to provided deployment, required for Azure
OpenAI.
---------

Co-authored-by: Lucas Pickup <lupickup@microsoft.com>
Co-authored-by: Bagatur <baskaryan@gmail.com>
pull/9020/head^2
Lucas Pickup 1 year ago committed by GitHub
parent 45741bcc1b
commit 1d3735a84c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,4 +1,6 @@
"""Test openai embeddings."""
import os
import numpy as np
import openai
import pytest
@ -79,3 +81,26 @@ def test_embed_documents_normalized() -> None:
def test_embed_query_normalized() -> None:
output = OpenAIEmbeddings().embed_query("foo walked to the market")
assert np.isclose(np.linalg.norm(output), 1.0)
def test_azure_openai_embeddings() -> None:
from openai import error
os.environ["OPENAI_API_TYPE"] = "azure"
os.environ["OPENAI_API_BASE"] = "https://your-endpoint.openai.azure.com/"
os.environ["OPENAI_API_KEY"] = "your AzureOpenAI key"
os.environ["OPENAI_API_VERSION"] = "2023-03-15-preview"
embeddings = OpenAIEmbeddings(deployment="your-embeddings-deployment-name")
text = "This is a test document."
try:
embeddings.embed_query(text)
except error.InvalidRequestError as e:
if "Must provide an 'engine' or 'deployment_id' parameter" in str(e):
assert (
False
), "deployment was provided to but openai.Embeddings didn't get it."
except Exception:
# Expected to fail because endpoint doesn't exist.
pass

Loading…
Cancel
Save