2023-02-18 22:25:37 +00:00
|
|
|
{
|
|
|
|
"cells": [
|
|
|
|
{
|
|
|
|
"cell_type": "markdown",
|
2023-03-27 02:49:46 +00:00
|
|
|
"id": "c3852491",
|
2023-02-18 22:25:37 +00:00
|
|
|
"metadata": {},
|
|
|
|
"source": [
|
2023-06-16 18:52:56 +00:00
|
|
|
"# AzureOpenAI\n",
|
2023-03-27 02:49:46 +00:00
|
|
|
"\n",
|
|
|
|
"Let's load the OpenAI Embedding class with environment variables set to indicate to use Azure endpoints."
|
2023-02-18 22:25:37 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
2023-03-27 02:49:46 +00:00
|
|
|
"execution_count": null,
|
|
|
|
"id": "1b40f827",
|
2023-02-18 22:25:37 +00:00
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
2023-03-27 02:49:46 +00:00
|
|
|
"# set the environment variables needed for openai package to know to reach out to azure\n",
|
|
|
|
"import os\n",
|
|
|
|
"\n",
|
|
|
|
"os.environ[\"OPENAI_API_TYPE\"] = \"azure\"\n",
|
|
|
|
"os.environ[\"OPENAI_API_BASE\"] = \"https://<your-endpoint.openai.azure.com/\"\n",
|
2023-05-15 01:26:08 +00:00
|
|
|
"os.environ[\"OPENAI_API_KEY\"] = \"your AzureOpenAI key\"\n",
|
2023-07-18 16:50:15 +00:00
|
|
|
"os.environ[\"OPENAI_API_VERSION\"] = \"2023-05-15\""
|
2023-02-18 22:25:37 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
2023-03-27 02:49:46 +00:00
|
|
|
"execution_count": null,
|
|
|
|
"id": "bb36d16c",
|
2023-02-18 22:25:37 +00:00
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
2023-04-09 19:25:31 +00:00
|
|
|
"from langchain.embeddings import OpenAIEmbeddings\n",
|
|
|
|
"\n",
|
2023-05-18 04:05:53 +00:00
|
|
|
"embeddings = OpenAIEmbeddings(deployment=\"your-embeddings-deployment-name\")"
|
2023-02-18 22:25:37 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
2023-03-27 02:49:46 +00:00
|
|
|
"execution_count": null,
|
|
|
|
"id": "228abcbb",
|
2023-02-18 22:25:37 +00:00
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
2023-03-27 02:49:46 +00:00
|
|
|
"text = \"This is a test document.\""
|
2023-02-18 22:25:37 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
2023-03-27 02:49:46 +00:00
|
|
|
"execution_count": null,
|
|
|
|
"id": "60dd7fad",
|
2023-02-18 22:25:37 +00:00
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
2023-03-27 02:49:46 +00:00
|
|
|
"query_result = embeddings.embed_query(text)"
|
2023-02-18 22:25:37 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": null,
|
2023-03-27 02:49:46 +00:00
|
|
|
"id": "83bc1a72",
|
2023-02-18 22:25:37 +00:00
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
2023-03-27 02:49:46 +00:00
|
|
|
"doc_result = embeddings.embed_documents([text])"
|
2023-02-18 22:25:37 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": null,
|
2023-03-27 02:49:46 +00:00
|
|
|
"id": "aaad49f8",
|
2023-02-18 22:25:37 +00:00
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": []
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"metadata": {
|
|
|
|
"kernelspec": {
|
|
|
|
"display_name": "Python 3 (ipykernel)",
|
|
|
|
"language": "python",
|
|
|
|
"name": "python3"
|
|
|
|
},
|
|
|
|
"language_info": {
|
|
|
|
"codemirror_mode": {
|
|
|
|
"name": "ipython",
|
|
|
|
"version": 3
|
|
|
|
},
|
|
|
|
"file_extension": ".py",
|
|
|
|
"mimetype": "text/x-python",
|
|
|
|
"name": "python",
|
|
|
|
"nbconvert_exporter": "python",
|
|
|
|
"pygments_lexer": "ipython3",
|
2023-06-16 18:52:56 +00:00
|
|
|
"version": "3.9.1"
|
2023-03-27 02:49:46 +00:00
|
|
|
},
|
|
|
|
"vscode": {
|
|
|
|
"interpreter": {
|
|
|
|
"hash": "7377c2ccc78bc62c2683122d48c8cd1fb85a53850a1b1fc29736ed39852c9885"
|
|
|
|
}
|
2023-02-18 22:25:37 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
"nbformat": 4,
|
|
|
|
"nbformat_minor": 5
|
|
|
|
}
|