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 app 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 URL and API Key shown at the top of the app page
Configure LangChain
In this example we will configure LangChain to work with OpenAI (or OpenAI compatible models).
To work with OpenAI in LangChain it's 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 your app's API URL with/v1appended, for examplehttps://my-gateway-main-2e18f50.zuplo.app/config_fe0a04972d2848e0a94ae4b8bcd1497e/v1. The app page in the Zuplo Portal shows the API URL, which ends in the app's ID
Both of these values are passed to ChatOpenAI when it's instantiated,
switching the configuration from using default OpenAI APIs to using Zuplo's AI
Gateway.
Always name the model as providerName/model, where providerName is the
provider name configured in your gateway. The gateway needs the prefix to know
which provider to route to, and a request with no model, or a model without that
prefix, gets a 400. Adding the
Model Filtering
policy restricts an app to certain models, and an allow list also supplies a
default so requests may omit the model.