Files
langchain/docs/modules/models/text_embedding/examples/azureopenai.ipynb
T
Ismael G SerranoandHarrison Chase 41e2394c9c Fix AzureOpenAI embeddings documentation example. model -> deployment (#4389)
# Documentation for Azure OpenAI embeddings model

- OPENAI_API_VERSION environment variable is needed for the endpoint
- The constructor does not work with model, it works with deployment.

I fixed it in the notebook.

(This is my first contribution)

## Who can review?

@hwchase17 
@agola

Co-authored-by: Harrison Chase <hw.chase.17@gmail.com>
2023-05-17 21:05:53 -07:00

2.3 KiB

AzureOpenAI

Let's load the OpenAI Embedding class with environment variables set to indicate to use Azure endpoints.

In [ ]:
# set the environment variables needed for openai package to know to reach out to azure
import os

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"
In [ ]:
from langchain.embeddings import OpenAIEmbeddings

embeddings = OpenAIEmbeddings(deployment="your-embeddings-deployment-name")
In [ ]:
text = "This is a test document."
In [ ]:
query_result = embeddings.embed_query(text)
In [ ]:
doc_result = embeddings.embed_documents([text])
In [ ]: