diff --git a/docs/docs_skeleton/docs/use_cases/apis/api.mdx b/docs/docs_skeleton/docs/use_cases/apis/api.mdx deleted file mode 100644 index 7760ab04af..0000000000 --- a/docs/docs_skeleton/docs/use_cases/apis/api.mdx +++ /dev/null @@ -1,9 +0,0 @@ ---- -sidebar_position: 0 ---- -# API chains -APIChain enables using LLMs to interact with APIs to retrieve relevant information. Construct the chain by providing a question relevant to the provided API documentation. - -import Example from "@snippets/modules/chains/popular/api.mdx" - - diff --git a/docs/docs_skeleton/static/img/api_chain.png b/docs/docs_skeleton/static/img/api_chain.png new file mode 100644 index 0000000000..f296056498 Binary files /dev/null and b/docs/docs_skeleton/static/img/api_chain.png differ diff --git a/docs/docs_skeleton/static/img/api_chain_response.png b/docs/docs_skeleton/static/img/api_chain_response.png new file mode 100644 index 0000000000..9b3103a9e3 Binary files /dev/null and b/docs/docs_skeleton/static/img/api_chain_response.png differ diff --git a/docs/docs_skeleton/static/img/api_function_call.png b/docs/docs_skeleton/static/img/api_function_call.png new file mode 100644 index 0000000000..82f151afe1 Binary files /dev/null and b/docs/docs_skeleton/static/img/api_function_call.png differ diff --git a/docs/docs_skeleton/static/img/api_use_case.png b/docs/docs_skeleton/static/img/api_use_case.png new file mode 100644 index 0000000000..f2fa0cdb7a Binary files /dev/null and b/docs/docs_skeleton/static/img/api_use_case.png differ diff --git a/docs/extras/use_cases/apis.ipynb b/docs/extras/use_cases/apis.ipynb new file mode 100644 index 0000000000..598d100e06 --- /dev/null +++ b/docs/extras/use_cases/apis.ipynb @@ -0,0 +1,423 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "a15e6a18", + "metadata": {}, + "source": [ + "# Interacting with APIs\n", + "\n", + "[![Open In Collab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/langchain-ai/langchain/blob/master/docs/extras/use_cases/apis.ipynb)\n", + "\n", + "## Use case \n", + "\n", + "Suppose you want an LLM to interact with external APIs.\n", + "\n", + "This can be very useful for retrieving context for the LLM to utilize.\n", + "\n", + "And, more generally, it allows us to interact with APIs using natural langugage! \n", + " \n", + "\n", + "## Overview\n", + "\n", + "There are two primary ways to interface LLMs with external APIs:\n", + " \n", + "* `Functions`: For example, [OpenAI functions](https://platform.openai.com/docs/guides/gpt/function-calling) is one popular means of doing this.\n", + "* `LLM-generated interface`: Use an LLM with access to API documentation to create an interface.\n", + "\n", + "![Image description](/img/api_use_case.png)" + ] + }, + { + "cell_type": "markdown", + "id": "abbd82f0", + "metadata": {}, + "source": [ + "## Quickstart \n", + "\n", + "Many APIs already are compatible with OpenAI function calling.\n", + "\n", + "For example, [Klarna](https://www.klarna.com/international/press/klarna-brings-smoooth-shopping-to-chatgpt/) has a YAML file that describes its API and allows OpenAI to interact with it:\n", + "\n", + "```\n", + "https://www.klarna.com/us/shopping/public/openai/v0/api-docs/\n", + "```\n", + "\n", + "Other options include:\n", + "\n", + "* [Speak](https://api.speak.com/openapi.yaml) for translation\n", + "* [XKCD](https://gist.githubusercontent.com/roaldnefs/053e505b2b7a807290908fe9aa3e1f00/raw/0a212622ebfef501163f91e23803552411ed00e4/openapi.yaml) for comics\n", + "\n", + "We can supply the specification to `get_openapi_chain` directly in order to query the API with OpenAI functions:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5a218fcc", + "metadata": {}, + "outputs": [], + "source": [ + "pip install langchain openai \n", + "\n", + "# Set env var OPENAI_API_KEY or load from a .env file:\n", + "# import dotenv\n", + "# dotenv.load_env()" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "30b780e3", + "metadata": { + "scrolled": false + }, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "Attempting to load an OpenAPI 3.0.1 spec. This may result in degraded performance. Convert your OpenAPI spec to 3.1.* spec for better support.\n" + ] + }, + { + "data": { + "text/plain": [ + "{'query': \"What are some options for a men's large blue button down shirt\",\n", + " 'response': {'products': [{'name': 'Cubavera Four Pocket Guayabera Shirt',\n", + " 'url': 'https://www.klarna.com/us/shopping/pl/cl10001/3202055522/Clothing/Cubavera-Four-Pocket-Guayabera-Shirt/?utm_source=openai&ref-site=openai_plugin',\n", + " 'price': '$13.50',\n", + " 'attributes': ['Material:Polyester,Cotton',\n", + " 'Target Group:Man',\n", + " 'Color:Red,White,Blue,Black',\n", + " 'Properties:Pockets',\n", + " 'Pattern:Solid Color',\n", + " 'Size (Small-Large):S,XL,L,M,XXL']},\n", + " {'name': 'Polo Ralph Lauren Plaid Short Sleeve Button-down Oxford Shirt',\n", + " 'url': 'https://www.klarna.com/us/shopping/pl/cl10001/3207163438/Clothing/Polo-Ralph-Lauren-Plaid-Short-Sleeve-Button-down-Oxford-Shirt/?utm_source=openai&ref-site=openai_plugin',\n", + " 'price': '$52.20',\n", + " 'attributes': ['Material:Cotton',\n", + " 'Target Group:Man',\n", + " 'Color:Red,Blue,Multicolor',\n", + " 'Size (Small-Large):S,XL,L,M,XXL']},\n", + " {'name': 'Brixton Bowery Flannel Shirt',\n", + " 'url': 'https://www.klarna.com/us/shopping/pl/cl10001/3202331096/Clothing/Brixton-Bowery-Flannel-Shirt/?utm_source=openai&ref-site=openai_plugin',\n", + " 'price': '$27.48',\n", + " 'attributes': ['Material:Cotton',\n", + " 'Target Group:Man',\n", + " 'Color:Gray,Blue,Black,Orange',\n", + " 'Properties:Pockets',\n", + " 'Pattern:Checkered',\n", + " 'Size (Small-Large):XL,3XL,4XL,5XL,L,M,XXL']},\n", + " {'name': 'Vineyard Vines Gingham On-The-Go brrr Classic Fit Shirt Crystal',\n", + " 'url': 'https://www.klarna.com/us/shopping/pl/cl10001/3201938510/Clothing/Vineyard-Vines-Gingham-On-The-Go-brrr-Classic-Fit-Shirt-Crystal/?utm_source=openai&ref-site=openai_plugin',\n", + " 'price': '$80.64',\n", + " 'attributes': ['Material:Cotton',\n", + " 'Target Group:Man',\n", + " 'Color:Blue',\n", + " 'Size (Small-Large):XL,XS,L,M']},\n", + " {'name': \"Carhartt Men's Loose Fit Midweight Short Sleeve Plaid Shirt\",\n", + " 'url': 'https://www.klarna.com/us/shopping/pl/cl10001/3201826024/Clothing/Carhartt-Men-s-Loose-Fit-Midweight-Short-Sleeve-Plaid-Shirt/?utm_source=openai&ref-site=openai_plugin',\n", + " 'price': '$17.99',\n", + " 'attributes': ['Material:Cotton',\n", + " 'Target Group:Man',\n", + " 'Color:Red,Brown,Blue,Green',\n", + " 'Properties:Pockets',\n", + " 'Pattern:Checkered',\n", + " 'Size (Small-Large):S,XL,L,M']}]}}" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from langchain.chains.openai_functions.openapi import get_openapi_chain\n", + "chain = get_openapi_chain(\"https://www.klarna.com/us/shopping/public/openai/v0/api-docs/\")\n", + "chain(\"What are some options for a men's large blue button down shirt\")" + ] + }, + { + "cell_type": "markdown", + "id": "9162c91c", + "metadata": {}, + "source": [ + "## Functions \n", + "\n", + "We can unpack what is hapening when we use the funtions to calls external APIs.\n", + "\n", + "Let's look at the [LangSmith trace](https://smith.langchain.com/public/76a58b85-193f-4eb7-ba40-747f0d5dd56e/r):\n", + "\n", + "* See [here](https://github.com/langchain-ai/langchain/blob/7fc07ba5df99b9fa8bef837b0fafa220bc5c932c/libs/langchain/langchain/chains/openai_functions/openapi.py#L279C9-L279C19) that we call the OpenAI LLM with the provided API spec:\n", + "\n", + "```\n", + "https://www.klarna.com/us/shopping/public/openai/v0/api-docs/\n", + "```\n", + "\n", + "* The prompt then tells the LLM to use the API spec wiith input question:\n", + "\n", + "```\n", + "Use the provided API's to respond to this user query:\n", + "What are some options for a men's large blue button down shirt\n", + "```\n", + "\n", + "* The LLM returns the parameters for the function call `productsUsingGET`, which is [specified in the provided API spec](https://www.klarna.com/us/shopping/public/openai/v0/api-docs/):\n", + "```\n", + "function_call:\n", + " name: productsUsingGET\n", + " arguments: |-\n", + " {\n", + " \"params\": {\n", + " \"countryCode\": \"US\",\n", + " \"q\": \"men's large blue button down shirt\",\n", + " \"size\": 5,\n", + " \"min_price\": 0,\n", + " \"max_price\": 100\n", + " }\n", + " }\n", + " ```\n", + " \n", + "![Image description](/img/api_function_call.png)\n", + " \n", + "* This `Dict` above split and the [API is called here](https://github.com/langchain-ai/langchain/blob/7fc07ba5df99b9fa8bef837b0fafa220bc5c932c/libs/langchain/langchain/chains/openai_functions/openapi.py#L215)." + ] + }, + { + "cell_type": "markdown", + "id": "1fe49a0d", + "metadata": {}, + "source": [ + "## API Chain \n", + "\n", + "We can also build our own interface to external APIs using the `APIChain` and provided API documentation." + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "4ef0c3d0", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n", + "\u001b[1m> Entering new APIChain chain...\u001b[0m\n", + "\u001b[32;1m\u001b[1;3mhttps://api.open-meteo.com/v1/forecast?latitude=48.1351&longitude=11.5820&hourly=temperature_2m&temperature_unit=fahrenheit¤t_weather=true\u001b[0m\n", + "\u001b[33;1m\u001b[1;3m{\"latitude\":48.14,\"longitude\":11.58,\"generationtime_ms\":1.0769367218017578,\"utc_offset_seconds\":0,\"timezone\":\"GMT\",\"timezone_abbreviation\":\"GMT\",\"elevation\":521.0,\"current_weather\":{\"temperature\":52.9,\"windspeed\":12.6,\"winddirection\":239.0,\"weathercode\":3,\"is_day\":0,\"time\":\"2023-08-07T22:00\"},\"hourly_units\":{\"time\":\"iso8601\",\"temperature_2m\":\"°F\"},\"hourly\":{\"time\":[\"2023-08-07T00:00\",\"2023-08-07T01:00\",\"2023-08-07T02:00\",\"2023-08-07T03:00\",\"2023-08-07T04:00\",\"2023-08-07T05:00\",\"2023-08-07T06:00\",\"2023-08-07T07:00\",\"2023-08-07T08:00\",\"2023-08-07T09:00\",\"2023-08-07T10:00\",\"2023-08-07T11:00\",\"2023-08-07T12:00\",\"2023-08-07T13:00\",\"2023-08-07T14:00\",\"2023-08-07T15:00\",\"2023-08-07T16:00\",\"2023-08-07T17:00\",\"2023-08-07T18:00\",\"2023-08-07T19:00\",\"2023-08-07T20:00\",\"2023-08-07T21:00\",\"2023-08-07T22:00\",\"2023-08-07T23:00\",\"2023-08-08T00:00\",\"2023-08-08T01:00\",\"2023-08-08T02:00\",\"2023-08-08T03:00\",\"2023-08-08T04:00\",\"2023-08-08T05:00\",\"2023-08-08T06:00\",\"2023-08-08T07:00\",\"2023-08-08T08:00\",\"2023-08-08T09:00\",\"2023-08-08T10:00\",\"2023-08-08T11:00\",\"2023-08-08T12:00\",\"2023-08-08T13:00\",\"2023-08-08T14:00\",\"2023-08-08T15:00\",\"2023-08-08T16:00\",\"2023-08-08T17:00\",\"2023-08-08T18:00\",\"2023-08-08T19:00\",\"2023-08-08T20:00\",\"2023-08-08T21:00\",\"2023-08-08T22:00\",\"2023-08-08T23:00\",\"2023-08-09T00:00\",\"2023-08-09T01:00\",\"2023-08-09T02:00\",\"2023-08-09T03:00\",\"2023-08-09T04:00\",\"2023-08-09T05:00\",\"2023-08-09T06:00\",\"2023-08-09T07:00\",\"2023-08-09T08:00\",\"2023-08-09T09:00\",\"2023-08-09T10:00\",\"2023-08-09T11:00\",\"2023-08-09T12:00\",\"2023-08-09T13:00\",\"2023-08-09T14:00\",\"2023-08-09T15:00\",\"2023-08-09T16:00\",\"2023-08-09T17:00\",\"2023-08-09T18:00\",\"2023-08-09T19:00\",\"2023-08-09T20:00\",\"2023-08-09T21:00\",\"2023-08-09T22:00\",\"2023-08-09T23:00\",\"2023-08-10T00:00\",\"2023-08-10T01:00\",\"2023-08-10T02:00\",\"2023-08-10T03:00\",\"2023-08-10T04:00\",\"2023-08-10T05:00\",\"2023-08-10T06:00\",\"2023-08-10T07:00\",\"2023-08-10T08:00\",\"2023-08-10T09:00\",\"2023-08-10T10:00\",\"2023-08-10T11:00\",\"2023-08-10T12:00\",\"2023-08-10T13:00\",\"2023-08-10T14:00\",\"2023-08-10T15:00\",\"2023-08-10T16:00\",\"2023-08-10T17:00\",\"2023-08-10T18:00\",\"2023-08-10T19:00\",\"2023-08-10T20:00\",\"2023-08-10T21:00\",\"2023-08-10T22:00\",\"2023-08-10T23:00\",\"2023-08-11T00:00\",\"2023-08-11T01:00\",\"2023-08-11T02:00\",\"2023-08-11T03:00\",\"2023-08-11T04:00\",\"2023-08-11T05:00\",\"2023-08-11T06:00\",\"2023-08-11T07:00\",\"2023-08-11T08:00\",\"2023-08-11T09:00\",\"2023-08-11T10:00\",\"2023-08-11T11:00\",\"2023-08-11T12:00\",\"2023-08-11T13:00\",\"2023-08-11T14:00\",\"2023-08-11T15:00\",\"2023-08-11T16:00\",\"2023-08-11T17:00\",\"2023-08-11T18:00\",\"2023-08-11T19:00\",\"2023-08-11T20:00\",\"2023-08-11T21:00\",\"2023-08-11T22:00\",\"2023-08-11T23:00\",\"2023-08-12T00:00\",\"2023-08-12T01:00\",\"2023-08-12T02:00\",\"2023-08-12T03:00\",\"2023-08-12T04:00\",\"2023-08-12T05:00\",\"2023-08-12T06:00\",\"2023-08-12T07:00\",\"2023-08-12T08:00\",\"2023-08-12T09:00\",\"2023-08-12T10:00\",\"2023-08-12T11:00\",\"2023-08-12T12:00\",\"2023-08-12T13:00\",\"2023-08-12T14:00\",\"2023-08-12T15:00\",\"2023-08-12T16:00\",\"2023-08-12T17:00\",\"2023-08-12T18:00\",\"2023-08-12T19:00\",\"2023-08-12T20:00\",\"2023-08-12T21:00\",\"2023-08-12T22:00\",\"2023-08-12T23:00\",\"2023-08-13T00:00\",\"2023-08-13T01:00\",\"2023-08-13T02:00\",\"2023-08-13T03:00\",\"2023-08-13T04:00\",\"2023-08-13T05:00\",\"2023-08-13T06:00\",\"2023-08-13T07:00\",\"2023-08-13T08:00\",\"2023-08-13T09:00\",\"2023-08-13T10:00\",\"2023-08-13T11:00\",\"2023-08-13T12:00\",\"2023-08-13T13:00\",\"2023-08-13T14:00\",\"2023-08-13T15:00\",\"2023-08-13T16:00\",\"2023-08-13T17:00\",\"2023-08-13T18:00\",\"2023-08-13T19:00\",\"2023-08-13T20:00\",\"2023-08-13T21:00\",\"2023-08-13T22:00\",\"2023-08-13T23:00\"],\"temperature_2m\":[53.0,51.2,50.9,50.4,50.7,51.3,51.7,52.9,54.3,56.1,57.4,59.3,59.1,60.7,59.7,58.8,58.8,57.8,56.6,55.3,53.9,52.7,52.9,53.2,52.0,51.8,51.3,50.7,50.8,51.5,53.9,57.7,61.2,63.2,64.7,66.6,67.5,67.0,68.7,68.7,67.9,66.2,64.4,61.4,59.8,58.9,57.9,56.3,55.7,55.3,55.5,55.4,55.7,56.5,57.6,58.8,59.7,59.1,58.9,60.6,59.9,59.8,59.9,61.7,63.2,63.6,62.3,58.9,57.3,57.1,57.0,56.5,56.2,56.0,55.3,54.7,54.4,55.2,57.8,60.7,63.0,65.3,66.9,68.2,70.1,72.1,72.6,71.4,69.7,68.6,66.2,63.6,61.8,60.6,59.6,58.9,58.0,57.1,56.3,56.2,56.7,57.9,59.9,63.7,68.4,72.4,75.0,76.8,78.0,78.7,78.9,78.4,76.9,74.8,72.5,70.1,67.6,65.6,64.4,63.9,63.4,62.7,62.2,62.1,62.5,63.4,65.1,68.0,71.7,74.8,76.8,78.2,79.1,79.6,79.7,79.2,77.6,75.3,73.7,68.6,66.8,65.3,64.2,63.4,62.6,61.7,60.9,60.6,60.9,61.6,63.2,65.9,69.3,72.2,74.4,76.2,77.6,78.8,79.6,79.6,78.4,76.4,74.3,72.3,70.4,68.7,67.6,66.8]}}\u001b[0m\n", + "\n", + "\u001b[1m> Finished chain.\u001b[0m\n" + ] + }, + { + "data": { + "text/plain": [ + "' The current temperature in Munich, Germany is 52.9°F.'" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from langchain.llms import OpenAI\n", + "from langchain.chains import APIChain\n", + "from langchain.chains.api import open_meteo_docs\n", + "llm = OpenAI(temperature=0)\n", + "chain = APIChain.from_llm_and_api_docs(llm, open_meteo_docs.OPEN_METEO_DOCS, verbose=True)\n", + "chain.run('What is the weather like right now in Munich, Germany in degrees Fahrenheit?')" + ] + }, + { + "cell_type": "markdown", + "id": "5b179318", + "metadata": {}, + "source": [ + "Note that we supply information about the API:" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "id": "a9e03cc2", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'BASE URL: https://api.open-meteo.com/\\n\\nAPI Documentation\\nThe API endpoint /v1/forecast accepts a geographical coordinate, a list of weather variables and responds with a JSON hourly weather forecast for 7 days. Time always starts at 0:00 today and contains 168 hours. All URL parameters are listed below:\\n\\nParameter\\tFormat\\tRequired\\tDefault\\tDescription\\nlatitude, longitude\\tFloating point\\tYes\\t\\tGeographical WGS84 coordinate of the location\\nhourly\\tString array\\tNo\\t\\tA list of weather variables which shou'" + ] + }, + "execution_count": 37, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "open_meteo_docs.OPEN_METEO_DOCS[0:500]" + ] + }, + { + "cell_type": "markdown", + "id": "3fab7930", + "metadata": {}, + "source": [ + "Under the hood, we do two things:\n", + " \n", + "* `api_request_chain`: Generate an API URL based on the input question and the api_docs\n", + "* `api_answer_chain`: generate a final answer based on the API response\n", + "\n", + "We can look at the [LangSmith trace](https://smith.langchain.com/public/1e0d18ca-0d76-444c-97df-a939a6a815a7/r) to inspect this:\n", + "\n", + "* The `api_request_chain` produces the API url from our question and the API documentation:\n", + "\n", + "![Image description](/img/api_chain.png)\n", + "\n", + "* [Here](https://github.com/langchain-ai/langchain/blob/bbd22b9b761389a5e40fc45b0570e1830aabb707/libs/langchain/langchain/chains/api/base.py#L82) we make the API request with the API url.\n", + "* The `api_answer_chain` takes the response from the API and provides us with a natural langugae response:\n", + "\n", + "![Image description](/img/api_chain_response.png)" + ] + }, + { + "cell_type": "markdown", + "id": "2511f446", + "metadata": {}, + "source": [ + "### Going deeper\n", + "\n", + "**Test with other APIs**" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1e1cf418", + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "os.environ['TMDB_BEARER_TOKEN'] = \"\"\n", + "from langchain.chains.api import tmdb_docs\n", + "headers = {\"Authorization\": f\"Bearer {os.environ['TMDB_BEARER_TOKEN']}\"}\n", + "chain = APIChain.from_llm_and_api_docs(llm, tmdb_docs.TMDB_DOCS, headers=headers, verbose=True)\n", + "chain.run(\"Search for 'Avatar'\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "dd80a717", + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "from langchain.llms import OpenAI\n", + "from langchain.chains.api import podcast_docs\n", + "from langchain.chains import APIChain\n", + " \n", + "listen_api_key = 'xxx' # Get api key here: https://www.listennotes.com/api/pricing/\n", + "llm = OpenAI(temperature=0)\n", + "headers = {\"X-ListenAPI-Key\": listen_api_key}\n", + "chain = APIChain.from_llm_and_api_docs(llm, podcast_docs.PODCAST_DOCS, headers=headers, verbose=True)\n", + "chain.run(\"Search for 'silicon valley bank' podcast episodes, audio length is more than 30 minutes, return only 1 results\")" + ] + }, + { + "cell_type": "markdown", + "id": "a5939be5", + "metadata": {}, + "source": [ + "**Web requests**\n", + "\n", + "URL requets are such a common use-case that we have the `LLMRequestsChain`, which makes a HTTP GET request. " + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "id": "0b158296", + "metadata": {}, + "outputs": [], + "source": [ + "from langchain.llms import OpenAI\n", + "from langchain.prompts import PromptTemplate\n", + "from langchain.chains import LLMRequestsChain, LLMChain" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "id": "d49c33e4", + "metadata": {}, + "outputs": [], + "source": [ + "template = \"\"\"Between >>> and <<< are the raw search result text from google.\n", + "Extract the answer to the question '{query}' or say \"not found\" if the information is not contained.\n", + "Use the format\n", + "Extracted:\n", + ">>> {requests_result} <<<\n", + "Extracted:\"\"\"\n", + "\n", + "PROMPT = PromptTemplate(\n", + " input_variables=[\"query\", \"requests_result\"],\n", + " template=template,\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "id": "d0fd4aab", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'query': 'What are the Three (3) biggest countries, and their respective sizes?',\n", + " 'url': 'https://www.google.com/search?q=What+are+the+Three+(3)+biggest+countries,+and+their+respective+sizes?',\n", + " 'output': ' Russia (17,098,242 km²), Canada (9,984,670 km²), China (9,706,961 km²)'}" + ] + }, + "execution_count": 43, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "chain = LLMRequestsChain(llm_chain=LLMChain(llm=OpenAI(temperature=0), prompt=PROMPT))\n", + "question = \"What are the Three (3) biggest countries, and their respective sizes?\"\n", + "inputs = {\n", + " \"query\": question,\n", + " \"url\": \"https://www.google.com/search?q=\" + question.replace(\" \", \"+\"),\n", + "}\n", + "chain(inputs)" + ] + } + ], + "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", + "version": "3.9.16" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/docs/extras/use_cases/apis/index.mdx b/docs/extras/use_cases/apis/index.mdx deleted file mode 100644 index c5f3c12932..0000000000 --- a/docs/extras/use_cases/apis/index.mdx +++ /dev/null @@ -1,24 +0,0 @@ ---- -sidebar_position: 3 ---- - -# Interacting with APIs - -Lots of data and information is stored behind APIs. -This page covers all resources available in LangChain for working with APIs. - -## Chains - -If you are just getting started, and you have relatively simple apis, you should get started with chains. -Chains are a sequence of predetermined steps, so they are good to get started with as they give you more control and let you -understand what is happening better. - -- [API Chain](/docs/use_cases/apis/api.html) - -## Agents - -Agents are more complex, and involve multiple queries to the LLM to understand what to do. -The downside of agents are that you have less control. The upside is that they are more powerful, -which allows you to use them on larger and more complex schemas. - -- [OpenAPI Agent](/docs/integrations/toolkits/openapi.html) diff --git a/docs/extras/use_cases/apis/llm_requests.ipynb b/docs/extras/use_cases/apis/llm_requests.ipynb deleted file mode 100644 index a5bbe64ce3..0000000000 --- a/docs/extras/use_cases/apis/llm_requests.ipynb +++ /dev/null @@ -1,123 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "dd7ec7af", - "metadata": {}, - "source": [ - "# HTTP request chain\n", - "\n", - "Using the request library to get HTML results from a URL and then an LLM to parse results" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "id": "dd8eae75", - "metadata": {}, - "outputs": [], - "source": [ - "from langchain.llms import OpenAI\n", - "from langchain.chains import LLMRequestsChain, LLMChain" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "id": "65bf324e", - "metadata": {}, - "outputs": [], - "source": [ - "from langchain.prompts import PromptTemplate\n", - "\n", - "template = \"\"\"Between >>> and <<< are the raw search result text from google.\n", - "Extract the answer to the question '{query}' or say \"not found\" if the information is not contained.\n", - "Use the format\n", - "Extracted:\n", - ">>> {requests_result} <<<\n", - "Extracted:\"\"\"\n", - "\n", - "PROMPT = PromptTemplate(\n", - " input_variables=[\"query\", \"requests_result\"],\n", - " template=template,\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "id": "f36ae0d8", - "metadata": {}, - "outputs": [], - "source": [ - "chain = LLMRequestsChain(llm_chain=LLMChain(llm=OpenAI(temperature=0), prompt=PROMPT))" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "id": "b5d22d9d", - "metadata": {}, - "outputs": [], - "source": [ - "question = \"What are the Three (3) biggest countries, and their respective sizes?\"\n", - "inputs = {\n", - " \"query\": question,\n", - " \"url\": \"https://www.google.com/search?q=\" + question.replace(\" \", \"+\"),\n", - "}" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "id": "2ea81168", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'query': 'What are the Three (3) biggest countries, and their respective sizes?',\n", - " 'url': 'https://www.google.com/search?q=What+are+the+Three+(3)+biggest+countries,+and+their+respective+sizes?',\n", - " 'output': ' Russia (17,098,242 km²), Canada (9,984,670 km²), United States (9,826,675 km²)'}" - ] - }, - "execution_count": 5, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "chain(inputs)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "db8f2b6d", - "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", - "version": "3.11.3" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/docs/extras/use_cases/apis/openai_openapi.yaml b/docs/extras/use_cases/apis/openai_openapi.yaml deleted file mode 100644 index 8962cccc77..0000000000 --- a/docs/extras/use_cases/apis/openai_openapi.yaml +++ /dev/null @@ -1,3650 +0,0 @@ -openapi: 3.0.0 -info: - title: OpenAI API - description: APIs for sampling from and fine-tuning language models - version: '1.2.0' -servers: - - url: https://api.openai.com/v1 -tags: -- name: OpenAI - description: The OpenAI REST API -paths: - /engines: - get: - operationId: listEngines - deprecated: true - tags: - - OpenAI - summary: Lists the currently available (non-finetuned) models, and provides basic information about each one such as the owner and availability. - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: '#/components/schemas/ListEnginesResponse' - x-oaiMeta: - name: List engines - group: engines - path: list - examples: - curl: | - curl https://api.openai.com/v1/engines \ - -H 'Authorization: Bearer YOUR_API_KEY' - python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.Engine.list() - node.js: | - const { Configuration, OpenAIApi } = require("openai"); - const configuration = new Configuration({ - apiKey: process.env.OPENAI_API_KEY, - }); - const openai = new OpenAIApi(configuration); - const response = await openai.listEngines(); - response: | - { - "data": [ - { - "id": "engine-id-0", - "object": "engine", - "owner": "organization-owner", - "ready": true - }, - { - "id": "engine-id-2", - "object": "engine", - "owner": "organization-owner", - "ready": true - }, - { - "id": "engine-id-3", - "object": "engine", - "owner": "openai", - "ready": false - }, - ], - "object": "list" - } - - /engines/{engine_id}: - get: - operationId: retrieveEngine - deprecated: true - tags: - - OpenAI - summary: Retrieves a model instance, providing basic information about it such as the owner and availability. - parameters: - - in: path - name: engine_id - required: true - schema: - type: string - # ideally this will be an actual ID, so this will always work from browser - example: - davinci - description: &engine_id_description > - The ID of the engine to use for this request - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: '#/components/schemas/Engine' - x-oaiMeta: - name: Retrieve engine - group: engines - path: retrieve - examples: - curl: | - curl https://api.openai.com/v1/engines/VAR_model_id \ - -H 'Authorization: Bearer YOUR_API_KEY' - python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.Engine.retrieve("VAR_model_id") - node.js: | - const { Configuration, OpenAIApi } = require("openai"); - const configuration = new Configuration({ - apiKey: process.env.OPENAI_API_KEY, - }); - const openai = new OpenAIApi(configuration); - const response = await openai.retrieveEngine("VAR_model_id"); - response: | - { - "id": "VAR_model_id", - "object": "engine", - "owner": "openai", - "ready": true - } - - /completions: - post: - operationId: createCompletion - tags: - - OpenAI - summary: Creates a completion for the provided prompt and parameters - requestBody: - required: true - content: - application/json: - schema: - $ref: '#/components/schemas/CreateCompletionRequest' - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: '#/components/schemas/CreateCompletionResponse' - x-oaiMeta: - name: Create completion - group: completions - path: create - examples: - curl: | - curl https://api.openai.com/v1/completions \ - -H 'Content-Type: application/json' \ - -H 'Authorization: Bearer YOUR_API_KEY' \ - -d '{ - "model": "VAR_model_id", - "prompt": "Say this is a test", - "max_tokens": 7, - "temperature": 0 - }' - python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.Completion.create( - model="VAR_model_id", - prompt="Say this is a test", - max_tokens=7, - temperature=0 - ) - node.js: | - const { Configuration, OpenAIApi } = require("openai"); - const configuration = new Configuration({ - apiKey: process.env.OPENAI_API_KEY, - }); - const openai = new OpenAIApi(configuration); - const response = await openai.createCompletion({ - model: "VAR_model_id", - prompt: "Say this is a test", - max_tokens: 7, - temperature: 0, - }); - parameters: | - { - "model": "VAR_model_id", - "prompt": "Say this is a test", - "max_tokens": 7, - "temperature": 0, - "top_p": 1, - "n": 1, - "stream": false, - "logprobs": null, - "stop": "\n" - } - response: | - { - "id": "cmpl-uqkvlQyYK7bGYrRHQ0eXlWi7", - "object": "text_completion", - "created": 1589478378, - "model": "VAR_model_id", - "choices": [ - { - "text": "\n\nThis is indeed a test", - "index": 0, - "logprobs": null, - "finish_reason": "length" - } - ], - "usage": { - "prompt_tokens": 5, - "completion_tokens": 7, - "total_tokens": 12 - } - } - /chat/completions: - post: - operationId: createChatCompletion - tags: - - OpenAI - summary: Creates a completion for the chat message - requestBody: - required: true - content: - application/json: - schema: - $ref: '#/components/schemas/CreateChatCompletionRequest' - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: '#/components/schemas/CreateChatCompletionResponse' - - x-oaiMeta: - name: Create chat completion - group: chat - path: create - beta: true - examples: - curl: | - curl https://api.openai.com/v1/chat/completions \ - -H 'Content-Type: application/json' \ - -H 'Authorization: Bearer YOUR_API_KEY' \ - -d '{ - "model": "gpt-3.5-turbo", - "messages": [{"role": "user", "content": "Hello!"}] - }' - python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - - completion = openai.ChatCompletion.create( - model="gpt-3.5-turbo", - messages=[ - {"role": "user", "content": "Hello!"} - ] - ) - - print(completion.choices[0].message) - node.js: | - const { Configuration, OpenAIApi } = require("openai"); - - const configuration = new Configuration({ - apiKey: process.env.OPENAI_API_KEY, - }); - const openai = new OpenAIApi(configuration); - - const completion = await openai.createChatCompletion({ - model: "gpt-3.5-turbo", - messages: [{role: "user", content: "Hello world"}], - }); - console.log(completion.data.choices[0].message); - parameters: | - { - "model": "gpt-3.5-turbo", - "messages": [{"role": "user", "content": "Hello!"}] - } - response: | - { - "id": "chatcmpl-123", - "object": "chat.completion", - "created": 1677652288, - "choices": [{ - "index": 0, - "message": { - "role": "assistant", - "content": "\n\nHello there, how may I assist you today?", - }, - "finish_reason": "stop" - }], - "usage": { - "prompt_tokens": 9, - "completion_tokens": 12, - "total_tokens": 21 - } - } - - /edits: - post: - operationId: createEdit - tags: - - OpenAI - summary: Creates a new edit for the provided input, instruction, and parameters. - requestBody: - required: true - content: - application/json: - schema: - $ref: '#/components/schemas/CreateEditRequest' - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: '#/components/schemas/CreateEditResponse' - x-oaiMeta: - name: Create edit - group: edits - path: create - examples: - curl: | - curl https://api.openai.com/v1/edits \ - -H 'Content-Type: application/json' \ - -H 'Authorization: Bearer YOUR_API_KEY' \ - -d '{ - "model": "VAR_model_id", - "input": "What day of the wek is it?", - "instruction": "Fix the spelling mistakes" - }' - python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.Edit.create( - model="VAR_model_id", - input="What day of the wek is it?", - instruction="Fix the spelling mistakes" - ) - node.js: | - const { Configuration, OpenAIApi } = require("openai"); - const configuration = new Configuration({ - apiKey: process.env.OPENAI_API_KEY, - }); - const openai = new OpenAIApi(configuration); - const response = await openai.createEdit({ - model: "VAR_model_id", - input: "What day of the wek is it?", - instruction: "Fix the spelling mistakes", - }); - parameters: | - { - "model": "VAR_model_id", - "input": "What day of the wek is it?", - "instruction": "Fix the spelling mistakes", - } - response: | - { - "object": "edit", - "created": 1589478378, - "choices": [ - { - "text": "What day of the week is it?", - "index": 0, - } - ], - "usage": { - "prompt_tokens": 25, - "completion_tokens": 32, - "total_tokens": 57 - } - } - - /images/generations: - post: - operationId: createImage - tags: - - OpenAI - summary: Creates an image given a prompt. - requestBody: - required: true - content: - application/json: - schema: - $ref: '#/components/schemas/CreateImageRequest' - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: '#/components/schemas/ImagesResponse' - x-oaiMeta: - name: Create image - group: images - path: create - beta: true - examples: - curl: | - curl https://api.openai.com/v1/images/generations \ - -H 'Content-Type: application/json' \ - -H 'Authorization: Bearer YOUR_API_KEY' \ - -d '{ - "prompt": "A cute baby sea otter", - "n": 2, - "size": "1024x1024" - }' - python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.Image.create( - prompt="A cute baby sea otter", - n=2, - size="1024x1024" - ) - node.js: | - const { Configuration, OpenAIApi } = require("openai"); - const configuration = new Configuration({ - apiKey: process.env.OPENAI_API_KEY, - }); - const openai = new OpenAIApi(configuration); - const response = await openai.createImage({ - prompt: "A cute baby sea otter", - n: 2, - size: "1024x1024", - }); - parameters: | - { - "prompt": "A cute baby sea otter", - "n": 2, - "size": "1024x1024" - } - response: | - { - "created": 1589478378, - "data": [ - { - "url": "https://..." - }, - { - "url": "https://..." - } - ] - } - - /images/edits: - post: - operationId: createImageEdit - tags: - - OpenAI - summary: Creates an edited or extended image given an original image and a prompt. - requestBody: - required: true - content: - multipart/form-data: - schema: - $ref: '#/components/schemas/CreateImageEditRequest' - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: '#/components/schemas/ImagesResponse' - x-oaiMeta: - name: Create image edit - group: images - path: create-edit - beta: true - examples: - curl: | - curl https://api.openai.com/v1/images/edits \ - -H 'Authorization: Bearer YOUR_API_KEY' \ - -F image='@otter.png' \ - -F mask='@mask.png' \ - -F prompt="A cute baby sea otter wearing a beret" \ - -F n=2 \ - -F size="1024x1024" - python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.Image.create_edit( - image=open("otter.png", "rb"), - mask=open("mask.png", "rb"), - prompt="A cute baby sea otter wearing a beret", - n=2, - size="1024x1024" - ) - node.js: | - const { Configuration, OpenAIApi } = require("openai"); - const configuration = new Configuration({ - apiKey: process.env.OPENAI_API_KEY, - }); - const openai = new OpenAIApi(configuration); - const response = await openai.createImageEdit( - fs.createReadStream("otter.png"), - fs.createReadStream("mask.png"), - "A cute baby sea otter wearing a beret", - 2, - "1024x1024" - ); - response: | - { - "created": 1589478378, - "data": [ - { - "url": "https://..." - }, - { - "url": "https://..." - } - ] - } - - /images/variations: - post: - operationId: createImageVariation - tags: - - OpenAI - summary: Creates a variation of a given image. - requestBody: - required: true - content: - multipart/form-data: - schema: - $ref: '#/components/schemas/CreateImageVariationRequest' - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: '#/components/schemas/ImagesResponse' - x-oaiMeta: - name: Create image variation - group: images - path: create-variation - beta: true - examples: - curl: | - curl https://api.openai.com/v1/images/variations \ - -H 'Authorization: Bearer YOUR_API_KEY' \ - -F image='@otter.png' \ - -F n=2 \ - -F size="1024x1024" - python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.Image.create_variation( - image=open("otter.png", "rb"), - n=2, - size="1024x1024" - ) - node.js: | - const { Configuration, OpenAIApi } = require("openai"); - const configuration = new Configuration({ - apiKey: process.env.OPENAI_API_KEY, - }); - const openai = new OpenAIApi(configuration); - const response = await openai.createImageVariation( - fs.createReadStream("otter.png"), - 2, - "1024x1024" - ); - response: | - { - "created": 1589478378, - "data": [ - { - "url": "https://..." - }, - { - "url": "https://..." - } - ] - } - - /embeddings: - post: - operationId: createEmbedding - tags: - - OpenAI - summary: Creates an embedding vector representing the input text. - requestBody: - required: true - content: - application/json: - schema: - $ref: '#/components/schemas/CreateEmbeddingRequest' - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: '#/components/schemas/CreateEmbeddingResponse' - x-oaiMeta: - name: Create embeddings - group: embeddings - path: create - examples: - curl: | - curl https://api.openai.com/v1/embeddings \ - -X POST \ - -H "Authorization: Bearer YOUR_API_KEY" \ - -H "Content-Type: application/json" \ - -d '{"input": "The food was delicious and the waiter...", - "model": "text-embedding-ada-002"}' - - python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.Embedding.create( - model="text-embedding-ada-002", - input="The food was delicious and the waiter..." - ) - node.js: | - const { Configuration, OpenAIApi } = require("openai"); - const configuration = new Configuration({ - apiKey: process.env.OPENAI_API_KEY, - }); - const openai = new OpenAIApi(configuration); - const response = await openai.createEmbedding({ - model: "text-embedding-ada-002", - input: "The food was delicious and the waiter...", - }); - parameters: | - { - "model": "text-embedding-ada-002", - "input": "The food was delicious and the waiter..." - } - response: | - { - "object": "list", - "data": [ - { - "object": "embedding", - "embedding": [ - 0.0023064255, - -0.009327292, - .... (1536 floats total for ada-002) - -0.0028842222, - ], - "index": 0 - } - ], - "model": "text-embedding-ada-002", - "usage": { - "prompt_tokens": 8, - "total_tokens": 8 - } - } - - /audio/transcriptions: - post: - operationId: createTranscription - tags: - - OpenAI - summary: Transcribes audio into the input language. - requestBody: - required: true - content: - multipart/form-data: - schema: - $ref: '#/components/schemas/CreateTranscriptionRequest' - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: '#/components/schemas/CreateTranscriptionResponse' - x-oaiMeta: - name: Create transcription - group: audio - path: create - beta: true - examples: - curl: | - curl https://api.openai.com/v1/audio/transcriptions \ - -X POST \ - -H 'Authorization: Bearer TOKEN' \ - -H 'Content-Type: multipart/form-data' \ - -F file=@/path/to/file/audio.mp3 \ - -F model=whisper-1 - python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - audio_file = open("audio.mp3", "rb") - transcript = openai.Audio.transcribe("whisper-1", audio_file) - node: | - const { Configuration, OpenAIApi } = require("openai"); - const configuration = new Configuration({ - apiKey: process.env.OPENAI_API_KEY, - }); - const openai = new OpenAIApi(configuration); - const resp = await openai.createTranscription( - fs.createReadStream("audio.mp3"), - "whisper-1" - ); - parameters: | - { - "file": "audio.mp3", - "model": "whisper-1" - } - response: | - { - "text": "Imagine the wildest idea that you've ever had, and you're curious about how it might scale to something that's a 100, a 1,000 times bigger. This is a place where you can get to do that." - } - - /audio/translations: - post: - operationId: createTranslation - tags: - - OpenAI - summary: Translates audio into into English. - requestBody: - required: true - content: - multipart/form-data: - schema: - $ref: '#/components/schemas/CreateTranslationRequest' - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: '#/components/schemas/CreateTranslationResponse' - x-oaiMeta: - name: Create translation - group: audio - path: create - beta: true - examples: - curl: | - curl https://api.openai.com/v1/audio/translations \ - -X POST \ - -H 'Authorization: Bearer TOKEN' \ - -H 'Content-Type: multipart/form-data' \ - -F file=@/path/to/file/german.m4a \ - -F model=whisper-1 - python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - audio_file = open("german.m4a", "rb") - transcript = openai.Audio.translate("whisper-1", audio_file) - node: | - const { Configuration, OpenAIApi } = require("openai"); - const configuration = new Configuration({ - apiKey: process.env.OPENAI_API_KEY, - }); - const openai = new OpenAIApi(configuration); - const resp = await openai.createTranslation( - fs.createReadStream("audio.mp3"), - "whisper-1" - ); - parameters: | - { - "file": "german.m4a", - "model": "whisper-1" - } - response: | - { - "text": "Hello, my name is Wolfgang and I come from Germany. Where are you heading today?" - } - - /engines/{engine_id}/search: - post: - operationId: createSearch - deprecated: true - tags: - - OpenAI - summary: | - The search endpoint computes similarity scores between provided query and documents. Documents can be passed directly to the API if there are no more than 200 of them. - - To go beyond the 200 document limit, documents can be processed offline and then used for efficient retrieval at query time. When `file` is set, the search endpoint searches over all the documents in the given file and returns up to the `max_rerank` number of documents. These documents will be returned along with their search scores. - - The similarity score is a positive score that usually ranges from 0 to 300 (but can sometimes go higher), where a score above 200 usually means the document is semantically similar to the query. - parameters: - - in: path - name: engine_id - required: true - schema: - type: string - example: davinci - description: The ID of the engine to use for this request. You can select one of `ada`, `babbage`, `curie`, or `davinci`. - requestBody: - required: true - content: - application/json: - schema: - $ref: '#/components/schemas/CreateSearchRequest' - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: '#/components/schemas/CreateSearchResponse' - x-oaiMeta: - name: Create search - group: searches - path: create - examples: - curl: | - curl https://api.openai.com/v1/engines/davinci/search \ - -H "Content-Type: application/json" \ - -H 'Authorization: Bearer YOUR_API_KEY' \ - -d '{ - "documents": ["White House", "hospital", "school"], - "query": "the president" - }' - python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.Engine("davinci").search( - documents=["White House", "hospital", "school"], - query="the president" - ) - node.js: | - const { Configuration, OpenAIApi } = require("openai"); - const configuration = new Configuration({ - apiKey: process.env.OPENAI_API_KEY, - }); - const openai = new OpenAIApi(configuration); - const response = await openai.createSearch("davinci", { - documents: ["White House", "hospital", "school"], - query: "the president", - }); - parameters: | - { - "documents": [ - "White House", - "hospital", - "school" - ], - "query": "the president" - } - response: | - { - "data": [ - { - "document": 0, - "object": "search_result", - "score": 215.412 - }, - { - "document": 1, - "object": "search_result", - "score": 40.316 - }, - { - "document": 2, - "object": "search_result", - "score": 55.226 - } - ], - "object": "list" - } - - /files: - get: - operationId: listFiles - tags: - - OpenAI - summary: Returns a list of files that belong to the user's organization. - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: '#/components/schemas/ListFilesResponse' - x-oaiMeta: - name: List files - group: files - path: list - examples: - curl: | - curl https://api.openai.com/v1/files \ - -H 'Authorization: Bearer YOUR_API_KEY' - python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.File.list() - node.js: | - const { Configuration, OpenAIApi } = require("openai"); - const configuration = new Configuration({ - apiKey: process.env.OPENAI_API_KEY, - }); - const openai = new OpenAIApi(configuration); - const response = await openai.listFiles(); - response: | - { - "data": [ - { - "id": "file-ccdDZrC3iZVNiQVeEA6Z66wf", - "object": "file", - "bytes": 175, - "created_at": 1613677385, - "filename": "train.jsonl", - "purpose": "search" - }, - { - "id": "file-XjGxS3KTG0uNmNOK362iJua3", - "object": "file", - "bytes": 140, - "created_at": 1613779121, - "filename": "puppy.jsonl", - "purpose": "search" - } - ], - "object": "list" - } - post: - operationId: createFile - tags: - - OpenAI - summary: | - Upload a file that contains document(s) to be used across various endpoints/features. Currently, the size of all the files uploaded by one organization can be up to 1 GB. Please contact us if you need to increase the storage limit. - - requestBody: - required: true - content: - multipart/form-data: - schema: - $ref: '#/components/schemas/CreateFileRequest' - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: '#/components/schemas/OpenAIFile' - x-oaiMeta: - name: Upload file - group: files - path: upload - examples: - curl: | - curl https://api.openai.com/v1/files \ - -H "Authorization: Bearer YOUR_API_KEY" \ - -F purpose="fine-tune" \ - -F file='@mydata.jsonl' - - python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.File.create( - file=open("mydata.jsonl", "rb"), - purpose='fine-tune' - ) - node.js: | - const fs = require("fs"); - const { Configuration, OpenAIApi } = require("openai"); - const configuration = new Configuration({ - apiKey: process.env.OPENAI_API_KEY, - }); - const openai = new OpenAIApi(configuration); - const response = await openai.createFile( - fs.createReadStream("mydata.jsonl"), - "fine-tune" - ); - response: | - { - "id": "file-XjGxS3KTG0uNmNOK362iJua3", - "object": "file", - "bytes": 140, - "created_at": 1613779121, - "filename": "mydata.jsonl", - "purpose": "fine-tune" - } - - /files/{file_id}: - delete: - operationId: deleteFile - tags: - - OpenAI - summary: Delete a file. - parameters: - - in: path - name: file_id - required: true - schema: - type: string - description: The ID of the file to use for this request - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: '#/components/schemas/DeleteFileResponse' - x-oaiMeta: - name: Delete file - group: files - path: delete - examples: - curl: | - curl https://api.openai.com/v1/files/file-XjGxS3KTG0uNmNOK362iJua3 \ - -X DELETE \ - -H 'Authorization: Bearer YOUR_API_KEY' - python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.File.delete("file-XjGxS3KTG0uNmNOK362iJua3") - node.js: | - const { Configuration, OpenAIApi } = require("openai"); - const configuration = new Configuration({ - apiKey: process.env.OPENAI_API_KEY, - }); - const openai = new OpenAIApi(configuration); - const response = await openai.deleteFile("file-XjGxS3KTG0uNmNOK362iJua3"); - response: | - { - "id": "file-XjGxS3KTG0uNmNOK362iJua3", - "object": "file", - "deleted": true - } - get: - operationId: retrieveFile - tags: - - OpenAI - summary: Returns information about a specific file. - parameters: - - in: path - name: file_id - required: true - schema: - type: string - description: The ID of the file to use for this request - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: '#/components/schemas/OpenAIFile' - x-oaiMeta: - name: Retrieve file - group: files - path: retrieve - examples: - curl: | - curl https://api.openai.com/v1/files/file-XjGxS3KTG0uNmNOK362iJua3 \ - -H 'Authorization: Bearer YOUR_API_KEY' - python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.File.retrieve("file-XjGxS3KTG0uNmNOK362iJua3") - node.js: | - const { Configuration, OpenAIApi } = require("openai"); - const configuration = new Configuration({ - apiKey: process.env.OPENAI_API_KEY, - }); - const openai = new OpenAIApi(configuration); - const response = await openai.retrieveFile("file-XjGxS3KTG0uNmNOK362iJua3"); - response: | - { - "id": "file-XjGxS3KTG0uNmNOK362iJua3", - "object": "file", - "bytes": 140, - "created_at": 1613779657, - "filename": "mydata.jsonl", - "purpose": "fine-tune" - } - - /files/{file_id}/content: - get: - operationId: downloadFile - tags: - - OpenAI - summary: Returns the contents of the specified file - parameters: - - in: path - name: file_id - required: true - schema: - type: string - description: The ID of the file to use for this request - responses: - "200": - description: OK - content: - application/json: - schema: - type: string - x-oaiMeta: - name: Retrieve file content - group: files - path: retrieve-content - examples: - curl: | - curl https://api.openai.com/v1/files/file-XjGxS3KTG0uNmNOK362iJua3/content \ - -H 'Authorization: Bearer YOUR_API_KEY' > file.jsonl - python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - content = openai.File.download("file-XjGxS3KTG0uNmNOK362iJua3") - node.js: | - const { Configuration, OpenAIApi } = require("openai"); - const configuration = new Configuration({ - apiKey: process.env.OPENAI_API_KEY, - }); - const openai = new OpenAIApi(configuration); - const response = await openai.downloadFile("file-XjGxS3KTG0uNmNOK362iJua3"); - - /answers: - post: - operationId: createAnswer - deprecated: true - tags: - - OpenAI - summary: | - Answers the specified question using the provided documents and examples. - - The endpoint first [searches](/docs/api-reference/searches) over provided documents or files to find relevant context. The relevant context is combined with the provided examples and question to create the prompt for [completion](/docs/api-reference/completions). - requestBody: - required: true - content: - application/json: - schema: - $ref: '#/components/schemas/CreateAnswerRequest' - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: '#/components/schemas/CreateAnswerResponse' - x-oaiMeta: - name: Create answer - group: answers - path: create - examples: - curl: | - curl https://api.openai.com/v1/answers \ - -X POST \ - -H "Authorization: Bearer YOUR_API_KEY" \ - -H 'Content-Type: application/json' \ - -d '{ - "documents": ["Puppy A is happy.", "Puppy B is sad."], - "question": "which puppy is happy?", - "search_model": "ada", - "model": "curie", - "examples_context": "In 2017, U.S. life expectancy was 78.6 years.", - "examples": [["What is human life expectancy in the United States?","78 years."]], - "max_tokens": 5, - "stop": ["\n", "<|endoftext|>"] - }' - - python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.Answer.create( - search_model="ada", - model="curie", - question="which puppy is happy?", - documents=["Puppy A is happy.", "Puppy B is sad."], - examples_context="In 2017, U.S. life expectancy was 78.6 years.", - examples=[["What is human life expectancy in the United States?","78 years."]], - max_tokens=5, - stop=["\n", "<|endoftext|>"], - ) - node.js: | - const { Configuration, OpenAIApi } = require("openai"); - const configuration = new Configuration({ - apiKey: process.env.OPENAI_API_KEY, - }); - const openai = new OpenAIApi(configuration); - const response = await openai.createAnswer({ - search_model: "ada", - model: "curie", - question: "which puppy is happy?", - documents: ["Puppy A is happy.", "Puppy B is sad."], - examples_context: "In 2017, U.S. life expectancy was 78.6 years.", - examples: [["What is human life expectancy in the United States?","78 years."]], - max_tokens: 5, - stop: ["\n", "<|endoftext|>"], - }); - parameters: | - { - "documents": ["Puppy A is happy.", "Puppy B is sad."], - "question": "which puppy is happy?", - "search_model": "ada", - "model": "curie", - "examples_context": "In 2017, U.S. life expectancy was 78.6 years.", - "examples": [["What is human life expectancy in the United States?","78 years."]], - "max_tokens": 5, - "stop": ["\n", "<|endoftext|>"] - } - response: | - { - "answers": [ - "puppy A." - ], - "completion": "cmpl-2euVa1kmKUuLpSX600M41125Mo9NI", - "model": "curie:2020-05-03", - "object": "answer", - "search_model": "ada", - "selected_documents": [ - { - "document": 0, - "text": "Puppy A is happy. " - }, - { - "document": 1, - "text": "Puppy B is sad. " - } - ] - } - - /classifications: - post: - operationId: createClassification - deprecated: true - tags: - - OpenAI - summary: | - Classifies the specified `query` using provided examples. - - The endpoint first [searches](/docs/api-reference/searches) over the labeled examples - to select the ones most relevant for the particular query. Then, the relevant examples - are combined with the query to construct a prompt to produce the final label via the - [completions](/docs/api-reference/completions) endpoint. - - Labeled examples can be provided via an uploaded `file`, or explicitly listed in the - request using the `examples` parameter for quick tests and small scale use cases. - requestBody: - required: true - content: - application/json: - schema: - $ref: '#/components/schemas/CreateClassificationRequest' - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: '#/components/schemas/CreateClassificationResponse' - x-oaiMeta: - name: Create classification - group: classifications - path: create - examples: - curl: | - curl https://api.openai.com/v1/classifications \ - -X POST \ - -H "Authorization: Bearer YOUR_API_KEY" \ - -H 'Content-Type: application/json' \ - -d '{ - "examples": [ - ["A happy moment", "Positive"], - ["I am sad.", "Negative"], - ["I am feeling awesome", "Positive"]], - "query": "It is a raining day :(", - "search_model": "ada", - "model": "curie", - "labels":["Positive", "Negative", "Neutral"] - }' - python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.Classification.create( - search_model="ada", - model="curie", - examples=[ - ["A happy moment", "Positive"], - ["I am sad.", "Negative"], - ["I am feeling awesome", "Positive"] - ], - query="It is a raining day :(", - labels=["Positive", "Negative", "Neutral"], - ) - node.js: | - const { Configuration, OpenAIApi } = require("openai"); - const configuration = new Configuration({ - apiKey: process.env.OPENAI_API_KEY, - }); - const openai = new OpenAIApi(configuration); - const response = await openai.createClassification({ - search_model: "ada", - model: "curie", - examples: [ - ["A happy moment", "Positive"], - ["I am sad.", "Negative"], - ["I am feeling awesome", "Positive"] - ], - query:"It is a raining day :(", - labels: ["Positive", "Negative", "Neutral"], - }); - parameters: | - { - "examples": [ - ["A happy moment", "Positive"], - ["I am sad.", "Negative"], - ["I am feeling awesome", "Positive"] - ], - "labels": ["Positive", "Negative", "Neutral"], - "query": "It is a raining day :(", - "search_model": "ada", - "model": "curie" - } - response: | - { - "completion": "cmpl-2euN7lUVZ0d4RKbQqRV79IiiE6M1f", - "label": "Negative", - "model": "curie:2020-05-03", - "object": "classification", - "search_model": "ada", - "selected_examples": [ - { - "document": 1, - "label": "Negative", - "text": "I am sad." - }, - { - "document": 0, - "label": "Positive", - "text": "A happy moment" - }, - { - "document": 2, - "label": "Positive", - "text": "I am feeling awesome" - } - ] - } - - /fine-tunes: - post: - operationId: createFineTune - tags: - - OpenAI - summary: | - Creates a job that fine-tunes a specified model from a given dataset. - - Response includes details of the enqueued job including job status and the name of the fine-tuned models once complete. - - [Learn more about Fine-tuning](/docs/guides/fine-tuning) - requestBody: - required: true - content: - application/json: - schema: - $ref: '#/components/schemas/CreateFineTuneRequest' - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: '#/components/schemas/FineTune' - x-oaiMeta: - name: Create fine-tune - group: fine-tunes - path: create - examples: - curl: | - curl https://api.openai.com/v1/fine-tunes \ - -X POST \ - -H "Content-Type: application/json" \ - -H "Authorization: Bearer YOUR_API_KEY" \ - -d '{ - "training_file": "file-XGinujblHPwGLSztz8cPS8XY" - }' - python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.FineTune.create(training_file="file-XGinujblHPwGLSztz8cPS8XY") - node.js: | - const { Configuration, OpenAIApi } = require("openai"); - const configuration = new Configuration({ - apiKey: process.env.OPENAI_API_KEY, - }); - const openai = new OpenAIApi(configuration); - const response = await openai.createFineTune({ - training_file: "file-XGinujblHPwGLSztz8cPS8XY", - }); - response: | - { - "id": "ft-AF1WoRqd3aJAHsqc9NY7iL8F", - "object": "fine-tune", - "model": "curie", - "created_at": 1614807352, - "events": [ - { - "object": "fine-tune-event", - "created_at": 1614807352, - "level": "info", - "message": "Job enqueued. Waiting for jobs ahead to complete. Queue number: 0." - } - ], - "fine_tuned_model": null, - "hyperparams": { - "batch_size": 4, - "learning_rate_multiplier": 0.1, - "n_epochs": 4, - "prompt_loss_weight": 0.1, - }, - "organization_id": "org-...", - "result_files": [], - "status": "pending", - "validation_files": [], - "training_files": [ - { - "id": "file-XGinujblHPwGLSztz8cPS8XY", - "object": "file", - "bytes": 1547276, - "created_at": 1610062281, - "filename": "my-data-train.jsonl", - "purpose": "fine-tune-train" - } - ], - "updated_at": 1614807352, - } - get: - operationId: listFineTunes - tags: - - OpenAI - summary: | - List your organization's fine-tuning jobs - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: '#/components/schemas/ListFineTunesResponse' - x-oaiMeta: - name: List fine-tunes - group: fine-tunes - path: list - examples: - curl: | - curl https://api.openai.com/v1/fine-tunes \ - -H 'Authorization: Bearer YOUR_API_KEY' - python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.FineTune.list() - node.js: | - const { Configuration, OpenAIApi } = require("openai"); - const configuration = new Configuration({ - apiKey: process.env.OPENAI_API_KEY, - }); - const openai = new OpenAIApi(configuration); - const response = await openai.listFineTunes(); - response: | - { - "object": "list", - "data": [ - { - "id": "ft-AF1WoRqd3aJAHsqc9NY7iL8F", - "object": "fine-tune", - "model": "curie", - "created_at": 1614807352, - "fine_tuned_model": null, - "hyperparams": { ... }, - "organization_id": "org-...", - "result_files": [], - "status": "pending", - "validation_files": [], - "training_files": [ { ... } ], - "updated_at": 1614807352, - }, - { ... }, - { ... } - ] - } - - /fine-tunes/{fine_tune_id}: - get: - operationId: retrieveFineTune - tags: - - OpenAI - summary: | - Gets info about the fine-tune job. - - [Learn more about Fine-tuning](/docs/guides/fine-tuning) - parameters: - - in: path - name: fine_tune_id - required: true - schema: - type: string - example: - ft-AF1WoRqd3aJAHsqc9NY7iL8F - description: | - The ID of the fine-tune job - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: '#/components/schemas/FineTune' - x-oaiMeta: - name: Retrieve fine-tune - group: fine-tunes - path: retrieve - examples: - curl: | - curl https://api.openai.com/v1/fine-tunes/ft-AF1WoRqd3aJAHsqc9NY7iL8F \ - -H "Authorization: Bearer YOUR_API_KEY" - python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.FineTune.retrieve(id="ft-AF1WoRqd3aJAHsqc9NY7iL8F") - node.js: | - const { Configuration, OpenAIApi } = require("openai"); - const configuration = new Configuration({ - apiKey: process.env.OPENAI_API_KEY, - }); - const openai = new OpenAIApi(configuration); - const response = await openai.retrieveFineTune("ft-AF1WoRqd3aJAHsqc9NY7iL8F"); - response: | - { - "id": "ft-AF1WoRqd3aJAHsqc9NY7iL8F", - "object": "fine-tune", - "model": "curie", - "created_at": 1614807352, - "events": [ - { - "object": "fine-tune-event", - "created_at": 1614807352, - "level": "info", - "message": "Job enqueued. Waiting for jobs ahead to complete. Queue number: 0." - }, - { - "object": "fine-tune-event", - "created_at": 1614807356, - "level": "info", - "message": "Job started." - }, - { - "object": "fine-tune-event", - "created_at": 1614807861, - "level": "info", - "message": "Uploaded snapshot: curie:ft-acmeco-2021-03-03-21-44-20." - }, - { - "object": "fine-tune-event", - "created_at": 1614807864, - "level": "info", - "message": "Uploaded result files: file-QQm6ZpqdNwAaVC3aSz5sWwLT." - }, - { - "object": "fine-tune-event", - "created_at": 1614807864, - "level": "info", - "message": "Job succeeded." - } - ], - "fine_tuned_model": "curie:ft-acmeco-2021-03-03-21-44-20", - "hyperparams": { - "batch_size": 4, - "learning_rate_multiplier": 0.1, - "n_epochs": 4, - "prompt_loss_weight": 0.1, - }, - "organization_id": "org-...", - "result_files": [ - { - "id": "file-QQm6ZpqdNwAaVC3aSz5sWwLT", - "object": "file", - "bytes": 81509, - "created_at": 1614807863, - "filename": "compiled_results.csv", - "purpose": "fine-tune-results" - } - ], - "status": "succeeded", - "validation_files": [], - "training_files": [ - { - "id": "file-XGinujblHPwGLSztz8cPS8XY", - "object": "file", - "bytes": 1547276, - "created_at": 1610062281, - "filename": "my-data-train.jsonl", - "purpose": "fine-tune-train" - } - ], - "updated_at": 1614807865, - } - - /fine-tunes/{fine_tune_id}/cancel: - post: - operationId: cancelFineTune - tags: - - OpenAI - summary: | - Immediately cancel a fine-tune job. - parameters: - - in: path - name: fine_tune_id - required: true - schema: - type: string - example: - ft-AF1WoRqd3aJAHsqc9NY7iL8F - description: | - The ID of the fine-tune job to cancel - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: '#/components/schemas/FineTune' - x-oaiMeta: - name: Cancel fine-tune - group: fine-tunes - path: cancel - examples: - curl: | - curl https://api.openai.com/v1/fine-tunes/ft-AF1WoRqd3aJAHsqc9NY7iL8F/cancel \ - -X POST \ - -H "Authorization: Bearer YOUR_API_KEY" - python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.FineTune.cancel(id="ft-AF1WoRqd3aJAHsqc9NY7iL8F") - node.js: | - const { Configuration, OpenAIApi } = require("openai"); - const configuration = new Configuration({ - apiKey: process.env.OPENAI_API_KEY, - }); - const openai = new OpenAIApi(configuration); - const response = await openai.cancelFineTune("ft-AF1WoRqd3aJAHsqc9NY7iL8F"); - response: | - { - "id": "ft-xhrpBbvVUzYGo8oUO1FY4nI7", - "object": "fine-tune", - "model": "curie", - "created_at": 1614807770, - "events": [ { ... } ], - "fine_tuned_model": null, - "hyperparams": { ... }, - "organization_id": "org-...", - "result_files": [], - "status": "cancelled", - "validation_files": [], - "training_files": [ - { - "id": "file-XGinujblHPwGLSztz8cPS8XY", - "object": "file", - "bytes": 1547276, - "created_at": 1610062281, - "filename": "my-data-train.jsonl", - "purpose": "fine-tune-train" - } - ], - "updated_at": 1614807789, - } - - /fine-tunes/{fine_tune_id}/events: - get: - operationId: listFineTuneEvents - tags: - - OpenAI - summary: | - Get fine-grained status updates for a fine-tune job. - parameters: - - in: path - name: fine_tune_id - required: true - schema: - type: string - example: - ft-AF1WoRqd3aJAHsqc9NY7iL8F - description: | - The ID of the fine-tune job to get events for. - - in: query - name: stream - required: false - schema: - type: boolean - default: false - description: | - Whether to stream events for the fine-tune job. If set to true, - events will be sent as data-only - [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format) - as they become available. The stream will terminate with a - `data: [DONE]` message when the job is finished (succeeded, cancelled, - or failed). - - If set to false, only events generated so far will be returned. - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: '#/components/schemas/ListFineTuneEventsResponse' - x-oaiMeta: - name: List fine-tune events - group: fine-tunes - path: events - examples: - curl: | - curl https://api.openai.com/v1/fine-tunes/ft-AF1WoRqd3aJAHsqc9NY7iL8F/events \ - -H "Authorization: Bearer YOUR_API_KEY" - python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.FineTune.list_events(id="ft-AF1WoRqd3aJAHsqc9NY7iL8F") - node.js: | - const { Configuration, OpenAIApi } = require("openai"); - const configuration = new Configuration({ - apiKey: process.env.OPENAI_API_KEY, - }); - const openai = new OpenAIApi(configuration); - const response = await openai.listFineTuneEvents("ft-AF1WoRqd3aJAHsqc9NY7iL8F"); - response: | - { - "object": "list", - "data": [ - { - "object": "fine-tune-event", - "created_at": 1614807352, - "level": "info", - "message": "Job enqueued. Waiting for jobs ahead to complete. Queue number: 0." - }, - { - "object": "fine-tune-event", - "created_at": 1614807356, - "level": "info", - "message": "Job started." - }, - { - "object": "fine-tune-event", - "created_at": 1614807861, - "level": "info", - "message": "Uploaded snapshot: curie:ft-acmeco-2021-03-03-21-44-20." - }, - { - "object": "fine-tune-event", - "created_at": 1614807864, - "level": "info", - "message": "Uploaded result files: file-QQm6ZpqdNwAaVC3aSz5sWwLT." - }, - { - "object": "fine-tune-event", - "created_at": 1614807864, - "level": "info", - "message": "Job succeeded." - } - ] - } - - /models: - get: - operationId: listModels - tags: - - OpenAI - summary: Lists the currently available models, and provides basic information about each one such as the owner and availability. - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: '#/components/schemas/ListModelsResponse' - x-oaiMeta: - name: List models - group: models - path: list - examples: - curl: | - curl https://api.openai.com/v1/models \ - -H 'Authorization: Bearer YOUR_API_KEY' - python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.Model.list() - node.js: | - const { Configuration, OpenAIApi } = require("openai"); - const configuration = new Configuration({ - apiKey: process.env.OPENAI_API_KEY, - }); - const openai = new OpenAIApi(configuration); - const response = await openai.listModels(); - response: | - { - "data": [ - { - "id": "model-id-0", - "object": "model", - "owned_by": "organization-owner", - "permission": [...] - }, - { - "id": "model-id-1", - "object": "model", - "owned_by": "organization-owner", - "permission": [...] - }, - { - "id": "model-id-2", - "object": "model", - "owned_by": "openai", - "permission": [...] - }, - ], - "object": "list" - } - - /models/{model}: - get: - operationId: retrieveModel - tags: - - OpenAI - summary: Retrieves a model instance, providing basic information about the model such as the owner and permissioning. - parameters: - - in: path - name: model - required: true - schema: - type: string - # ideally this will be an actual ID, so this will always work from browser - example: - text-davinci-001 - description: - The ID of the model to use for this request - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: '#/components/schemas/Model' - x-oaiMeta: - name: Retrieve model - group: models - path: retrieve - examples: - curl: | - curl https://api.openai.com/v1/models/VAR_model_id \ - -H 'Authorization: Bearer YOUR_API_KEY' - python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.Model.retrieve("VAR_model_id") - node.js: | - const { Configuration, OpenAIApi } = require("openai"); - const configuration = new Configuration({ - apiKey: process.env.OPENAI_API_KEY, - }); - const openai = new OpenAIApi(configuration); - const response = await openai.retrieveModel("VAR_model_id"); - response: | - { - "id": "VAR_model_id", - "object": "model", - "owned_by": "openai", - "permission": [...] - } - delete: - operationId: deleteModel - tags: - - OpenAI - summary: Delete a fine-tuned model. You must have the Owner role in your organization. - parameters: - - in: path - name: model - required: true - schema: - type: string - example: curie:ft-acmeco-2021-03-03-21-44-20 - description: The model to delete - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: '#/components/schemas/DeleteModelResponse' - x-oaiMeta: - name: Delete fine-tune model - group: fine-tunes - path: delete-model - examples: - curl: | - curl https://api.openai.com/v1/models/curie:ft-acmeco-2021-03-03-21-44-20 \ - -X DELETE \ - -H "Authorization: Bearer YOUR_API_KEY" - python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.Model.delete("curie:ft-acmeco-2021-03-03-21-44-20") - node.js: | - const { Configuration, OpenAIApi } = require("openai"); - const configuration = new Configuration({ - apiKey: process.env.OPENAI_API_KEY, - }); - const openai = new OpenAIApi(configuration); - const response = await openai.deleteModel('curie:ft-acmeco-2021-03-03-21-44-20'); - response: | - { - "id": "curie:ft-acmeco-2021-03-03-21-44-20", - "object": "model", - "deleted": true - } - - /moderations: - post: - operationId: createModeration - tags: - - OpenAI - summary: Classifies if text violates OpenAI's Content Policy - requestBody: - required: true - content: - application/json: - schema: - $ref: '#/components/schemas/CreateModerationRequest' - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: '#/components/schemas/CreateModerationResponse' - x-oaiMeta: - name: Create moderation - group: moderations - path: create - examples: - curl: | - curl https://api.openai.com/v1/moderations \ - -H 'Content-Type: application/json' \ - -H 'Authorization: Bearer YOUR_API_KEY' \ - -d '{ - "input": "I want to kill them." - }' - python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.Moderation.create( - input="I want to kill them.", - ) - node.js: | - const { Configuration, OpenAIApi } = require("openai"); - const configuration = new Configuration({ - apiKey: process.env.OPENAI_API_KEY, - }); - const openai = new OpenAIApi(configuration); - const response = await openai.createModeration({ - input: "I want to kill them.", - }); - parameters: | - { - "input": "I want to kill them." - } - response: | - { - "id": "modr-5MWoLO", - "model": "text-moderation-001", - "results": [ - { - "categories": { - "hate": false, - "hate/threatening": true, - "self-harm": false, - "sexual": false, - "sexual/minors": false, - "violence": true, - "violence/graphic": false - }, - "category_scores": { - "hate": 0.22714105248451233, - "hate/threatening": 0.4132447838783264, - "self-harm": 0.005232391878962517, - "sexual": 0.01407341007143259, - "sexual/minors": 0.0038522258400917053, - "violence": 0.9223177433013916, - "violence/graphic": 0.036865197122097015 - }, - "flagged": true - } - ] - } - -components: - schemas: - ListEnginesResponse: - type: object - properties: - object: - type: string - data: - type: array - items: - $ref: '#/components/schemas/Engine' - required: - - object - - data - - ListModelsResponse: - type: object - properties: - object: - type: string - data: - type: array - items: - $ref: '#/components/schemas/Model' - required: - - object - - data - - DeleteModelResponse: - type: object - properties: - id: - type: string - object: - type: string - deleted: - type: boolean - required: - - id - - object - - deleted - - CreateCompletionRequest: - type: object - properties: - model: &model_configuration - description: ID of the model to use. You can use the [List models](/docs/api-reference/models/list) API to see all of your available models, or see our [Model overview](/docs/models/overview) for descriptions of them. - type: string - prompt: - description: &completions_prompt_description | - The prompt(s) to generate completions for, encoded as a string, array of strings, array of tokens, or array of token arrays. - - Note that <|endoftext|> is the document separator that the model sees during training, so if a prompt is not specified the model will generate as if from the beginning of a new document. - default: '<|endoftext|>' - nullable: true - oneOf: - - type: string - default: '' - example: "This is a test." - - type: array - items: - type: string - default: '' - example: "This is a test." - - type: array - minItems: 1 - items: - type: integer - example: "[1212, 318, 257, 1332, 13]" - - type: array - minItems: 1 - items: - type: array - minItems: 1 - items: - type: integer - example: "[[1212, 318, 257, 1332, 13]]" - suffix: - description: - The suffix that comes after a completion of inserted text. - default: null - nullable: true - type: string - example: "test." - max_tokens: - type: integer - minimum: 0 - default: 16 - example: 16 - nullable: true - description: &completions_max_tokens_description | - The maximum number of [tokens](/tokenizer) to generate in the completion. - - The token count of your prompt plus `max_tokens` cannot exceed the model's context length. Most models have a context length of 2048 tokens (except for the newest models, which support 4096). - temperature: - type: number - minimum: 0 - maximum: 2 - default: 1 - example: 1 - nullable: true - description: &completions_temperature_description | - What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. - - We generally recommend altering this or `top_p` but not both. - top_p: - type: number - minimum: 0 - maximum: 1 - default: 1 - example: 1 - nullable: true - description: &completions_top_p_description | - An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. - - We generally recommend altering this or `temperature` but not both. - n: - type: integer - minimum: 1 - maximum: 128 - default: 1 - example: 1 - nullable: true - description: &completions_completions_description | - How many completions to generate for each prompt. - - **Note:** Because this parameter generates many completions, it can quickly consume your token quota. Use carefully and ensure that you have reasonable settings for `max_tokens` and `stop`. - stream: - description: > - Whether to stream back partial progress. If set, tokens will be sent as data-only [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format) - as they become available, with the stream terminated by a `data: [DONE]` message. - type: boolean - nullable: true - default: false - logprobs: &completions_logprobs_configuration - type: integer - minimum: 0 - maximum: 5 - default: null - nullable: true - description: &completions_logprobs_description | - Include the log probabilities on the `logprobs` most likely tokens, as well the chosen tokens. For example, if `logprobs` is 5, the API will return a list of the 5 most likely tokens. The API will always return the `logprob` of the sampled token, so there may be up to `logprobs+1` elements in the response. - - The maximum value for `logprobs` is 5. If you need more than this, please contact us through our [Help center](https://help.openai.com) and describe your use case. - echo: - type: boolean - default: false - nullable: true - description: &completions_echo_description > - Echo back the prompt in addition to the completion - stop: - description: &completions_stop_description > - Up to 4 sequences where the API will stop generating further tokens. The returned text will not contain the stop sequence. - default: null - nullable: true - oneOf: - - type: string - default: <|endoftext|> - example: "\n" - nullable: true - - type: array - minItems: 1 - maxItems: 4 - items: - type: string - example: '["\n"]' - presence_penalty: - type: number - default: 0 - minimum: -2 - maximum: 2 - nullable: true - description: &completions_presence_penalty_description | - Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics. - - [See more information about frequency and presence penalties.](/docs/api-reference/parameter-details) - frequency_penalty: - type: number - default: 0 - minimum: -2 - maximum: 2 - nullable: true - description: &completions_frequency_penalty_description | - Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim. - - [See more information about frequency and presence penalties.](/docs/api-reference/parameter-details) - best_of: - type: integer - default: 1 - minimum: 0 - maximum: 20 - nullable: true - description: &completions_best_of_description | - Generates `best_of` completions server-side and returns the "best" (the one with the highest log probability per token). Results cannot be streamed. - - When used with `n`, `best_of` controls the number of candidate completions and `n` specifies how many to return – `best_of` must be greater than `n`. - - **Note:** Because this parameter generates many completions, it can quickly consume your token quota. Use carefully and ensure that you have reasonable settings for `max_tokens` and `stop`. - logit_bias: &completions_logit_bias - type: object - x-oaiTypeLabel: map - default: null - nullable: true - description: &completions_logit_bias_description | - Modify the likelihood of specified tokens appearing in the completion. - - Accepts a json object that maps tokens (specified by their token ID in the GPT tokenizer) to an associated bias value from -100 to 100. You can use this [tokenizer tool](/tokenizer?view=bpe) (which works for both GPT-2 and GPT-3) to convert text to token IDs. Mathematically, the bias is added to the logits generated by the model prior to sampling. The exact effect will vary per model, but values between -1 and 1 should decrease or increase likelihood of selection; values like -100 or 100 should result in a ban or exclusive selection of the relevant token. - - As an example, you can pass `{"50256": -100}` to prevent the <|endoftext|> token from being generated. - user: &end_user_param_configuration - type: string - example: user-1234 - description: | - A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. [Learn more](/docs/guides/safety-best-practices/end-user-ids). - required: - - model - - CreateCompletionResponse: - type: object - properties: - id: - type: string - object: - type: string - created: - type: integer - model: - type: string - choices: - type: array - items: - type: object - properties: - text: - type: string - index: - type: integer - logprobs: - type: object - nullable: true - properties: - tokens: - type: array - items: - type: string - token_logprobs: - type: array - items: - type: number - top_logprobs: - type: array - items: - type: object - text_offset: - type: array - items: - type: integer - finish_reason: - type: string - usage: - type: object - properties: - prompt_tokens: - type: integer - completion_tokens: - type: integer - total_tokens: - type: integer - required: - - prompt_tokens - - completion_tokens - - total_tokens - required: - - id - - object - - created - - model - - choices - - ChatCompletionRequestMessage: - type: object - properties: - role: - type: string - enum: ["system", "user", "assistant"] - description: The role of the author of this message. - content: - type: string - description: The contents of the message - name: - type: string - description: The name of the user in a multi-user chat - required: - - role - - content - - ChatCompletionResponseMessage: - type: object - properties: - role: - type: string - enum: ["system", "user", "assistant"] - description: The role of the author of this message. - content: - type: string - description: The contents of the message - required: - - role - - content - - CreateChatCompletionRequest: - type: object - properties: - model: - description: ID of the model to use. Currently, only `gpt-3.5-turbo` and `gpt-3.5-turbo-0301` are supported. - type: string - messages: - description: The messages to generate chat completions for, in the [chat format](/docs/guides/chat/introduction). - type: array - minItems: 1 - items: - $ref: '#/components/schemas/ChatCompletionRequestMessage' - temperature: - type: number - minimum: 0 - maximum: 2 - default: 1 - example: 1 - nullable: true - description: *completions_temperature_description - top_p: - type: number - minimum: 0 - maximum: 1 - default: 1 - example: 1 - nullable: true - description: *completions_top_p_description - n: - type: integer - minimum: 1 - maximum: 128 - default: 1 - example: 1 - nullable: true - description: How many chat completion choices to generate for each input message. - stream: - description: > - If set, partial message deltas will be sent, like in ChatGPT. Tokens will be sent as data-only [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format) - as they become available, with the stream terminated by a `data: [DONE]` message. - type: boolean - nullable: true - default: false - stop: - description: | - Up to 4 sequences where the API will stop generating further tokens. - default: null - oneOf: - - type: string - nullable: true - - type: array - minItems: 1 - maxItems: 4 - items: - type: string - max_tokens: - description: | - The maximum number of tokens allowed for the generated answer. By default, the number of tokens the model can return will be (4096 - prompt tokens). - default: inf - type: integer - presence_penalty: - type: number - default: 0 - minimum: -2 - maximum: 2 - nullable: true - description: *completions_presence_penalty_description - frequency_penalty: - type: number - default: 0 - minimum: -2 - maximum: 2 - nullable: true - description: *completions_frequency_penalty_description - logit_bias: - type: object - x-oaiTypeLabel: map - default: null - nullable: true - description: | - Modify the likelihood of specified tokens appearing in the completion. - - Accepts a json object that maps tokens (specified by their token ID in the tokenizer) to an associated bias value from -100 to 100. Mathematically, the bias is added to the logits generated by the model prior to sampling. The exact effect will vary per model, but values between -1 and 1 should decrease or increase likelihood of selection; values like -100 or 100 should result in a ban or exclusive selection of the relevant token. - user: *end_user_param_configuration - required: - - model - - messages - - CreateChatCompletionResponse: - type: object - properties: - id: - type: string - object: - type: string - created: - type: integer - model: - type: string - choices: - type: array - items: - type: object - properties: - index: - type: integer - message: - $ref: '#/components/schemas/ChatCompletionResponseMessage' - finish_reason: - type: string - usage: - type: object - properties: - prompt_tokens: - type: integer - completion_tokens: - type: integer - total_tokens: - type: integer - required: - - prompt_tokens - - completion_tokens - - total_tokens - required: - - id - - object - - created - - model - - choices - - CreateEditRequest: - type: object - properties: - model: - description: ID of the model to use. You can use the `text-davinci-edit-001` or `code-davinci-edit-001` model with this endpoint. - type: string - input: - description: - The input text to use as a starting point for the edit. - type: string - default: '' - nullable: true - example: "What day of the wek is it?" - instruction: - description: - The instruction that tells the model how to edit the prompt. - type: string - example: "Fix the spelling mistakes." - n: - type: integer - minimum: 1 - maximum: 20 - default: 1 - example: 1 - nullable: true - description: - How many edits to generate for the input and instruction. - temperature: - type: number - minimum: 0 - maximum: 2 - default: 1 - example: 1 - nullable: true - description: *completions_temperature_description - top_p: - type: number - minimum: 0 - maximum: 1 - default: 1 - example: 1 - nullable: true - description: *completions_top_p_description - required: - - model - - instruction - - CreateEditResponse: - type: object - properties: - object: - type: string - created: - type: integer - choices: - type: array - items: - type: object - properties: - text: - type: string - index: - type: integer - logprobs: - type: object - nullable: true - properties: - tokens: - type: array - items: - type: string - token_logprobs: - type: array - items: - type: number - top_logprobs: - type: array - items: - type: object - text_offset: - type: array - items: - type: integer - finish_reason: - type: string - usage: - type: object - properties: - prompt_tokens: - type: integer - completion_tokens: - type: integer - total_tokens: - type: integer - required: - - prompt_tokens - - completion_tokens - - total_tokens - required: - - object - - created - - choices - - usage - - CreateImageRequest: - type: object - properties: - prompt: - description: A text description of the desired image(s). The maximum length is 1000 characters. - type: string - example: "A cute baby sea otter" - n: &images_n - type: integer - minimum: 1 - maximum: 10 - default: 1 - example: 1 - nullable: true - description: The number of images to generate. Must be between 1 and 10. - size: &images_size - type: string - enum: ["256x256", "512x512", "1024x1024"] - default: "1024x1024" - example: "1024x1024" - nullable: true - description: The size of the generated images. Must be one of `256x256`, `512x512`, or `1024x1024`. - response_format: &images_response_format - type: string - enum: ["url", "b64_json"] - default: "url" - example: "url" - nullable: true - description: The format in which the generated images are returned. Must be one of `url` or `b64_json`. - user: *end_user_param_configuration - required: - - prompt - - ImagesResponse: - properties: - created: - type: integer - data: - type: array - items: - type: object - properties: - url: - type: string - b64_json: - type: string - required: - - created - - data - - CreateImageEditRequest: - type: object - properties: - image: - description: The image to edit. Must be a valid PNG file, less than 4MB, and square. If mask is not provided, image must have transparency, which will be used as the mask. - type: string - format: binary - mask: - description: An additional image whose fully transparent areas (e.g. where alpha is zero) indicate where `image` should be edited. Must be a valid PNG file, less than 4MB, and have the same dimensions as `image`. - type: string - format: binary - prompt: - description: A text description of the desired image(s). The maximum length is 1000 characters. - type: string - example: "A cute baby sea otter wearing a beret" - n: *images_n - size: *images_size - response_format: *images_response_format - user: *end_user_param_configuration - required: - - prompt - - image - - CreateImageVariationRequest: - type: object - properties: - image: - description: The image to use as the basis for the variation(s). Must be a valid PNG file, less than 4MB, and square. - type: string - format: binary - n: *images_n - size: *images_size - response_format: *images_response_format - user: *end_user_param_configuration - required: - - image - - CreateModerationRequest: - type: object - properties: - input: - description: The input text to classify - oneOf: - - type: string - default: '' - example: "I want to kill them." - - type: array - items: - type: string - default: '' - example: "I want to kill them." - model: - description: | - Two content moderations models are available: `text-moderation-stable` and `text-moderation-latest`. - - The default is `text-moderation-latest` which will be automatically upgraded over time. This ensures you are always using our most accurate model. If you use `text-moderation-stable`, we will provide advanced notice before updating the model. Accuracy of `text-moderation-stable` may be slightly lower than for `text-moderation-latest`. - type: string - nullable: false - default: "text-moderation-latest" - example: "text-moderation-stable" - required: - - input - - CreateModerationResponse: - type: object - properties: - id: - type: string - model: - type: string - results: - type: array - items: - type: object - properties: - flagged: - type: boolean - categories: - type: object - properties: - hate: - type: boolean - hate/threatening: - type: boolean - self-harm: - type: boolean - sexual: - type: boolean - sexual/minors: - type: boolean - violence: - type: boolean - violence/graphic: - type: boolean - required: - - hate - - hate/threatening - - self-harm - - sexual - - sexual/minors - - violence - - violence/graphic - category_scores: - type: object - properties: - hate: - type: number - hate/threatening: - type: number - self-harm: - type: number - sexual: - type: number - sexual/minors: - type: number - violence: - type: number - violence/graphic: - type: number - required: - - hate - - hate/threatening - - self-harm - - sexual - - sexual/minors - - violence - - violence/graphic - required: - - flagged - - categories - - category_scores - required: - - id - - model - - results - - CreateSearchRequest: - type: object - properties: - query: - description: Query to search against the documents. - type: string - example: "the president" - minLength: 1 - documents: - description: | - Up to 200 documents to search over, provided as a list of strings. - - The maximum document length (in tokens) is 2034 minus the number of tokens in the query. - - You should specify either `documents` or a `file`, but not both. - type: array - minItems: 1 - maxItems: 200 - items: - type: string - nullable: true - example: "['White House', 'hospital', 'school']" - file: - description: | - The ID of an uploaded file that contains documents to search over. - - You should specify either `documents` or a `file`, but not both. - type: string - nullable: true - max_rerank: - description: | - The maximum number of documents to be re-ranked and returned by search. - - This flag only takes effect when `file` is set. - type: integer - minimum: 1 - default: 200 - nullable: true - return_metadata: &return_metadata_configuration - description: | - A special boolean flag for showing metadata. If set to `true`, each document entry in the returned JSON will contain a "metadata" field. - - This flag only takes effect when `file` is set. - type: boolean - default: false - nullable: true - user: *end_user_param_configuration - required: - - query - - CreateSearchResponse: - type: object - properties: - object: - type: string - model: - type: string - data: - type: array - items: - type: object - properties: - object: - type: string - document: - type: integer - score: - type: number - - ListFilesResponse: - type: object - properties: - object: - type: string - data: - type: array - items: - $ref: '#/components/schemas/OpenAIFile' - required: - - object - - data - - CreateFileRequest: - type: object - additionalProperties: false - properties: - file: - description: | - Name of the [JSON Lines](https://jsonlines.readthedocs.io/en/latest/) file to be uploaded. - - If the `purpose` is set to "fine-tune", each line is a JSON record with "prompt" and "completion" fields representing your [training examples](/docs/guides/fine-tuning/prepare-training-data). - type: string - format: binary - purpose: - description: | - The intended purpose of the uploaded documents. - - Use "fine-tune" for [Fine-tuning](/docs/api-reference/fine-tunes). This allows us to validate the format of the uploaded file. - - type: string - required: - - file - - purpose - - DeleteFileResponse: - type: object - properties: - id: - type: string - object: - type: string - deleted: - type: boolean - required: - - id - - object - - deleted - - CreateAnswerRequest: - type: object - additionalProperties: false - properties: - model: - description: ID of the model to use for completion. You can select one of `ada`, `babbage`, `curie`, or `davinci`. - type: string - question: - description: Question to get answered. - type: string - minLength: 1 - example: "What is the capital of Japan?" - examples: - description: List of (question, answer) pairs that will help steer the model towards the tone and answer format you'd like. We recommend adding 2 to 3 examples. - type: array - minItems: 1 - maxItems: 200 - items: - type: array - minItems: 2 - maxItems: 2 - items: - type: string - minLength: 1 - example: "[['What is the capital of Canada?', 'Ottawa'], ['Which province is Ottawa in?', 'Ontario']]" - examples_context: - description: A text snippet containing the contextual information used to generate the answers for the `examples` you provide. - type: string - example: "Ottawa, Canada's capital, is located in the east of southern Ontario, near the city of Montréal and the U.S. border." - documents: - description: | - List of documents from which the answer for the input `question` should be derived. If this is an empty list, the question will be answered based on the question-answer examples. - - You should specify either `documents` or a `file`, but not both. - type: array - maxItems: 200 - items: - type: string - example: "['Japan is an island country in East Asia, located in the northwest Pacific Ocean.', 'Tokyo is the capital and most populous prefecture of Japan.']" - nullable: true - file: - description: | - The ID of an uploaded file that contains documents to search over. See [upload file](/docs/api-reference/files/upload) for how to upload a file of the desired format and purpose. - - You should specify either `documents` or a `file`, but not both. - type: string - nullable: true - search_model: &search_model_configuration - description: ID of the model to use for [Search](/docs/api-reference/searches/create). You can select one of `ada`, `babbage`, `curie`, or `davinci`. - type: string - default: ada - nullable: true - max_rerank: - description: The maximum number of documents to be ranked by [Search](/docs/api-reference/searches/create) when using `file`. Setting it to a higher value leads to improved accuracy but with increased latency and cost. - type: integer - default: 200 - nullable: true - temperature: - description: What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. - type: number - default: 0 - nullable: true - logprobs: &context_completions_logprobs_configuration - type: integer - minimum: 0 - maximum: 5 - default: null - nullable: true - description: | - Include the log probabilities on the `logprobs` most likely tokens, as well the chosen tokens. For example, if `logprobs` is 5, the API will return a list of the 5 most likely tokens. The API will always return the `logprob` of the sampled token, so there may be up to `logprobs+1` elements in the response. - - The maximum value for `logprobs` is 5. If you need more than this, please contact us through our [Help center](https://help.openai.com) and describe your use case. - - When `logprobs` is set, `completion` will be automatically added into `expand` to get the logprobs. - max_tokens: - description: The maximum number of tokens allowed for the generated answer - type: integer - default: 16 - nullable: true - stop: - description: *completions_stop_description - default: null - oneOf: - - type: string - default: <|endoftext|> - example: "\n" - - type: array - minItems: 1 - maxItems: 4 - items: - type: string - example: '["\n"]' - nullable: true - n: - description: How many answers to generate for each question. - type: integer - minimum: 1 - maximum: 10 - default: 1 - nullable: true - logit_bias: *completions_logit_bias - return_metadata: *return_metadata_configuration - return_prompt: &return_prompt_configuration - description: If set to `true`, the returned JSON will include a "prompt" field containing the final prompt that was used to request a completion. This is mainly useful for debugging purposes. - type: boolean - default: false - nullable: true - expand: &expand_configuration - description: If an object name is in the list, we provide the full information of the object; otherwise, we only provide the object ID. Currently we support `completion` and `file` objects for expansion. - type: array - items: {} - nullable: true - default: [] - user: *end_user_param_configuration - required: - - model - - question - - examples - - examples_context - - CreateAnswerResponse: - type: object - properties: - object: - type: string - model: - type: string - search_model: - type: string - completion: - type: string - answers: - type: array - items: - type: string - selected_documents: - type: array - items: - type: object - properties: - document: - type: integer - text: - type: string - - CreateClassificationRequest: - type: object - additionalProperties: false - properties: - model: *model_configuration - query: - description: Query to be classified. - type: string - minLength: 1 - example: "The plot is not very attractive." - examples: - description: | - A list of examples with labels, in the following format: - - `[["The movie is so interesting.", "Positive"], ["It is quite boring.", "Negative"], ...]` - - All the label strings will be normalized to be capitalized. - - You should specify either `examples` or `file`, but not both. - type: array - minItems: 2 - maxItems: 200 - items: - type: array - minItems: 2 - maxItems: 2 - items: - type: string - minLength: 1 - example: "[['Do not see this film.', 'Negative'], ['Smart, provocative and blisteringly funny.', 'Positive']]" - nullable: true - file: - description: | - The ID of the uploaded file that contains training examples. See [upload file](/docs/api-reference/files/upload) for how to upload a file of the desired format and purpose. - - You should specify either `examples` or `file`, but not both. - type: string - nullable: true - labels: - description: The set of categories being classified. If not specified, candidate labels will be automatically collected from the examples you provide. All the label strings will be normalized to be capitalized. - type: array - minItems: 2 - maxItems: 200 - default: null - items: - type: string - example: ["Positive", "Negative"] - nullable: true - search_model: *search_model_configuration - temperature: - description: - What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. - type: number - minimum: 0 - maximum: 2 - default: 0 - nullable: true - example: 0 - logprobs: *context_completions_logprobs_configuration - max_examples: - description: The maximum number of examples to be ranked by [Search](/docs/api-reference/searches/create) when using `file`. Setting it to a higher value leads to improved accuracy but with increased latency and cost. - type: integer - default: 200 - nullable: true - logit_bias: *completions_logit_bias - return_prompt: *return_prompt_configuration - return_metadata: *return_metadata_configuration - expand: *expand_configuration - user: *end_user_param_configuration - required: - - model - - query - - CreateClassificationResponse: - type: object - properties: - object: - type: string - model: - type: string - search_model: - type: string - completion: - type: string - label: - type: string - selected_examples: - type: array - items: - type: object - properties: - document: - type: integer - text: - type: string - label: - type: string - - CreateFineTuneRequest: - type: object - properties: - training_file: - description: | - The ID of an uploaded file that contains training data. - - See [upload file](/docs/api-reference/files/upload) for how to upload a file. - - Your dataset must be formatted as a JSONL file, where each training - example is a JSON object with the keys "prompt" and "completion". - Additionally, you must upload your file with the purpose `fine-tune`. - - See the [fine-tuning guide](/docs/guides/fine-tuning/creating-training-data) for more details. - type: string - example: "file-ajSREls59WBbvgSzJSVWxMCB" - validation_file: - description: | - The ID of an uploaded file that contains validation data. - - If you provide this file, the data is used to generate validation - metrics periodically during fine-tuning. These metrics can be viewed in - the [fine-tuning results file](/docs/guides/fine-tuning/analyzing-your-fine-tuned-model). - Your train and validation data should be mutually exclusive. - - Your dataset must be formatted as a JSONL file, where each validation - example is a JSON object with the keys "prompt" and "completion". - Additionally, you must upload your file with the purpose `fine-tune`. - - See the [fine-tuning guide](/docs/guides/fine-tuning/creating-training-data) for more details. - type: string - nullable: true - example: "file-XjSREls59WBbvgSzJSVWxMCa" - model: - description: | - The name of the base model to fine-tune. You can select one of "ada", - "babbage", "curie", "davinci", or a fine-tuned model created after 2022-04-21. - To learn more about these models, see the - [Models](https://platform.openai.com/docs/models) documentation. - default: "curie" - type: string - nullable: true - n_epochs: - description: | - The number of epochs to train the model for. An epoch refers to one - full cycle through the training dataset. - default: 4 - type: integer - nullable: true - batch_size: - description: | - The batch size to use for training. The batch size is the number of - training examples used to train a single forward and backward pass. - - By default, the batch size will be dynamically configured to be - ~0.2% of the number of examples in the training set, capped at 256 - - in general, we've found that larger batch sizes tend to work better - for larger datasets. - default: null - type: integer - nullable: true - learning_rate_multiplier: - description: | - The learning rate multiplier to use for training. - The fine-tuning learning rate is the original learning rate used for - pretraining multiplied by this value. - - By default, the learning rate multiplier is the 0.05, 0.1, or 0.2 - depending on final `batch_size` (larger learning rates tend to - perform better with larger batch sizes). We recommend experimenting - with values in the range 0.02 to 0.2 to see what produces the best - results. - default: null - type: number - nullable: true - prompt_loss_weight: - description: | - The weight to use for loss on the prompt tokens. This controls how - much the model tries to learn to generate the prompt (as compared - to the completion which always has a weight of 1.0), and can add - a stabilizing effect to training when completions are short. - - If prompts are extremely long (relative to completions), it may make - sense to reduce this weight so as to avoid over-prioritizing - learning the prompt. - default: 0.01 - type: number - nullable: true - compute_classification_metrics: - description: | - If set, we calculate classification-specific metrics such as accuracy - and F-1 score using the validation set at the end of every epoch. - These metrics can be viewed in the [results file](/docs/guides/fine-tuning/analyzing-your-fine-tuned-model). - - In order to compute classification metrics, you must provide a - `validation_file`. Additionally, you must - specify `classification_n_classes` for multiclass classification or - `classification_positive_class` for binary classification. - type: boolean - default: false - nullable: true - classification_n_classes: - description: | - The number of classes in a classification task. - - This parameter is required for multiclass classification. - type: integer - default: null - nullable: true - classification_positive_class: - description: | - The positive class in binary classification. - - This parameter is needed to generate precision, recall, and F1 - metrics when doing binary classification. - type: string - default: null - nullable: true - classification_betas: - description: | - If this is provided, we calculate F-beta scores at the specified - beta values. The F-beta score is a generalization of F-1 score. - This is only used for binary classification. - - With a beta of 1 (i.e. the F-1 score), precision and recall are - given the same weight. A larger beta score puts more weight on - recall and less on precision. A smaller beta score puts more weight - on precision and less on recall. - type: array - items: - type: number - example: [0.6, 1, 1.5, 2] - default: null - nullable: true - suffix: - description: | - A string of up to 40 characters that will be added to your fine-tuned model name. - - For example, a `suffix` of "custom-model-name" would produce a model name like `ada:ft-your-org:custom-model-name-2022-02-15-04-21-04`. - type: string - minLength: 1 - maxLength: 40 - default: null - nullable: true - required: - - training_file - - ListFineTunesResponse: - type: object - properties: - object: - type: string - data: - type: array - items: - $ref: '#/components/schemas/FineTune' - required: - - object - - data - - ListFineTuneEventsResponse: - type: object - properties: - object: - type: string - data: - type: array - items: - $ref: '#/components/schemas/FineTuneEvent' - required: - - object - - data - - CreateEmbeddingRequest: - type: object - additionalProperties: false - properties: - model: *model_configuration - input: - description: | - Input text to get embeddings for, encoded as a string or array of tokens. To get embeddings for multiple inputs in a single request, pass an array of strings or array of token arrays. Each input must not exceed 8192 tokens in length. - example: "The quick brown fox jumped over the lazy dog" - oneOf: - - type: string - default: '' - example: "This is a test." - - type: array - items: - type: string - default: '' - example: "This is a test." - - type: array - minItems: 1 - items: - type: integer - example: "[1212, 318, 257, 1332, 13]" - - type: array - minItems: 1 - items: - type: array - minItems: 1 - items: - type: integer - example: "[[1212, 318, 257, 1332, 13]]" - user: *end_user_param_configuration - required: - - model - - input - - CreateEmbeddingResponse: - type: object - properties: - object: - type: string - model: - type: string - data: - type: array - items: - type: object - properties: - index: - type: integer - object: - type: string - embedding: - type: array - items: - type: number - required: - - index - - object - - embedding - usage: - type: object - properties: - prompt_tokens: - type: integer - total_tokens: - type: integer - required: - - prompt_tokens - - total_tokens - required: - - object - - model - - data - - usage - - CreateTranscriptionRequest: - type: object - additionalProperties: false - properties: - file: - description: | - The audio file to transcribe, in one of these formats: mp3, mp4, mpeg, mpga, m4a, wav, or webm. - type: string - format: binary - model: - description: | - ID of the model to use. Only `whisper-1` is currently available. - type: string - prompt: - description: | - An optional text to guide the model's style or continue a previous audio segment. The [prompt](/docs/guides/speech-to-text/prompting) should match the audio language. - type: string - response_format: - description: | - The format of the transcript output, in one of these options: json, text, srt, verbose_json, or vtt. - type: string - default: json - temperature: - description: | - The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use [log probability](https://en.wikipedia.org/wiki/Log_probability) to automatically increase the temperature until certain thresholds are hit. - type: number - default: 0 - language: - description: | - The language of the input audio. Supplying the input language in [ISO-639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) format will improve accuracy and latency. - type: string - required: - - file - - model - - # Note: This does not currently support the non-default response format types. - CreateTranscriptionResponse: - type: object - properties: - text: - type: string - required: - - text - - CreateTranslationRequest: - type: object - additionalProperties: false - properties: - file: - description: | - The audio file to translate, in one of these formats: mp3, mp4, mpeg, mpga, m4a, wav, or webm. - type: string - format: binary - model: - description: | - ID of the model to use. Only `whisper-1` is currently available. - type: string - prompt: - description: | - An optional text to guide the model's style or continue a previous audio segment. The [prompt](/docs/guides/speech-to-text/prompting) should be in English. - type: string - response_format: - description: | - The format of the transcript output, in one of these options: json, text, srt, verbose_json, or vtt. - type: string - default: json - temperature: - description: | - The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use [log probability](https://en.wikipedia.org/wiki/Log_probability) to automatically increase the temperature until certain thresholds are hit. - type: number - default: 0 - required: - - file - - model - - # Note: This does not currently support the non-default response format types. - CreateTranslationResponse: - type: object - properties: - text: - type: string - required: - - text - - Engine: - title: Engine - properties: - id: - type: string - object: - type: string - created: - type: integer - nullable: true - ready: - type: boolean - required: - - id - - object - - created - - ready - - Model: - title: Model - properties: - id: - type: string - object: - type: string - created: - type: integer - owned_by: - type: string - required: - - id - - object - - created - - owned_by - - OpenAIFile: - title: OpenAIFile - properties: - id: - type: string - object: - type: string - bytes: - type: integer - created_at: - type: integer - filename: - type: string - purpose: - type: string - status: - type: string - status_details: - type: object - nullable: true - required: - - id - - object - - bytes - - created_at - - filename - - purpose - - FineTune: - title: FineTune - properties: - id: - type: string - object: - type: string - created_at: - type: integer - updated_at: - type: integer - model: - type: string - fine_tuned_model: - type: string - nullable: true - organization_id: - type: string - status: - type: string - hyperparams: - type: object - training_files: - type: array - items: - $ref: '#/components/schemas/OpenAIFile' - validation_files: - type: array - items: - $ref: '#/components/schemas/OpenAIFile' - result_files: - type: array - items: - $ref: '#/components/schemas/OpenAIFile' - events: - type: array - items: - $ref: '#/components/schemas/FineTuneEvent' - required: - - id - - object - - created_at - - updated_at - - model - - fine_tuned_model - - organization_id - - status - - hyperparams - - training_files - - validation_files - - result_files - - FineTuneEvent: - title: FineTuneEvent - properties: - object: - type: string - created_at: - type: integer - level: - type: string - message: - type: string - required: - - object - - created_at - - level - - message - -x-oaiMeta: - groups: - - id: models - title: Models - description: | - List and describe the various models available in the API. You can refer to the [Models](/docs/models) documentation to understand what models are available and the differences between them. - - id: completions - title: Completions - description: | - Given a prompt, the model will return one or more predicted completions, and can also return the probabilities of alternative tokens at each position. - - id: chat - title: Chat - description: | - Given a chat conversation, the model will return a chat completion response. - - id: edits - title: Edits - description: | - Given a prompt and an instruction, the model will return an edited version of the prompt. - - id: images - title: Images - description: | - Given a prompt and/or an input image, the model will generate a new image. - - Related guide: [Image generation](/docs/guides/images) - - id: embeddings - title: Embeddings - description: | - Get a vector representation of a given input that can be easily consumed by machine learning models and algorithms. - - Related guide: [Embeddings](/docs/guides/embeddings) - - id: audio - title: Audio - description: | - Learn how to turn audio into text. - - Related guide: [Speech to text](/docs/guides/speech-to-text) - - id: files - title: Files - description: | - Files are used to upload documents that can be used with features like [Fine-tuning](/docs/api-reference/fine-tunes). - - id: fine-tunes - title: Fine-tunes - description: | - Manage fine-tuning jobs to tailor a model to your specific training data. - - Related guide: [Fine-tune models](/docs/guides/fine-tuning) - - id: moderations - title: Moderations - description: | - Given a input text, outputs if the model classifies it as violating OpenAI's content policy. - - Related guide: [Moderations](/docs/guides/moderation) - - id: searches - title: Searches - warning: - title: This endpoint is deprecated and will be removed on December 3rd, 2022 - message: We’ve developed new methods with better performance. [Learn more](https://help.openai.com/en/articles/6272952-search-transition-guide). - description: | - Given a query and a set of documents or labels, the model ranks each document based on its semantic similarity to the provided query. - - Related guide: [Search](/docs/guides/search) - - id: classifications - title: Classifications - warning: - title: This endpoint is deprecated and will be removed on December 3rd, 2022 - message: We’ve developed new methods with better performance. [Learn more](https://help.openai.com/en/articles/6272941-classifications-transition-guide). - description: | - Given a query and a set of labeled examples, the model will predict the most likely label for the query. Useful as a drop-in replacement for any ML classification or text-to-label task. - - Related guide: [Classification](/docs/guides/classifications) - - id: answers - title: Answers - warning: - title: This endpoint is deprecated and will be removed on December 3rd, 2022 - message: We’ve developed new methods with better performance. [Learn more](https://help.openai.com/en/articles/6233728-answers-transition-guide). - description: | - Given a question, a set of documents, and some examples, the API generates an answer to the question based on the information in the set of documents. This is useful for question-answering applications on sources of truth, like company documentation or a knowledge base. - - Related guide: [Question answering](/docs/guides/answers) - - id: engines - title: Engines - description: These endpoints describe and provide access to the various engines available in the API. - warning: - title: The Engines endpoints are deprecated. - message: Please use their replacement, [Models](/docs/api-reference/models), instead. [Learn more](https://help.openai.com/TODO). diff --git a/docs/extras/use_cases/apis/openapi.ipynb b/docs/extras/use_cases/apis/openapi.ipynb deleted file mode 100644 index 625a5f2414..0000000000 --- a/docs/extras/use_cases/apis/openapi.ipynb +++ /dev/null @@ -1,583 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "9fcaa37f", - "metadata": {}, - "source": [ - "# OpenAPI chain\n", - "\n", - "This notebook shows an example of using an OpenAPI chain to call an endpoint in natural language, and get back a response in natural language." - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "id": "efa6909f", - "metadata": {}, - "outputs": [], - "source": [ - "from langchain.tools import OpenAPISpec, APIOperation\n", - "from langchain.chains import OpenAPIEndpointChain\n", - "from langchain.requests import Requests\n", - "from langchain.llms import OpenAI" - ] - }, - { - "cell_type": "markdown", - "id": "71e38c6c", - "metadata": {}, - "source": [ - "## Load the spec\n", - "\n", - "Load a wrapper of the spec (so we can work with it more easily). You can load from a url or from a local file." - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "id": "0831271b", - "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "Attempting to load an OpenAPI 3.0.1 spec. This may result in degraded performance. Convert your OpenAPI spec to 3.1.* spec for better support.\n" - ] - } - ], - "source": [ - "spec = OpenAPISpec.from_url(\n", - " \"https://www.klarna.com/us/shopping/public/openai/v0/api-docs/\"\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "id": "189dd506", - "metadata": {}, - "outputs": [], - "source": [ - "# Alternative loading from file\n", - "# spec = OpenAPISpec.from_file(\"openai_openapi.yaml\")" - ] - }, - { - "cell_type": "markdown", - "id": "f7093582", - "metadata": {}, - "source": [ - "## Select the Operation\n", - "\n", - "In order to provide a focused on modular chain, we create a chain specifically only for one of the endpoints. Here we get an API operation from a specified endpoint and method." - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "id": "157494b9", - "metadata": {}, - "outputs": [], - "source": [ - "operation = APIOperation.from_openapi_spec(spec, \"/public/openai/v0/products\", \"get\")" - ] - }, - { - "cell_type": "markdown", - "id": "e3ab1c5c", - "metadata": {}, - "source": [ - "## Construct the chain\n", - "\n", - "We can now construct a chain to interact with it. In order to construct such a chain, we will pass in:\n", - "\n", - "1. The operation endpoint\n", - "2. A requests wrapper (can be used to handle authentication, etc)\n", - "3. The LLM to use to interact with it" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "id": "788a7cef", - "metadata": {}, - "outputs": [], - "source": [ - "llm = OpenAI() # Load a Language Model" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "id": "c5f27406", - "metadata": {}, - "outputs": [], - "source": [ - "chain = OpenAPIEndpointChain.from_api_operation(\n", - " operation,\n", - " llm,\n", - " requests=Requests(),\n", - " verbose=True,\n", - " return_intermediate_steps=True, # Return request and response text\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "id": "23652053", - "metadata": { - "scrolled": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "\n", - "\u001b[1m> Entering new OpenAPIEndpointChain chain...\u001b[0m\n", - "\n", - "\n", - "\u001b[1m> Entering new APIRequesterChain chain...\u001b[0m\n", - "Prompt after formatting:\n", - "\u001b[32;1m\u001b[1;3mYou are a helpful AI Assistant. Please provide JSON arguments to agentFunc() based on the user's instructions.\n", - "\n", - "API_SCHEMA: ```typescript\n", - "/* API for fetching Klarna product information */\n", - "type productsUsingGET = (_: {\n", - "/* A precise query that matches one very small category or product that needs to be searched for to find the products the user is looking for. If the user explicitly stated what they want, use that as a query. The query is as specific as possible to the product name or category mentioned by the user in its singular form, and don't contain any clarifiers like latest, newest, cheapest, budget, premium, expensive or similar. The query is always taken from the latest topic, if there is a new topic a new query is started. */\n", - "\t\tq: string,\n", - "/* number of products returned */\n", - "\t\tsize?: number,\n", - "/* (Optional) Minimum price in local currency for the product searched for. Either explicitly stated by the user or implicitly inferred from a combination of the user's request and the kind of product searched for. */\n", - "\t\tmin_price?: number,\n", - "/* (Optional) Maximum price in local currency for the product searched for. Either explicitly stated by the user or implicitly inferred from a combination of the user's request and the kind of product searched for. */\n", - "\t\tmax_price?: number,\n", - "}) => any;\n", - "```\n", - "\n", - "USER_INSTRUCTIONS: \"whats the most expensive shirt?\"\n", - "\n", - "Your arguments must be plain json provided in a markdown block:\n", - "\n", - "ARGS: ```json\n", - "{valid json conforming to API_SCHEMA}\n", - "```\n", - "\n", - "Example\n", - "-----\n", - "\n", - "ARGS: ```json\n", - "{\"foo\": \"bar\", \"baz\": {\"qux\": \"quux\"}}\n", - "```\n", - "\n", - "The block must be no more than 1 line long, and all arguments must be valid JSON. All string arguments must be wrapped in double quotes.\n", - "You MUST strictly comply to the types indicated by the provided schema, including all required args.\n", - "\n", - "If you don't have sufficient information to call the function due to things like requiring specific uuid's, you can reply with the following message:\n", - "\n", - "Message: ```text\n", - "Concise response requesting the additional information that would make calling the function successful.\n", - "```\n", - "\n", - "Begin\n", - "-----\n", - "ARGS:\n", - "\u001b[0m\n", - "\n", - "\u001b[1m> Finished chain.\u001b[0m\n", - "\u001b[32;1m\u001b[1;3m{\"q\": \"shirt\", \"size\": 1, \"max_price\": null}\u001b[0m\n", - "\u001b[36;1m\u001b[1;3m{\"products\":[{\"name\":\"Burberry Check Poplin Shirt\",\"url\":\"https://www.klarna.com/us/shopping/pl/cl10001/3201810981/Clothing/Burberry-Check-Poplin-Shirt/?utm_source=openai&ref-site=openai_plugin\",\"price\":\"$360.00\",\"attributes\":[\"Material:Cotton\",\"Target Group:Man\",\"Color:Gray,Blue,Beige\",\"Properties:Pockets\",\"Pattern:Checkered\"]}]}\u001b[0m\n", - "\n", - "\n", - "\u001b[1m> Entering new APIResponderChain chain...\u001b[0m\n", - "Prompt after formatting:\n", - "\u001b[32;1m\u001b[1;3mYou are a helpful AI assistant trained to answer user queries from API responses.\n", - "You attempted to call an API, which resulted in:\n", - "API_RESPONSE: {\"products\":[{\"name\":\"Burberry Check Poplin Shirt\",\"url\":\"https://www.klarna.com/us/shopping/pl/cl10001/3201810981/Clothing/Burberry-Check-Poplin-Shirt/?utm_source=openai&ref-site=openai_plugin\",\"price\":\"$360.00\",\"attributes\":[\"Material:Cotton\",\"Target Group:Man\",\"Color:Gray,Blue,Beige\",\"Properties:Pockets\",\"Pattern:Checkered\"]}]}\n", - "\n", - "USER_COMMENT: \"whats the most expensive shirt?\"\n", - "\n", - "\n", - "If the API_RESPONSE can answer the USER_COMMENT respond with the following markdown json block:\n", - "Response: ```json\n", - "{\"response\": \"Human-understandable synthesis of the API_RESPONSE\"}\n", - "```\n", - "\n", - "Otherwise respond with the following markdown json block:\n", - "Response Error: ```json\n", - "{\"response\": \"What you did and a concise statement of the resulting error. If it can be easily fixed, provide a suggestion.\"}\n", - "```\n", - "\n", - "You MUST respond as a markdown json code block. The person you are responding to CANNOT see the API_RESPONSE, so if there is any relevant information there you must include it in your response.\n", - "\n", - "Begin:\n", - "---\n", - "\u001b[0m\n", - "\n", - "\u001b[1m> Finished chain.\u001b[0m\n", - "\u001b[33;1m\u001b[1;3mThe most expensive shirt in the API response is the Burberry Check Poplin Shirt, which costs $360.00.\u001b[0m\n", - "\n", - "\u001b[1m> Finished chain.\u001b[0m\n" - ] - } - ], - "source": [ - "output = chain(\"whats the most expensive shirt?\")" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "id": "c000295e", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'request_args': '{\"q\": \"shirt\", \"size\": 1, \"max_price\": null}',\n", - " 'response_text': '{\"products\":[{\"name\":\"Burberry Check Poplin Shirt\",\"url\":\"https://www.klarna.com/us/shopping/pl/cl10001/3201810981/Clothing/Burberry-Check-Poplin-Shirt/?utm_source=openai&ref-site=openai_plugin\",\"price\":\"$360.00\",\"attributes\":[\"Material:Cotton\",\"Target Group:Man\",\"Color:Gray,Blue,Beige\",\"Properties:Pockets\",\"Pattern:Checkered\"]}]}'}" - ] - }, - "execution_count": 8, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# View intermediate steps\n", - "output[\"intermediate_steps\"]" - ] - }, - { - "cell_type": "markdown", - "id": "092bdb4d", - "metadata": {}, - "source": [ - "## Return raw response\n", - "\n", - "We can also run this chain without synthesizing the response. This will have the effect of just returning the raw API output." - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "id": "4dff3849", - "metadata": {}, - "outputs": [], - "source": [ - "chain = OpenAPIEndpointChain.from_api_operation(\n", - " operation,\n", - " llm,\n", - " requests=Requests(),\n", - " verbose=True,\n", - " return_intermediate_steps=True, # Return request and response text\n", - " raw_response=True, # Return raw response\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "id": "762499a9", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "\n", - "\u001b[1m> Entering new OpenAPIEndpointChain chain...\u001b[0m\n", - "\n", - "\n", - "\u001b[1m> Entering new APIRequesterChain chain...\u001b[0m\n", - "Prompt after formatting:\n", - "\u001b[32;1m\u001b[1;3mYou are a helpful AI Assistant. Please provide JSON arguments to agentFunc() based on the user's instructions.\n", - "\n", - "API_SCHEMA: ```typescript\n", - "/* API for fetching Klarna product information */\n", - "type productsUsingGET = (_: {\n", - "/* A precise query that matches one very small category or product that needs to be searched for to find the products the user is looking for. If the user explicitly stated what they want, use that as a query. The query is as specific as possible to the product name or category mentioned by the user in its singular form, and don't contain any clarifiers like latest, newest, cheapest, budget, premium, expensive or similar. The query is always taken from the latest topic, if there is a new topic a new query is started. */\n", - "\t\tq: string,\n", - "/* number of products returned */\n", - "\t\tsize?: number,\n", - "/* (Optional) Minimum price in local currency for the product searched for. Either explicitly stated by the user or implicitly inferred from a combination of the user's request and the kind of product searched for. */\n", - "\t\tmin_price?: number,\n", - "/* (Optional) Maximum price in local currency for the product searched for. Either explicitly stated by the user or implicitly inferred from a combination of the user's request and the kind of product searched for. */\n", - "\t\tmax_price?: number,\n", - "}) => any;\n", - "```\n", - "\n", - "USER_INSTRUCTIONS: \"whats the most expensive shirt?\"\n", - "\n", - "Your arguments must be plain json provided in a markdown block:\n", - "\n", - "ARGS: ```json\n", - "{valid json conforming to API_SCHEMA}\n", - "```\n", - "\n", - "Example\n", - "-----\n", - "\n", - "ARGS: ```json\n", - "{\"foo\": \"bar\", \"baz\": {\"qux\": \"quux\"}}\n", - "```\n", - "\n", - "The block must be no more than 1 line long, and all arguments must be valid JSON. All string arguments must be wrapped in double quotes.\n", - "You MUST strictly comply to the types indicated by the provided schema, including all required args.\n", - "\n", - "If you don't have sufficient information to call the function due to things like requiring specific uuid's, you can reply with the following message:\n", - "\n", - "Message: ```text\n", - "Concise response requesting the additional information that would make calling the function successful.\n", - "```\n", - "\n", - "Begin\n", - "-----\n", - "ARGS:\n", - "\u001b[0m\n", - "\n", - "\u001b[1m> Finished chain.\u001b[0m\n", - "\u001b[32;1m\u001b[1;3m{\"q\": \"shirt\", \"max_price\": null}\u001b[0m\n", - "\u001b[36;1m\u001b[1;3m{\"products\":[{\"name\":\"Burberry Check Poplin Shirt\",\"url\":\"https://www.klarna.com/us/shopping/pl/cl10001/3201810981/Clothing/Burberry-Check-Poplin-Shirt/?utm_source=openai&ref-site=openai_plugin\",\"price\":\"$360.00\",\"attributes\":[\"Material:Cotton\",\"Target Group:Man\",\"Color:Gray,Blue,Beige\",\"Properties:Pockets\",\"Pattern:Checkered\"]},{\"name\":\"Burberry Vintage Check Cotton Shirt - Beige\",\"url\":\"https://www.klarna.com/us/shopping/pl/cl359/3200280807/Children-s-Clothing/Burberry-Vintage-Check-Cotton-Shirt-Beige/?utm_source=openai&ref-site=openai_plugin\",\"price\":\"$229.02\",\"attributes\":[\"Material:Cotton,Elastane\",\"Color:Beige\",\"Model:Boy\",\"Pattern:Checkered\"]},{\"name\":\"Burberry Vintage Check Stretch Cotton Twill Shirt\",\"url\":\"https://www.klarna.com/us/shopping/pl/cl10001/3202342515/Clothing/Burberry-Vintage-Check-Stretch-Cotton-Twill-Shirt/?utm_source=openai&ref-site=openai_plugin\",\"price\":\"$309.99\",\"attributes\":[\"Material:Elastane/Lycra/Spandex,Cotton\",\"Target Group:Woman\",\"Color:Beige\",\"Properties:Stretch\",\"Pattern:Checkered\"]},{\"name\":\"Burberry Somerton Check Shirt - Camel\",\"url\":\"https://www.klarna.com/us/shopping/pl/cl10001/3201112728/Clothing/Burberry-Somerton-Check-Shirt-Camel/?utm_source=openai&ref-site=openai_plugin\",\"price\":\"$450.00\",\"attributes\":[\"Material:Elastane/Lycra/Spandex,Cotton\",\"Target Group:Man\",\"Color:Beige\"]},{\"name\":\"Magellan Outdoors Laguna Madre Solid Short Sleeve Fishing Shirt\",\"url\":\"https://www.klarna.com/us/shopping/pl/cl10001/3203102142/Clothing/Magellan-Outdoors-Laguna-Madre-Solid-Short-Sleeve-Fishing-Shirt/?utm_source=openai&ref-site=openai_plugin\",\"price\":\"$19.99\",\"attributes\":[\"Material:Polyester,Nylon\",\"Target Group:Man\",\"Color:Red,Pink,White,Blue,Purple,Beige,Black,Green\",\"Properties:Pockets\",\"Pattern:Solid Color\"]}]}\u001b[0m\n", - "\n", - "\u001b[1m> Finished chain.\u001b[0m\n" - ] - } - ], - "source": [ - "output = chain(\"whats the most expensive shirt?\")" - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "id": "4afc021a", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'instructions': 'whats the most expensive shirt?',\n", - " 'output': '{\"products\":[{\"name\":\"Burberry Check Poplin Shirt\",\"url\":\"https://www.klarna.com/us/shopping/pl/cl10001/3201810981/Clothing/Burberry-Check-Poplin-Shirt/?utm_source=openai&ref-site=openai_plugin\",\"price\":\"$360.00\",\"attributes\":[\"Material:Cotton\",\"Target Group:Man\",\"Color:Gray,Blue,Beige\",\"Properties:Pockets\",\"Pattern:Checkered\"]},{\"name\":\"Burberry Vintage Check Cotton Shirt - Beige\",\"url\":\"https://www.klarna.com/us/shopping/pl/cl359/3200280807/Children-s-Clothing/Burberry-Vintage-Check-Cotton-Shirt-Beige/?utm_source=openai&ref-site=openai_plugin\",\"price\":\"$229.02\",\"attributes\":[\"Material:Cotton,Elastane\",\"Color:Beige\",\"Model:Boy\",\"Pattern:Checkered\"]},{\"name\":\"Burberry Vintage Check Stretch Cotton Twill Shirt\",\"url\":\"https://www.klarna.com/us/shopping/pl/cl10001/3202342515/Clothing/Burberry-Vintage-Check-Stretch-Cotton-Twill-Shirt/?utm_source=openai&ref-site=openai_plugin\",\"price\":\"$309.99\",\"attributes\":[\"Material:Elastane/Lycra/Spandex,Cotton\",\"Target Group:Woman\",\"Color:Beige\",\"Properties:Stretch\",\"Pattern:Checkered\"]},{\"name\":\"Burberry Somerton Check Shirt - Camel\",\"url\":\"https://www.klarna.com/us/shopping/pl/cl10001/3201112728/Clothing/Burberry-Somerton-Check-Shirt-Camel/?utm_source=openai&ref-site=openai_plugin\",\"price\":\"$450.00\",\"attributes\":[\"Material:Elastane/Lycra/Spandex,Cotton\",\"Target Group:Man\",\"Color:Beige\"]},{\"name\":\"Magellan Outdoors Laguna Madre Solid Short Sleeve Fishing Shirt\",\"url\":\"https://www.klarna.com/us/shopping/pl/cl10001/3203102142/Clothing/Magellan-Outdoors-Laguna-Madre-Solid-Short-Sleeve-Fishing-Shirt/?utm_source=openai&ref-site=openai_plugin\",\"price\":\"$19.99\",\"attributes\":[\"Material:Polyester,Nylon\",\"Target Group:Man\",\"Color:Red,Pink,White,Blue,Purple,Beige,Black,Green\",\"Properties:Pockets\",\"Pattern:Solid Color\"]}]}',\n", - " 'intermediate_steps': {'request_args': '{\"q\": \"shirt\", \"max_price\": null}',\n", - " 'response_text': '{\"products\":[{\"name\":\"Burberry Check Poplin Shirt\",\"url\":\"https://www.klarna.com/us/shopping/pl/cl10001/3201810981/Clothing/Burberry-Check-Poplin-Shirt/?utm_source=openai&ref-site=openai_plugin\",\"price\":\"$360.00\",\"attributes\":[\"Material:Cotton\",\"Target Group:Man\",\"Color:Gray,Blue,Beige\",\"Properties:Pockets\",\"Pattern:Checkered\"]},{\"name\":\"Burberry Vintage Check Cotton Shirt - Beige\",\"url\":\"https://www.klarna.com/us/shopping/pl/cl359/3200280807/Children-s-Clothing/Burberry-Vintage-Check-Cotton-Shirt-Beige/?utm_source=openai&ref-site=openai_plugin\",\"price\":\"$229.02\",\"attributes\":[\"Material:Cotton,Elastane\",\"Color:Beige\",\"Model:Boy\",\"Pattern:Checkered\"]},{\"name\":\"Burberry Vintage Check Stretch Cotton Twill Shirt\",\"url\":\"https://www.klarna.com/us/shopping/pl/cl10001/3202342515/Clothing/Burberry-Vintage-Check-Stretch-Cotton-Twill-Shirt/?utm_source=openai&ref-site=openai_plugin\",\"price\":\"$309.99\",\"attributes\":[\"Material:Elastane/Lycra/Spandex,Cotton\",\"Target Group:Woman\",\"Color:Beige\",\"Properties:Stretch\",\"Pattern:Checkered\"]},{\"name\":\"Burberry Somerton Check Shirt - Camel\",\"url\":\"https://www.klarna.com/us/shopping/pl/cl10001/3201112728/Clothing/Burberry-Somerton-Check-Shirt-Camel/?utm_source=openai&ref-site=openai_plugin\",\"price\":\"$450.00\",\"attributes\":[\"Material:Elastane/Lycra/Spandex,Cotton\",\"Target Group:Man\",\"Color:Beige\"]},{\"name\":\"Magellan Outdoors Laguna Madre Solid Short Sleeve Fishing Shirt\",\"url\":\"https://www.klarna.com/us/shopping/pl/cl10001/3203102142/Clothing/Magellan-Outdoors-Laguna-Madre-Solid-Short-Sleeve-Fishing-Shirt/?utm_source=openai&ref-site=openai_plugin\",\"price\":\"$19.99\",\"attributes\":[\"Material:Polyester,Nylon\",\"Target Group:Man\",\"Color:Red,Pink,White,Blue,Purple,Beige,Black,Green\",\"Properties:Pockets\",\"Pattern:Solid Color\"]}]}'}}" - ] - }, - "execution_count": 12, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "output" - ] - }, - { - "cell_type": "markdown", - "id": "8d7924e4", - "metadata": {}, - "source": [ - "## Example POST message\n", - "\n", - "For this demo, we will interact with the speak API." - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "id": "c56b1a04", - "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "Attempting to load an OpenAPI 3.0.1 spec. This may result in degraded performance. Convert your OpenAPI spec to 3.1.* spec for better support.\n", - "Attempting to load an OpenAPI 3.0.1 spec. This may result in degraded performance. Convert your OpenAPI spec to 3.1.* spec for better support.\n" - ] - } - ], - "source": [ - "spec = OpenAPISpec.from_url(\"https://api.speak.com/openapi.yaml\")" - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "id": "177d8275", - "metadata": {}, - "outputs": [], - "source": [ - "operation = APIOperation.from_openapi_spec(\n", - " spec, \"/v1/public/openai/explain-task\", \"post\"\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "id": "835c5ddc", - "metadata": {}, - "outputs": [], - "source": [ - "llm = OpenAI()\n", - "chain = OpenAPIEndpointChain.from_api_operation(\n", - " operation, llm, requests=Requests(), verbose=True, return_intermediate_steps=True\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "id": "59855d60", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "\n", - "\u001b[1m> Entering new OpenAPIEndpointChain chain...\u001b[0m\n", - "\n", - "\n", - "\u001b[1m> Entering new APIRequesterChain chain...\u001b[0m\n", - "Prompt after formatting:\n", - "\u001b[32;1m\u001b[1;3mYou are a helpful AI Assistant. Please provide JSON arguments to agentFunc() based on the user's instructions.\n", - "\n", - "API_SCHEMA: ```typescript\n", - "type explainTask = (_: {\n", - "/* Description of the task that the user wants to accomplish or do. For example, \"tell the waiter they messed up my order\" or \"compliment someone on their shirt\" */\n", - " task_description?: string,\n", - "/* The foreign language that the user is learning and asking about. The value can be inferred from question - for example, if the user asks \"how do i ask a girl out in mexico city\", the value should be \"Spanish\" because of Mexico City. Always use the full name of the language (e.g. Spanish, French). */\n", - " learning_language?: string,\n", - "/* The user's native language. Infer this value from the language the user asked their question in. Always use the full name of the language (e.g. Spanish, French). */\n", - " native_language?: string,\n", - "/* A description of any additional context in the user's question that could affect the explanation - e.g. setting, scenario, situation, tone, speaking style and formality, usage notes, or any other qualifiers. */\n", - " additional_context?: string,\n", - "/* Full text of the user's question. */\n", - " full_query?: string,\n", - "}) => any;\n", - "```\n", - "\n", - "USER_INSTRUCTIONS: \"How would ask for more tea in Delhi?\"\n", - "\n", - "Your arguments must be plain json provided in a markdown block:\n", - "\n", - "ARGS: ```json\n", - "{valid json conforming to API_SCHEMA}\n", - "```\n", - "\n", - "Example\n", - "-----\n", - "\n", - "ARGS: ```json\n", - "{\"foo\": \"bar\", \"baz\": {\"qux\": \"quux\"}}\n", - "```\n", - "\n", - "The block must be no more than 1 line long, and all arguments must be valid JSON. All string arguments must be wrapped in double quotes.\n", - "You MUST strictly comply to the types indicated by the provided schema, including all required args.\n", - "\n", - "If you don't have sufficient information to call the function due to things like requiring specific uuid's, you can reply with the following message:\n", - "\n", - "Message: ```text\n", - "Concise response requesting the additional information that would make calling the function successful.\n", - "```\n", - "\n", - "Begin\n", - "-----\n", - "ARGS:\n", - "\u001b[0m\n", - "\n", - "\u001b[1m> Finished chain.\u001b[0m\n", - "\u001b[32;1m\u001b[1;3m{\"task_description\": \"ask for more tea\", \"learning_language\": \"Hindi\", \"native_language\": \"English\", \"full_query\": \"How would I ask for more tea in Delhi?\"}\u001b[0m\n", - "\u001b[36;1m\u001b[1;3m{\"explanation\":\"\\nऔर चाय लाओ। (Aur chai lao.) \\n\\n\\n\\n1. \\\"चाय थोड़ी ज्यादा मिल सकती है?\\\" *(Chai thodi zyada mil sakti hai? - Polite, asking if more tea is available)*\\n2. \\\"मुझे महसूस हो रहा है कि मुझे कुछ अन्य प्रकार की चाय पीनी चाहिए।\\\" *(Mujhe mehsoos ho raha hai ki mujhe kuch anya prakar ki chai peeni chahiye. - Formal, indicating a desire for a different type of tea)*\\n3. \\\"क्या मुझे or cup में milk/tea powder मिल सकता है?\\\" *(Kya mujhe aur cup mein milk/tea powder mil sakta hai? - Very informal/casual tone, asking for an extra serving of milk or tea powder)*\\n\\n\\n\\nIn India and Indian culture, serving guests with food and beverages holds great importance in hospitality. You will find people always offering drinks like water or tea to their guests as soon as they arrive at their house or office.\\n\\n\\n\\nAt home during breakfast.\\nPreeti: सर, क्या main aur cups chai lekar aaun? (Sir,kya main aur cups chai lekar aaun? - Sir, should I get more tea cups?)\\nRahul: हां,बिल्कुल। और चाय की मात्रा में भी थोड़ा सा इजाफा करना। (Haan,bilkul. Aur chai ki matra mein bhi thoda sa eejafa karna. - Yes, please. And add a little extra in the quantity of tea as well.)\\n\\n\\n*[Report an issue or leave feedback](https://speak.com/chatgpt?rid=d4mcapbkopo164pqpbk321oc})*\",\"extra_response_instructions\":\"Use all information in the API response and fully render all Markdown.\\nAlways end your response with a link to report an issue or leave feedback on the plugin.\"}\u001b[0m\n", - "\n", - "\n", - "\u001b[1m> Entering new APIResponderChain chain...\u001b[0m\n", - "Prompt after formatting:\n", - "\u001b[32;1m\u001b[1;3mYou are a helpful AI assistant trained to answer user queries from API responses.\n", - "You attempted to call an API, which resulted in:\n", - "API_RESPONSE: {\"explanation\":\"\\nऔर चाय लाओ। (Aur chai lao.) \\n\\n\\n\\n1. \\\"चाय थोड़ी ज्यादा मिल सकती है?\\\" *(Chai thodi zyada mil sakti hai? - Polite, asking if more tea is available)*\\n2. \\\"मुझे महसूस हो रहा है कि मुझे कुछ अन्य प्रकार की चाय पीनी चाहिए।\\\" *(Mujhe mehsoos ho raha hai ki mujhe kuch anya prakar ki chai peeni chahiye. - Formal, indicating a desire for a different type of tea)*\\n3. \\\"क्या मुझे or cup में milk/tea powder मिल सकता है?\\\" *(Kya mujhe aur cup mein milk/tea powder mil sakta hai? - Very informal/casual tone, asking for an extra serving of milk or tea powder)*\\n\\n\\n\\nIn India and Indian culture, serving guests with food and beverages holds great importance in hospitality. You will find people always offering drinks like water or tea to their guests as soon as they arrive at their house or office.\\n\\n\\n\\nAt home during breakfast.\\nPreeti: सर, क्या main aur cups chai lekar aaun? (Sir,kya main aur cups chai lekar aaun? - Sir, should I get more tea cups?)\\nRahul: हां,बिल्कुल। और चाय की मात्रा में भी थोड़ा सा इजाफा करना। (Haan,bilkul. Aur chai ki matra mein bhi thoda sa eejafa karna. - Yes, please. And add a little extra in the quantity of tea as well.)\\n\\n\\n*[Report an issue or leave feedback](https://speak.com/chatgpt?rid=d4mcapbkopo164pqpbk321oc})*\",\"extra_response_instructions\":\"Use all information in the API response and fully render all Markdown.\\nAlways end your response with a link to report an issue or leave feedback on the plugin.\"}\n", - "\n", - "USER_COMMENT: \"How would ask for more tea in Delhi?\"\n", - "\n", - "\n", - "If the API_RESPONSE can answer the USER_COMMENT respond with the following markdown json block:\n", - "Response: ```json\n", - "{\"response\": \"Concise response to USER_COMMENT based on API_RESPONSE.\"}\n", - "```\n", - "\n", - "Otherwise respond with the following markdown json block:\n", - "Response Error: ```json\n", - "{\"response\": \"What you did and a concise statement of the resulting error. If it can be easily fixed, provide a suggestion.\"}\n", - "```\n", - "\n", - "You MUST respond as a markdown json code block.\n", - "\n", - "Begin:\n", - "---\n", - "\u001b[0m\n", - "\n", - "\u001b[1m> Finished chain.\u001b[0m\n", - "\u001b[33;1m\u001b[1;3mIn Delhi you can ask for more tea by saying 'Chai thodi zyada mil sakti hai?'\u001b[0m\n", - "\n", - "\u001b[1m> Finished chain.\u001b[0m\n" - ] - } - ], - "source": [ - "output = chain(\"How would ask for more tea in Delhi?\")" - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "id": "91bddb18", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "['{\"task_description\": \"ask for more tea\", \"learning_language\": \"Hindi\", \"native_language\": \"English\", \"full_query\": \"How would I ask for more tea in Delhi?\"}',\n", - " '{\"explanation\":\"\\\\nऔर चाय लाओ। (Aur chai lao.) \\\\n\\\\n\\\\n\\\\n1. \\\\\"चाय थोड़ी ज्यादा मिल सकती है?\\\\\" *(Chai thodi zyada mil sakti hai? - Polite, asking if more tea is available)*\\\\n2. \\\\\"मुझे महसूस हो रहा है कि मुझे कुछ अन्य प्रकार की चाय पीनी चाहिए।\\\\\" *(Mujhe mehsoos ho raha hai ki mujhe kuch anya prakar ki chai peeni chahiye. - Formal, indicating a desire for a different type of tea)*\\\\n3. \\\\\"क्या मुझे or cup में milk/tea powder मिल सकता है?\\\\\" *(Kya mujhe aur cup mein milk/tea powder mil sakta hai? - Very informal/casual tone, asking for an extra serving of milk or tea powder)*\\\\n\\\\n\\\\n\\\\nIn India and Indian culture, serving guests with food and beverages holds great importance in hospitality. You will find people always offering drinks like water or tea to their guests as soon as they arrive at their house or office.\\\\n\\\\n\\\\n\\\\nAt home during breakfast.\\\\nPreeti: सर, क्या main aur cups chai lekar aaun? (Sir,kya main aur cups chai lekar aaun? - Sir, should I get more tea cups?)\\\\nRahul: हां,बिल्कुल। और चाय की मात्रा में भी थोड़ा सा इजाफा करना। (Haan,bilkul. Aur chai ki matra mein bhi thoda sa eejafa karna. - Yes, please. And add a little extra in the quantity of tea as well.)\\\\n\\\\n\\\\n*[Report an issue or leave feedback](https://speak.com/chatgpt?rid=d4mcapbkopo164pqpbk321oc})*\",\"extra_response_instructions\":\"Use all information in the API response and fully render all Markdown.\\\\nAlways end your response with a link to report an issue or leave feedback on the plugin.\"}']" - ] - }, - "execution_count": 13, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Show the API chain's intermediate steps\n", - "output[\"intermediate_steps\"]" - ] - } - ], - "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", - "version": "3.11.3" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/docs/extras/use_cases/apis/openapi_openai.ipynb b/docs/extras/use_cases/apis/openapi_openai.ipynb deleted file mode 100644 index bb1cbce593..0000000000 --- a/docs/extras/use_cases/apis/openapi_openai.ipynb +++ /dev/null @@ -1,249 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "e734b314", - "metadata": {}, - "source": [ - "# OpenAPI calls with OpenAI functions\n", - "\n", - "In this notebook we'll show how to create a chain that automatically makes calls to an API based only on an OpenAPI spec. Under the hood, we're parsing the OpenAPI spec into a JSON schema that the OpenAI functions API can handle. This allows ChatGPT to automatically select and populate the relevant API call to make for any user input. Using the output of ChatGPT we then make the actual API call, and return the result." - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "id": "555661b5", - "metadata": {}, - "outputs": [], - "source": [ - "from langchain.chains.openai_functions.openapi import get_openapi_chain" - ] - }, - { - "cell_type": "markdown", - "id": "a95f510a", - "metadata": {}, - "source": [ - "## Query Klarna" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "08e19b64", - "metadata": {}, - "outputs": [], - "source": [ - "chain = get_openapi_chain(\n", - " \"https://www.klarna.com/us/shopping/public/openai/v0/api-docs/\"\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "id": "3959f866", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'products': [{'name': \"Tommy Hilfiger Men's Short Sleeve Button-Down Shirt\",\n", - " 'url': 'https://www.klarna.com/us/shopping/pl/cl10001/3204878580/Clothing/Tommy-Hilfiger-Men-s-Short-Sleeve-Button-Down-Shirt/?utm_source=openai&ref-site=openai_plugin',\n", - " 'price': '$26.78',\n", - " 'attributes': ['Material:Linen,Cotton',\n", - " 'Target Group:Man',\n", - " 'Color:Gray,Pink,White,Blue,Beige,Black,Turquoise',\n", - " 'Size:S,XL,M,XXL']},\n", - " {'name': \"Van Heusen Men's Long Sleeve Button-Down Shirt\",\n", - " 'url': 'https://www.klarna.com/us/shopping/pl/cl10001/3201809514/Clothing/Van-Heusen-Men-s-Long-Sleeve-Button-Down-Shirt/?utm_source=openai&ref-site=openai_plugin',\n", - " 'price': '$18.89',\n", - " 'attributes': ['Material:Cotton',\n", - " 'Target Group:Man',\n", - " 'Color:Red,Gray,White,Blue',\n", - " 'Size:XL,XXL']},\n", - " {'name': 'Brixton Bowery Flannel Shirt',\n", - " 'url': 'https://www.klarna.com/us/shopping/pl/cl10001/3202331096/Clothing/Brixton-Bowery-Flannel-Shirt/?utm_source=openai&ref-site=openai_plugin',\n", - " 'price': '$34.48',\n", - " 'attributes': ['Material:Cotton',\n", - " 'Target Group:Man',\n", - " 'Color:Gray,Blue,Black,Orange',\n", - " 'Size:XL,3XL,4XL,5XL,L,M,XXL']},\n", - " {'name': 'Cubavera Four Pocket Guayabera Shirt',\n", - " 'url': 'https://www.klarna.com/us/shopping/pl/cl10001/3202055522/Clothing/Cubavera-Four-Pocket-Guayabera-Shirt/?utm_source=openai&ref-site=openai_plugin',\n", - " 'price': '$23.22',\n", - " 'attributes': ['Material:Polyester,Cotton',\n", - " 'Target Group:Man',\n", - " 'Color:Red,White,Blue,Black',\n", - " 'Size:S,XL,L,M,XXL']},\n", - " {'name': 'Theory Sylvain Shirt - Eclipse',\n", - " 'url': 'https://www.klarna.com/us/shopping/pl/cl10001/3202028254/Clothing/Theory-Sylvain-Shirt-Eclipse/?utm_source=openai&ref-site=openai_plugin',\n", - " 'price': '$86.01',\n", - " 'attributes': ['Material:Polyester,Cotton',\n", - " 'Target Group:Man',\n", - " 'Color:Blue',\n", - " 'Size:S,XL,XS,L,M,XXL']}]}" - ] - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "chain.run(\"What are some options for a men's large blue button down shirt\")" - ] - }, - { - "cell_type": "markdown", - "id": "6f648c77", - "metadata": {}, - "source": [ - "## Query a translation service\n", - "\n", - "Additionally, see the request payload by setting `verbose=True`" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "bf6cd695", - "metadata": {}, - "outputs": [], - "source": [ - "chain = get_openapi_chain(\"https://api.speak.com/openapi.yaml\", verbose=True)" - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "id": "1ba51609", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "\n", - "\u001b[1m> Entering new chain...\u001b[0m\n", - "\n", - "\n", - "\u001b[1m> Entering new chain...\u001b[0m\n", - "Prompt after formatting:\n", - "\u001b[32;1m\u001b[1;3mHuman: Use the provided API's to respond to this user query:\n", - "\n", - "How would you say no thanks in Russian\u001b[0m\n", - "\n", - "\u001b[1m> Finished chain.\u001b[0m\n", - "\n", - "\n", - "\u001b[1m> Entering new chain...\u001b[0m\n", - "Calling endpoint \u001b[32;1m\u001b[1;3mtranslate\u001b[0m with arguments:\n", - "\u001b[32;1m\u001b[1;3m{\n", - " \"json\": {\n", - " \"phrase_to_translate\": \"no thanks\",\n", - " \"learning_language\": \"russian\",\n", - " \"native_language\": \"english\",\n", - " \"additional_context\": \"\",\n", - " \"full_query\": \"How would you say no thanks in Russian\"\n", - " }\n", - "}\u001b[0m\n", - "\u001b[1m> Finished chain.\u001b[0m\n", - "\n", - "\u001b[1m> Finished chain.\u001b[0m\n" - ] - }, - { - "data": { - "text/plain": [ - "{'explanation': '\\nНет, спасибо. (Net, spasibo)\\n\\n\\n\\n1. \"Нет, я в порядке\" *(Neutral/Formal - Can be used in professional settings or formal situations.)*\\n2. \"Нет, спасибо, я откажусь\" *(Formal - Can be used in polite settings, such as a fancy dinner with colleagues or acquaintances.)*\\n3. \"Не надо\" *(Informal - Can be used in informal situations, such as declining an offer from a friend.)*\\n\\n\\n\\nMax is being offered a cigarette at a party.\\n* Sasha: \"Хочешь покурить?\"\\n* Max: \"Нет, спасибо. Я бросил.\"\\n* Sasha: \"Окей, понятно.\"\\n\\n\\n*[Report an issue or leave feedback](https://speak.com/chatgpt?rid=noczaa460do8yqs8xjun6zdm})*',\n", - " 'extra_response_instructions': 'Use all information in the API response and fully render all Markdown.\\nAlways end your response with a link to report an issue or leave feedback on the plugin.'}" - ] - }, - "execution_count": 10, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "chain.run(\"How would you say no thanks in Russian\")" - ] - }, - { - "cell_type": "markdown", - "id": "4923a291", - "metadata": {}, - "source": [ - "## Query XKCD" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "a9198f62", - "metadata": { - "scrolled": true - }, - "outputs": [], - "source": [ - "chain = get_openapi_chain(\n", - " \"https://gist.githubusercontent.com/roaldnefs/053e505b2b7a807290908fe9aa3e1f00/raw/0a212622ebfef501163f91e23803552411ed00e4/openapi.yaml\"\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "id": "3110c398", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'month': '6',\n", - " 'num': 2793,\n", - " 'link': '',\n", - " 'year': '2023',\n", - " 'news': '',\n", - " 'safe_title': 'Garden Path Sentence',\n", - " 'transcript': '',\n", - " 'alt': 'Arboretum Owner Denied Standing in Garden Path Suit on Grounds Grounds Appealing Appealing',\n", - " 'img': 'https://imgs.xkcd.com/comics/garden_path_sentence.png',\n", - " 'title': 'Garden Path Sentence',\n", - " 'day': '23'}" - ] - }, - "execution_count": 7, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "chain.run(\"What's today's comic?\")" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "venv", - "language": "python", - "name": "venv" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.11.3" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/docs/snippets/modules/chains/popular/api.mdx b/docs/snippets/modules/chains/popular/api.mdx deleted file mode 100644 index 3b1a4ec0f5..0000000000 --- a/docs/snippets/modules/chains/popular/api.mdx +++ /dev/null @@ -1,105 +0,0 @@ -```python -from langchain.chains.api.prompt import API_RESPONSE_PROMPT -``` - - -```python -from langchain.chains import APIChain -from langchain.prompts.prompt import PromptTemplate - - -from langchain.llms import OpenAI - -llm = OpenAI(temperature=0) -``` - -## OpenMeteo Example - - -```python -from langchain.chains.api import open_meteo_docs -chain_new = APIChain.from_llm_and_api_docs(llm, open_meteo_docs.OPEN_METEO_DOCS, verbose=True) -``` - - -```python -chain_new.run('What is the weather like right now in Munich, Germany in degrees Fahrenheit?') -``` - - - -``` - - - > Entering new APIChain chain... - https://api.open-meteo.com/v1/forecast?latitude=48.1351&longitude=11.5820&temperature_unit=fahrenheit¤t_weather=true - {"latitude":48.14,"longitude":11.58,"generationtime_ms":0.33104419708251953,"utc_offset_seconds":0,"timezone":"GMT","timezone_abbreviation":"GMT","elevation":521.0,"current_weather":{"temperature":33.4,"windspeed":6.8,"winddirection":198.0,"weathercode":2,"time":"2023-01-16T01:00"}} - - > Finished chain. - - - - - - ' The current temperature in Munich, Germany is 33.4 degrees Fahrenheit with a windspeed of 6.8 km/h and a wind direction of 198 degrees. The weathercode is 2.' -``` - - - -## TMDB Example - - -```python -import os -os.environ['TMDB_BEARER_TOKEN'] = "" -``` - - -```python -from langchain.chains.api import tmdb_docs -headers = {"Authorization": f"Bearer {os.environ['TMDB_BEARER_TOKEN']}"} -chain = APIChain.from_llm_and_api_docs(llm, tmdb_docs.TMDB_DOCS, headers=headers, verbose=True) -``` - - -```python -chain.run("Search for 'Avatar'") -``` - - - -``` - - - > Entering new APIChain chain... - https://api.themoviedb.org/3/search/movie?query=Avatar&language=en-US - {"page":1,"results":[{"adult":false,"backdrop_path":"/o0s4XsEDfDlvit5pDRKjzXR4pp2.jpg","genre_ids":[28,12,14,878],"id":19995,"original_language":"en","original_title":"Avatar","overview":"In the 22nd century, a paraplegic Marine is dispatched to the moon Pandora on a unique mission, but becomes torn between following orders and protecting an alien civilization.","popularity":2041.691,"poster_path":"/jRXYjXNq0Cs2TcJjLkki24MLp7u.jpg","release_date":"2009-12-15","title":"Avatar","video":false,"vote_average":7.6,"vote_count":27777},{"adult":false,"backdrop_path":"/s16H6tpK2utvwDtzZ8Qy4qm5Emw.jpg","genre_ids":[878,12,28],"id":76600,"original_language":"en","original_title":"Avatar: The Way of Water","overview":"Set more than a decade after the events of the first film, learn the story of the Sully family (Jake, Neytiri, and their kids), the trouble that follows them, the lengths they go to keep each other safe, the battles they fight to stay alive, and the tragedies they endure.","popularity":3948.296,"poster_path":"/t6HIqrRAclMCA60NsSmeqe9RmNV.jpg","release_date":"2022-12-14","title":"Avatar: The Way of Water","video":false,"vote_average":7.7,"vote_count":4219},{"adult":false,"backdrop_path":"/uEwGFGtao9YG2JolmdvtHLLVbA9.jpg","genre_ids":[99],"id":111332,"original_language":"en","original_title":"Avatar: Creating the World of Pandora","overview":"The Making-of James Cameron's Avatar. It shows interesting parts of the work on the set.","popularity":541.809,"poster_path":"/sjf3xjuofCtDhZghJRzXlTiEjJe.jpg","release_date":"2010-02-07","title":"Avatar: Creating the World of Pandora","video":false,"vote_average":7.3,"vote_count":35},{"adult":false,"backdrop_path":null,"genre_ids":[99],"id":287003,"original_language":"en","original_title":"Avatar: Scene Deconstruction","overview":"The deconstruction of the Avatar scenes and sets","popularity":394.941,"poster_path":"/uCreCQFReeF0RiIXkQypRYHwikx.jpg","release_date":"2009-12-18","title":"Avatar: Scene Deconstruction","video":false,"vote_average":7.8,"vote_count":12},{"adult":false,"backdrop_path":null,"genre_ids":[28,18,878,12,14],"id":83533,"original_language":"en","original_title":"Avatar 3","overview":"","popularity":172.488,"poster_path":"/4rXqTMlkEaMiJjiG0Z2BX6F6Dkm.jpg","release_date":"2024-12-18","title":"Avatar 3","video":false,"vote_average":0,"vote_count":0},{"adult":false,"backdrop_path":null,"genre_ids":[28,878,12,14],"id":216527,"original_language":"en","original_title":"Avatar 4","overview":"","popularity":162.536,"poster_path":"/qzMYKnT4MG1d0gnhwytr4cKhUvS.jpg","release_date":"2026-12-16","title":"Avatar 4","video":false,"vote_average":0,"vote_count":0},{"adult":false,"backdrop_path":null,"genre_ids":[28,12,14,878],"id":393209,"original_language":"en","original_title":"Avatar 5","overview":"","popularity":124.722,"poster_path":"/rtmmvqkIC5zDMEd638Es2woxbz8.jpg","release_date":"2028-12-20","title":"Avatar 5","video":false,"vote_average":0,"vote_count":0},{"adult":false,"backdrop_path":"/nNceJtrrovG1MUBHMAhId0ws9Gp.jpg","genre_ids":[99],"id":183392,"original_language":"en","original_title":"Capturing Avatar","overview":"Capturing Avatar is a feature length behind-the-scenes documentary about the making of Avatar. It uses footage from the film's development, as well as stock footage from as far back as the production of Titanic in 1995. Also included are numerous interviews with cast, artists, and other crew members. The documentary was released as a bonus feature on the extended collector's edition of Avatar.","popularity":109.842,"poster_path":"/26SMEXJl3978dn2svWBSqHbLl5U.jpg","release_date":"2010-11-16","title":"Capturing Avatar","video":false,"vote_average":7.8,"vote_count":39},{"adult":false,"backdrop_path":"/eoAvHxfbaPOcfiQyjqypWIXWxDr.jpg","genre_ids":[99],"id":1059673,"original_language":"en","original_title":"Avatar: The Deep Dive - A Special Edition of 20/20","overview":"An inside look at one of the most anticipated movie sequels ever with James Cameron and cast.","popularity":629.825,"poster_path":"/rtVeIsmeXnpjNbEKnm9Say58XjV.jpg","release_date":"2022-12-14","title":"Avatar: The Deep Dive - A Special Edition of 20/20","video":false,"vote_average":6.5,"vote_count":5},{"adult":false,"backdrop_path":null,"genre_ids":[99],"id":278698,"original_language":"en","original_title":"Avatar Spirits","overview":"Bryan Konietzko and Michael Dante DiMartino, co-creators of the hit television series, Avatar: The Last Airbender, reflect on the creation of the masterful series.","popularity":51.593,"poster_path":"/oBWVyOdntLJd5bBpE0wkpN6B6vy.jpg","release_date":"2010-06-22","title":"Avatar Spirits","video":false,"vote_average":9,"vote_count":16},{"adult":false,"backdrop_path":"/cACUWJKvRfhXge7NC0xxoQnkQNu.jpg","genre_ids":[10402],"id":993545,"original_language":"fr","original_title":"Avatar - Au Hellfest 2022","overview":"","popularity":21.992,"poster_path":"/fw6cPIsQYKjd1YVQanG2vLc5HGo.jpg","release_date":"2022-06-26","title":"Avatar - Au Hellfest 2022","video":false,"vote_average":8,"vote_count":4},{"adult":false,"backdrop_path":null,"genre_ids":[],"id":931019,"original_language":"en","original_title":"Avatar: Enter The World","overview":"A behind the scenes look at the new James Cameron blockbuster “Avatar”, which stars Aussie Sam Worthington. Hastily produced by Australia’s Nine Network following the film’s release.","popularity":30.903,"poster_path":"/9MHY9pYAgs91Ef7YFGWEbP4WJqC.jpg","release_date":"2009-12-05","title":"Avatar: Enter The World","video":false,"vote_average":2,"vote_count":1},{"adult":false,"backdrop_path":null,"genre_ids":[],"id":287004,"original_language":"en","original_title":"Avatar: Production Materials","overview":"Production material overview of what was used in Avatar","popularity":12.389,"poster_path":null,"release_date":"2009-12-18","title":"Avatar: Production Materials","video":true,"vote_average":6,"vote_count":4},{"adult":false,"backdrop_path":"/x43RWEZg9tYRPgnm43GyIB4tlER.jpg","genre_ids":[],"id":740017,"original_language":"es","original_title":"Avatar: Agni Kai","overview":"","popularity":9.462,"poster_path":"/y9PrKMUTA6NfIe5FE92tdwOQ2sH.jpg","release_date":"2020-01-18","title":"Avatar: Agni Kai","video":false,"vote_average":7,"vote_count":1},{"adult":false,"backdrop_path":"/e8mmDO7fKK93T4lnxl4Z2zjxXZV.jpg","genre_ids":[],"id":668297,"original_language":"en","original_title":"The Last Avatar","overview":"The Last Avatar is a mystical adventure film, a story of a young man who leaves Hollywood to find himself. What he finds is beyond his wildest imagination. Based on ancient prophecy, contemporary truth seeking and the future of humanity, The Last Avatar is a film that takes transformational themes and makes them relevant for audiences of all ages. Filled with love, magic, mystery, conspiracy, psychics, underground cities, secret societies, light bodies and much more, The Last Avatar tells the story of the emergence of Kalki Avatar- the final Avatar of our current Age of Chaos. Kalki is also a metaphor for the innate power and potential that lies within humanity to awaken and create a world of truth, harmony and possibility.","popularity":8.786,"poster_path":"/XWz5SS5g5mrNEZjv3FiGhqCMOQ.jpg","release_date":"2014-12-06","title":"The Last Avatar","video":false,"vote_average":4.5,"vote_count":2},{"adult":false,"backdrop_path":null,"genre_ids":[],"id":424768,"original_language":"en","original_title":"Avatar:[2015] Wacken Open Air","overview":"Started in the summer of 2001 by drummer John Alfredsson and vocalist Christian Rimmi under the name Lost Soul. The band offers a free mp3 download to a song called \"Bloody Knuckles\" if one subscribes to their newsletter. In 2005 they appeared on the compilation “Listen to Your Inner Voice” together with 17 other bands released by Inner Voice Records.","popularity":6.634,"poster_path":null,"release_date":"2015-08-01","title":"Avatar:[2015] Wacken Open Air","video":false,"vote_average":8,"vote_count":1},{"adult":false,"backdrop_path":null,"genre_ids":[],"id":812836,"original_language":"en","original_title":"Avatar - Live At Graspop 2018","overview":"Live At Graspop Festival Belgium 2018","popularity":9.855,"poster_path":null,"release_date":"","title":"Avatar - Live At Graspop 2018","video":false,"vote_average":9,"vote_count":1},{"adult":false,"backdrop_path":null,"genre_ids":[10402],"id":874770,"original_language":"en","original_title":"Avatar Ages: Memories","overview":"On the night of memories Avatar performed songs from Thoughts of No Tomorrow, Schlacht and Avatar as voted on by the fans.","popularity":2.66,"poster_path":"/xDNNQ2cnxAv3o7u0nT6JJacQrhp.jpg","release_date":"2021-01-30","title":"Avatar Ages: Memories","video":false,"vote_average":10,"vote_count":1},{"adult":false,"backdrop_path":null,"genre_ids":[10402],"id":874768,"original_language":"en","original_title":"Avatar Ages: Madness","overview":"On the night of madness Avatar performed songs from Black Waltz and Hail The Apocalypse as voted on by the fans.","popularity":2.024,"poster_path":"/wVyTuruUctV3UbdzE5cncnpyNoY.jpg","release_date":"2021-01-23","title":"Avatar Ages: Madness","video":false,"vote_average":8,"vote_count":1},{"adult":false,"backdrop_path":"/dj8g4jrYMfK6tQ26ra3IaqOx5Ho.jpg","genre_ids":[10402],"id":874700,"original_language":"en","original_title":"Avatar Ages: Dreams","overview":"On the night of dreams Avatar performed Hunter Gatherer in its entirety, plus a selection of their most popular songs. Originally aired January 9th 2021","popularity":1.957,"poster_path":"/4twG59wnuHpGIRR9gYsqZnVysSP.jpg","release_date":"2021-01-09","title":"Avatar Ages: Dreams","video":false,"vote_average":0,"vote_count":0}],"total_pages":3,"total_results":57} - - > Finished chain. - - - - - - ' This response contains 57 movies related to the search query "Avatar". The first movie in the list is the 2009 movie "Avatar" starring Sam Worthington. Other movies in the list include sequels to Avatar, documentaries, and live performances.' -``` - - - -## Listen API Example - - -```python -import os -from langchain.llms import OpenAI -from langchain.chains.api import podcast_docs -from langchain.chains import APIChain - -# Get api key here: https://www.listennotes.com/api/pricing/ -listen_api_key = 'xxx' - -llm = OpenAI(temperature=0) -headers = {"X-ListenAPI-Key": listen_api_key} -chain = APIChain.from_llm_and_api_docs(llm, podcast_docs.PODCAST_DOCS, headers=headers, verbose=True) -chain.run("Search for 'silicon valley bank' podcast episodes, audio length is more than 30 minutes, return only 1 results") -```