LangChain
LangChain is a framework for developing applications that are powered by Large Language Models (LLMs). It implements a standard interface for large language models and related technologies, such as embedding models and vector stores, and integrates with hundreds of providers.
Prerequisites
In order to use the AI Gateway with any LangChain powered application you will need to complete these steps first:
-
Create a new provider in the AI Gateway for the provider you want to use with LangChain
-
Create a new app to use specifically with LangChain and assign it to the team you created
-
Copy the API Key for the app you created, as well as the Gateway URL
Configure LangChain
In this example we will configure LangChain to work with OpenAI (or OpenAI compatible models).
To work with OpenAI in LangChain it is recommended to use their ChatOpenAI integration.
Code
In the code above, checks are performed for two environment variables:
ZUPLO_AI_GATEWAY_API_KEY
- This is the API key of the app you have configured to use with LangChain in ZuploBASE_URL
- This is the Gateway URL of your AI Gateway project in Zuplo
Both of these values are passed to ChatOpenAI
when it is instantiated,
switching the configuration from using default OpenAI APIs to using Zuplo's AI
Gateway for all gpt-4o
requests that the LangChain SDK will make.