mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-25 16:13:25 +00:00
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>
This commit is contained in:
parent
45741bcc1b
commit
1d3735a84c
@ -1,4 +1,6 @@
|
|||||||
"""Test openai embeddings."""
|
"""Test openai embeddings."""
|
||||||
|
import os
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import openai
|
import openai
|
||||||
import pytest
|
import pytest
|
||||||
@ -79,3 +81,26 @@ def test_embed_documents_normalized() -> None:
|
|||||||
def test_embed_query_normalized() -> None:
|
def test_embed_query_normalized() -> None:
|
||||||
output = OpenAIEmbeddings().embed_query("foo walked to the market")
|
output = OpenAIEmbeddings().embed_query("foo walked to the market")
|
||||||
assert np.isclose(np.linalg.norm(output), 1.0)
|
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…
Reference in New Issue
Block a user