langchain-ibm
This package provides the integration between LangChain and IBM watsonx.ai through the ibm-watsonx-ai SDK.
Installation
To use the langchain-ibm package, follow these installation steps:
pip install langchain-ibm
Usage
Setting up
To use IBM's models, you must have an IBM Cloud user API key. Here's how to obtain and set up your API key:
Obtain an API Key: For more details on how to create and manage an API key, refer to IBM's documentation.
Set the API Key as an Environment Variable: For security reasons, it's recommended to not hard-code your API key directly in your scripts. Instead, set it up as an environment variable. You can use the following code to prompt for the API key and set it as an environment variable:
import os
from getpass import getpass
watsonx_api_key = getpass()
os.environ["WATSONX_APIKEY"] = watsonx_api_key
In alternative, you can set the environment variable in your terminal.
Linux/macOS: Open your terminal and execute the following command:
ex
|