Skip to main contentü¶úÔ∏èüîó LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKQA over structured dataSQLRetrieval-augmented generation (RAG)Interacting with APIsChatbotsExtractionSummarizationTaggingWeb scrapingSynthetic data generationGraph queryingInteracting with APIsOn this pageInteracting with APIsUse case‚ÄãSuppose you want an LLM to interact with external APIs.This can be very useful for retrieving context for the LLM to utilize.And, more generally, it allows us to interact with APIs using natural language! Overview‚ÄãThere are two primary ways to interface LLMs with external APIs:Functions: For example, OpenAI functions is one popular means of doing this.LLM-generated interface: Use an LLM with access to API documentation to create an interface.Quickstart‚ÄãMany APIs are already compatible with OpenAI function calling.For example, Klarna has a YAML file that describes its API and allows OpenAI to interact with it:https://www.klarna.com/us/shopping/public/openai/v0/api-docs/Other options include:Speak for translationXKCD for comicsWe can supply the specification to get_openapi_chain directly in order to query the API with OpenAI functions:pip install langchain openai # Set env var OPENAI_API_KEY or load from a .env file:# import dotenv# dotenv.load_dotenv()from langchain.chains.openai_functions.openapi import get_openapi_chainchain = get_openapi_chain("https://www.klarna.com/us/shopping/public/openai/v0/api-docs/")chain("What are some options for a men's large blue button down shirt")    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.    {'query': "What are some options for a men's large blue button down shirt",     'response': {'products': [{'name': 'Cubavera Four Pocket Guayabera Shirt',        'url':
Open In Colab
Open In Colab ->: Skip to main contentü¶úÔ∏èüîó LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKQA over structured dataSQLRetrieval-augmented generation (RAG)Interacting with APIsChatbotsExtractionSummarizationTaggingWeb scrapingSynthetic data generationGraph queryingInteracting with APIsOn this pageInteracting with APIsUse case‚ÄãSuppose you want an LLM to interact with external APIs.This can be very useful for retrieving context for the LLM to utilize.And, more generally, it allows us to interact with APIs using natural language! Overview‚ÄãThere are two primary ways to interface LLMs with external APIs:Functions: For example, OpenAI functions is one popular means of doing this.LLM-generated interface: Use an LLM with access to API documentation to create an interface.Quickstart‚ÄãMany APIs are already compatible with OpenAI function calling.For example, Klarna has a YAML file that describes its API and allows OpenAI to interact with it:https://www.klarna.com/us/shopping/public/openai/v0/api-docs/Other options include:Speak for translationXKCD for comicsWe can supply the specification to get_openapi_chain directly in order to query the API with OpenAI functions:pip install langchain openai # Set env var OPENAI_API_KEY or load from a .env file:# import dotenv# dotenv.load_dotenv()from langchain.chains.openai_functions.openapi import get_openapi_chainchain = get_openapi_chain("https://www.klarna.com/us/shopping/public/openai/v0/api-docs/")chain("What are some options for a men's large blue button down shirt")    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.    {'query': "What are some options for a men's large blue button down shirt",     'response': {'products': [{'name': 'Cubavera Four Pocket Guayabera Shirt',        'url':