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

docs: update Azure OpenAI to v1 and langchain API to 0.1 #18005

Merged
merged 1 commit into from
Mar 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
57 changes: 27 additions & 30 deletions docs/docs/integrations/llms/azure_openai.ipynb
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like there's an issue with file format, can't see a preview

Copy link
Contributor Author

@mspronesti mspronesti Mar 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@baskaryan It looks alright to me. I can re-run all the cells and commit again, if that helps :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

showing up for me now as well! maybe was a github issue

Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,19 @@
"You can configure the `openai` package to use Azure OpenAI using environment variables. The following is for `bash`:\n",
"\n",
"```bash\n",
"# Set this to `azure`\n",
"export OPENAI_API_TYPE=azure\n",
"# The API version you want to use: set this to `2023-05-15` for the released version.\n",
"export OPENAI_API_VERSION=2023-05-15\n",
"# The API version you want to use: set this to `2023-12-01-preview` for the released version.\n",
"export OPENAI_API_VERSION=2023-12-01-preview\n",
"# The base URL for your Azure OpenAI resource. You can find this in the Azure portal under your Azure OpenAI resource.\n",
"export OPENAI_API_BASE=https://your-resource-name.openai.azure.com\n",
"export AZURE_OPENAI_ENDPOINT=https://your-resource-name.openai.azure.com\n",
"# The API key for your Azure OpenAI resource. You can find this in the Azure portal under your Azure OpenAI resource.\n",
"export OPENAI_API_KEY=<your Azure OpenAI API key>\n",
"export AZURE_OPENAI_API_KEY=<your Azure OpenAI API key>\n",
"```\n",
"\n",
"Alternatively, you can configure the API right within your running Python environment:\n",
"\n",
"```python\n",
"import os\n",
"os.environ[\"OPENAI_API_TYPE\"] = \"azure\"\n",
"os.environ[\"OPENAI_API_VERSION\"] = \"2023-12-01-preview\"\n",
"```\n",
"\n",
"## Azure Active Directory Authentication\n",
Expand Down Expand Up @@ -76,15 +74,18 @@
"\n",
"_**Note**: These docs are for the Azure text completion models. Models like GPT-4 are chat models. They have a slightly different interface, and can be accessed via the `AzureChatOpenAI` class. For docs on Azure chat see [Azure Chat OpenAI documentation](/docs/integrations/chat/azure_chat_openai)._\n",
"\n",
"Let's say your deployment name is `text-davinci-002-prod`. In the `openai` Python API, you can specify this deployment with the `engine` parameter. For example:\n",
"Let's say your deployment name is `gpt-35-turbo-instruct-prod`. In the `openai` Python API, you can specify this deployment with the `engine` parameter. For example:\n",
"\n",
"```python\n",
"import openai\n",
"\n",
"response = openai.Completion.create(\n",
" engine=\"text-davinci-002-prod\",\n",
" prompt=\"This is a test\",\n",
" max_tokens=5\n",
"client = AzureOpenAI(\n",
" api_version=\"2023-12-01-preview\",\n",
")\n",
"\n",
"response = client.completions.create(\n",
" model=\"gpt-35-turbo-instruct-prod\",\n",
" prompt=\"Test prompt\"\n",
")\n",
"```\n"
]
Expand All @@ -103,22 +104,21 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 1,
"id": "faacfa54",
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"\n",
"os.environ[\"OPENAI_API_TYPE\"] = \"azure\"\n",
"os.environ[\"OPENAI_API_VERSION\"] = \"2023-05-15\"\n",
"os.environ[\"OPENAI_API_BASE\"] = \"...\"\n",
"os.environ[\"OPENAI_API_KEY\"] = \"...\""
"os.environ[\"OPENAI_API_VERSION\"] = \"2023-12-01-preview\"\n",
"os.environ[\"AZURE_OPENAI_ENDPOINT\"] = \"...\"\n",
"os.environ[\"AZURE_OPENAI_API_KEY\"] = \"...\""
]
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 2,
"id": "8fad2a6e",
"metadata": {},
"outputs": [],
Expand All @@ -129,39 +129,36 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 3,
"id": "8c80213a",
"metadata": {},
"outputs": [],
"source": [
"# Create an instance of Azure OpenAI\n",
"# Replace the deployment name with your own\n",
"llm = AzureOpenAI(\n",
" deployment_name=\"td2\",\n",
" model_name=\"gpt-3.5-turbo-instruct\",\n",
" deployment_name=\"gpt-35-turbo-instruct-0914\",\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 5,
"id": "592dc404",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"\"\\n\\nWhy couldn't the bicycle stand up by itself? Because it was...two tired!\""
]
"text/plain": "\" Why couldn't the bicycle stand up by itself?\\n\\nBecause it was two-tired!\""
},
"execution_count": 6,
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Run the LLM\n",
"llm(\"Tell me a joke\")"
"llm.invoke(\"Tell me a joke\")"
]
},
{
Expand All @@ -174,16 +171,16 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 6,
"id": "9c33fa19",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1mAzureOpenAI\u001b[0m\n",
"Params: {'deployment_name': 'text-davinci-002', 'model_name': 'text-davinci-002', 'temperature': 0.7, 'max_tokens': 256, 'top_p': 1, 'frequency_penalty': 0, 'presence_penalty': 0, 'n': 1, 'best_of': 1}\n"
"\u001B[1mAzureOpenAI\u001B[0m\n",
"Params: {'deployment_name': 'gpt-35-turbo-instruct-0914', 'model_name': 'gpt-3.5-turbo-instruct', 'temperature': 0.7, 'top_p': 1, 'frequency_penalty': 0, 'presence_penalty': 0, 'n': 1, 'logit_bias': {}, 'max_tokens': 256}\n"
]
}
],
Expand Down