Skip to main content

An integration package connecting Fireworks and LangChain

Project description

LangChain-Fireworks

This is the partner package for tying Fireworks.ai and LangChain. Fireworks really strive to provide good support for LangChain use cases, so if you run into any issues please let us know. You can reach out to us in our Discord channel

Installation

To use the langchain-fireworks package, follow these installation steps:

pip install langchain-fireworks

Basic usage

Setting up

  1. Sign in to Fireworks AI to obtain an API Key to access the models, and make sure it is set as the FIREWORKS_API_KEY environment variable.

    Once you've signed in and obtained an API key, follow these steps to set the FIREWORKS_API_KEY environment variable:

    • Linux/macOS: Open your terminal and execute the following command:
    export FIREWORKS_API_KEY='your_api_key'
    

    Note: To make this environment variable persistent across terminal sessions, add the above line to your ~/.bashrc, ~/.bash_profile, or ~/.zshrc file.

    • Windows: For Command Prompt, use:
    set FIREWORKS_API_KEY=your_api_key
    
  2. Set up your model using a model id. If the model is not set, the default model is fireworks-llama-v2-7b-chat. See the full, most up-to-date model list on fireworks.ai.

import getpass
import os

# Initialize a Fireworks model
llm = Fireworks(
    model="accounts/fireworks/models/llama-v3p1-8b-instruct",
    base_url="https://api.fireworks.ai/inference/v1/completions",
)

Calling the Model Directly

You can call the model directly with string prompts to get completions.

# Single prompt
output = llm.invoke("Who's the best quarterback in the NFL?")
print(output)
# Calling multiple prompts
output = llm.generate(
    [
        "Who's the best cricket player in 2016?",
        "Who's the best basketball player in the league?",
    ]
)
print(output.generations)

Advanced usage

Tool use: LangChain Agent + Fireworks function calling model

Please checkout how to teach Fireworks function calling model to use a calculator in this notebook.

Fireworks focus on delivering the best experience for fast model inference as well as tool use. You can check out our blog for more details on how it compares to GPT-4, the punchline is that it is on par with GPT-4 in terms of function calling use cases, but it is way faster and much cheaper.

RAG: LangChain agent + Fireworks function calling model + MongoDB + Nomic AI embeddings

Please check out the cookbook here for an end to end flow

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langchain_fireworks-1.0.0a1.tar.gz (20.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langchain_fireworks-1.0.0a1-py3-none-any.whl (17.5 kB view details)

Uploaded Python 3

File details

Details for the file langchain_fireworks-1.0.0a1.tar.gz.

File metadata

  • Download URL: langchain_fireworks-1.0.0a1.tar.gz
  • Upload date:
  • Size: 20.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for langchain_fireworks-1.0.0a1.tar.gz
Algorithm Hash digest
SHA256 c78274d47e15f5d89ecacf6864fada1cf60aadad8722aef1ae8e659e758d9a52
MD5 e7a26907cd11f3f2a87794d39e5d88c7
BLAKE2b-256 16dc7cc1961510d8bae938355f34fccebb95422744143f8b33e38ee32f2058ac

See more details on using hashes here.

File details

Details for the file langchain_fireworks-1.0.0a1-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_fireworks-1.0.0a1-py3-none-any.whl
Algorithm Hash digest
SHA256 6b555816da1edab4f6dd2f4176fab1ba1de433611be0a771150c066b1792a994
MD5 d6460f078e0b23d06ad7d58d14ba0400
BLAKE2b-256 1cf21f7b4f49a815567a017db4bdba0f1ce70eb72f1ddfb34d6f06287f74815f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page