From 084bedd16e409f0e4d4347c875951b292ca22f4f Mon Sep 17 00:00:00 2001 From: Erick Friis Date: Wed, 17 Apr 2024 17:20:44 -0700 Subject: [PATCH] docs: nits (#20577) --- .../integrations/chat/azure_chat_openai.ipynb | 108 ++++++++++++------ docs/docs/integrations/platforms/index.mdx | 1 + 2 files changed, 73 insertions(+), 36 deletions(-) diff --git a/docs/docs/integrations/chat/azure_chat_openai.ipynb b/docs/docs/integrations/chat/azure_chat_openai.ipynb index 57e677340c..1b7cb31ee3 100644 --- a/docs/docs/integrations/chat/azure_chat_openai.ipynb +++ b/docs/docs/integrations/chat/azure_chat_openai.ipynb @@ -19,59 +19,85 @@ "\n", ">[Azure OpenAI Service](https://learn.microsoft.com/en-us/azure/ai-services/openai/overview) provides REST API access to OpenAI's powerful language models including the GPT-4, GPT-3.5-Turbo, and Embeddings model series. These models can be easily adapted to your specific task including but not limited to content generation, summarization, semantic search, and natural language to code translation. Users can access the service through REST APIs, Python SDK, or a web-based interface in the Azure OpenAI Studio.\n", "\n", - "This notebook goes over how to connect to an Azure-hosted OpenAI endpoint. We recommend having version `openai>=1` installed." + "This notebook goes over how to connect to an Azure-hosted OpenAI endpoint. First, we need to install the `langchain-openai` package." + ] + }, + { + "cell_type": "raw", + "id": "d83ba7de", + "metadata": { + "vscode": { + "languageId": "raw" + } + }, + "source": [ + "%pip install -qU langchain-openai" + ] + }, + { + "cell_type": "markdown", + "id": "e39133c8", + "metadata": { + "vscode": { + "languageId": "raw" + } + }, + "source": [ + "Next, let's set some environment variables to help us connect to the Azure OpenAI service. You can find these values in the Azure portal." ] }, { "cell_type": "code", - "execution_count": 3, - "id": "96164b42", + "execution_count": null, + "id": "1d8d73bd", "metadata": {}, "outputs": [], "source": [ "import os\n", "\n", - "from langchain_core.messages import HumanMessage\n", - "from langchain_openai import AzureChatOpenAI" + "os.environ[\"AZURE_OPENAI_API_KEY\"] = \"...\"\n", + "os.environ[\"AZURE_OPENAI_ENDPOINT\"] = \"https://.openai.azure.com/\"\n", + "os.environ[\"AZURE_OPENAI_API_VERSION\"] = \"2023-06-01-preview\"\n", + "os.environ[\"AZURE_OPENAI_CHAT_DEPLOYMENT_NAME\"] = \"chat\"" + ] + }, + { + "cell_type": "markdown", + "id": "e7b160f8", + "metadata": {}, + "source": [ + "Next, let's construct our model and chat with it:" ] }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 3, "id": "cbe4bb58-ba13-4355-8af9-cd990dc47a64", "metadata": {}, "outputs": [], "source": [ - "os.environ[\"AZURE_OPENAI_API_KEY\"] = \"...\"\n", - "os.environ[\"AZURE_OPENAI_ENDPOINT\"] = \"https://.openai.azure.com/\"" - ] - }, - { - "cell_type": "code", - "execution_count": 14, - "id": "8161278f", - "metadata": {}, - "outputs": [], - "source": [ + "from langchain_core.messages import HumanMessage\n", + "from langchain_openai import AzureChatOpenAI\n", + "\n", "model = AzureChatOpenAI(\n", - " openai_api_version=\"2023-05-15\",\n", - " azure_deployment=\"your-deployment-name\",\n", + " openai_api_version=os.environ[\"AZURE_OPENAI_API_VERSION\"],\n", + " azure_deployment=os.environ[\"AZURE_OPENAI_CHAT_DEPLOYMENT_NAME\"],\n", ")" ] }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 4, "id": "99509140", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "AIMessage(content=\"J'adore la programmation.\")" + "AIMessage(content=\"J'adore programmer.\", response_metadata={'token_usage': {'completion_tokens': 6, 'prompt_tokens': 19, 'total_tokens': 25}, 'model_name': 'gpt-35-turbo', 'system_fingerprint': None, 'prompt_filter_results': [{'prompt_index': 0, 'content_filter_results': {'hate': {'filtered': False, 'severity': 'safe'}, 'self_harm': {'filtered': False, 'severity': 'safe'}, 'sexual': {'filtered': False, 'severity': 'safe'}, 'violence': {'filtered': False, 'severity': 'safe'}}}], 'finish_reason': 'stop', 'logprobs': None, 'content_filter_results': {'hate': {'filtered': False, 'severity': 'safe'}, 'self_harm': {'filtered': False, 'severity': 'safe'}, 'sexual': {'filtered': False, 'severity': 'safe'}, 'violence': {'filtered': False, 'severity': 'safe'}}}, id='run-25ed88db-38f2-4b0c-a943-a03f217711a9-0')" ] }, - "execution_count": 15, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -80,7 +106,7 @@ "message = HumanMessage(\n", " content=\"Translate this sentence from English to French. I love programming.\"\n", ")\n", - "model([message])" + "model.invoke([message])" ] }, { @@ -96,7 +122,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 5, "id": "0531798a", "metadata": {}, "outputs": [], @@ -106,19 +132,29 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "id": "aceddb72", "metadata": { "scrolled": true }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Total Cost (USD): $0.000041\n" + ] + } + ], "source": [ "model = AzureChatOpenAI(\n", - " openai_api_version=\"2023-05-15\",\n", - " azure_deployment=\"gpt-35-turbo\", # in Azure, this deployment has version 0613 - input and output tokens are counted separately\n", + " openai_api_version=os.environ[\"AZURE_OPENAI_API_VERSION\"],\n", + " azure_deployment=os.environ[\n", + " \"AZURE_OPENAI_CHAT_DEPLOYMENT_NAME\"\n", + " ], # in Azure, this deployment has version 0613 - input and output tokens are counted separately\n", ")\n", "with get_openai_callback() as cb:\n", - " model([message])\n", + " model.invoke([message])\n", " print(\n", " f\"Total Cost (USD): ${format(cb.total_cost, '.6f')}\"\n", " ) # without specifying the model version, flat-rate 0.002 USD per 1k input and output tokens is used" @@ -134,7 +170,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 11, "id": "8d5e54e9", "metadata": {}, "outputs": [ @@ -147,13 +183,13 @@ } ], "source": [ - "model0613 = AzureChatOpenAI(\n", - " openai_api_version=\"2023-05-15\",\n", - " deployment_name=\"gpt-35-turbo\",\n", - " model_version=\"0613\",\n", + "model0301 = AzureChatOpenAI(\n", + " openai_api_version=os.environ[\"AZURE_OPENAI_API_VERSION\"],\n", + " azure_deployment=os.environ[\"AZURE_OPENAI_CHAT_DEPLOYMENT_NAME\"],\n", + " model_version=\"0301\",\n", ")\n", "with get_openai_callback() as cb:\n", - " model0613([message])\n", + " model0301.invoke([message])\n", " print(f\"Total Cost (USD): ${format(cb.total_cost, '.6f')}\")" ] } @@ -174,7 +210,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.12" + "version": "3.11.4" } }, "nbformat": 4, diff --git a/docs/docs/integrations/platforms/index.mdx b/docs/docs/integrations/platforms/index.mdx index d80e47f049..3136a07f83 100644 --- a/docs/docs/integrations/platforms/index.mdx +++ b/docs/docs/integrations/platforms/index.mdx @@ -13,6 +13,7 @@ These providers have standalone `langchain-{provider}` packages for improved ver - [AI21](/docs/integrations/providers/ai21) - [Airbyte](/docs/integrations/providers/airbyte) +- [Amazon Web Services](/docs/integrations/platforms/aws) - [Anthropic](/docs/integrations/platforms/anthropic) - [Astra DB](/docs/integrations/providers/astradb) - [Cohere](/docs/integrations/providers/cohere)