Fireworks LangChain Integration
An integration package connecting Fireworks AI with LangChain, providing functionalities for chat models (ChatFireworks) and embedding models (FireworksEmbeddings). The current version is 1.1.0, and the library follows a regular release cadence, often aligned with updates to the broader LangChain ecosystem.
Warnings
- breaking LangChain, as a rapidly evolving ecosystem, frequently undergoes API changes, especially with major version bumps of `langchain-core`. Code from older tutorials or examples may use deprecated patterns and require migration to newer interfaces (e.g., LCEL).
- gotcha The `FIREWORKS_API_KEY` environment variable is the primary method for authenticating with Fireworks AI. Failure to set this variable correctly or pass it directly to the model constructor will result in authentication errors.
- gotcha The library explicitly requires Python versions `>=3.10.0` and `<4.0.0`. Using unsupported Python versions (e.g., older than 3.10 or Python 4.x) may lead to installation failures or runtime incompatibilities.
- gotcha When using advanced features like tool calling or structured output, some specific Fireworks models have historically exhibited issues with retaining `reasoning_content` in multi-turn conversations, potentially leading to incorrect responses or hallucinations.
Install
-
pip install langchain-fireworks
Imports
- ChatFireworks
from langchain_fireworks import ChatFireworks
- FireworksEmbeddings
from langchain_fireworks import FireworksEmbeddings
Quickstart
import os
from langchain_fireworks import ChatFireworks
from langchain_core.messages import HumanMessage, SystemMessage
# Ensure FIREWORKS_API_KEY environment variable is set.
# For a real application, load your API key securely.
# os.environ["FIREWORKS_API_KEY"] = "YOUR_FIREWORKS_API_KEY"
llm = ChatFireworks(
model="accounts/fireworks/models/llama-v3p3-70b-instruct",
temperature=0,
max_tokens=None,
fireworks_api_key=os.environ.get("FIREWORKS_API_KEY", "") # Fallback for quickstart if not set
)
messages = [
SystemMessage(content="You are a helpful assistant."),
HumanMessage(content="What is the capital of France?"),
]
response = llm.invoke(messages)
print(response.content)