langchain/libs/partners/fireworks
Eugene Yurtsev 5f5e8c9a60
huggingface[patch], pinecone[patch], fireworks[patch], mistralai[patch], voyageai[patch], togetherai[path]: convert Pydantic extras to literals (#25384)
Backwards compatible change that converts pydantic extras to literals
which is consistent with pydantic 2 usage.

- fireworks
- voyage ai
- mistralai
- mistral ai
- together ai
- huggigng face
- pinecone
2024-08-14 09:55:30 -04:00
..
langchain_fireworks huggingface[patch], pinecone[patch], fireworks[patch], mistralai[patch], voyageai[patch], togetherai[path]: convert Pydantic extras to literals (#25384) 2024-08-14 09:55:30 -04:00
scripts fireworks[patch]: Add Fireworks partner packages (#17694) 2024-02-23 20:45:47 +00:00
tests fireworks[patch]: use firefunction-v2 in standard tests (#24264) 2024-07-15 13:15:08 +00:00
.gitignore fireworks[patch]: Add Fireworks partner packages (#17694) 2024-02-23 20:45:47 +00:00
LICENSE fireworks[patch]: Add Fireworks partner packages (#17694) 2024-02-23 20:45:47 +00:00
Makefile infra: update mypy 1.10, ruff 0.5 (#23721) 2024-07-03 10:33:27 -07:00
poetry.lock integrations[patch]: release model packages (#24900) 2024-07-31 20:48:20 +00:00
pyproject.toml integrations[patch]: release model packages (#24900) 2024-07-31 20:48:20 +00:00
README.md Updated partners/fireworks README (#18267) 2024-02-29 14:55:03 -08:00

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/mixtral-8x7b-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 here.

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 fares compares to GPT-4, the punchline is that it is on par with GPT-4 in terms just 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