Skip to main content

llama-index llms fireworks integration

Project description

LlamaIndex Llms Integration: Fireworks

Installation

  1. Install the required Python packages:

    %pip install llama-index-llms-fireworks
    %pip install llama-index
    
  2. Set the Fireworks API key as an environment variable or pass it directly to the class constructor.

Usage

Basic Completion

To generate a simple completion, use the complete method:

from llama_index.llms.fireworks import Fireworks

resp = Fireworks().complete("Paul Graham is ")
print(resp)

Example output:

Paul Graham is a well-known essayist, programmer, and startup entrepreneur. He co-founded Y Combinator, which supported startups like Dropbox, Airbnb, and Reddit.

Basic Chat

To simulate a chat with multiple messages:

from llama_index.core.llms import ChatMessage
from llama_index.llms.fireworks import Fireworks

messages = [
    ChatMessage(
        role="system", content="You are a pirate with a colorful personality"
    ),
    ChatMessage(role="user", content="What is your name"),
]
resp = Fireworks().chat(messages)
print(resp)

Example output:

Arr matey, ye be askin' for me name? Well, I be known as Captain Redbeard the Terrible!

Streaming Completion

To stream a response in real-time using stream_complete:

from llama_index.llms.fireworks import Fireworks

llm = Fireworks()
resp = llm.stream_complete("Paul Graham is ")

for r in resp:
    print(r.delta, end="")

Example output (partial):

Paul Graham is a well-known essayist, programmer, and venture capitalist...

Streaming Chat

For a streamed conversation, use stream_chat:

from llama_index.llms.fireworks import Fireworks
from llama_index.core.llms import ChatMessage

llm = Fireworks()
messages = [
    ChatMessage(
        role="system", content="You are a pirate with a colorful personality"
    ),
    ChatMessage(role="user", content="What is your name"),
]
resp = llm.stream_chat(messages)

for r in resp:
    print(r.delta, end="")

Example output (partial):

Arr matey, ye be askin' for me name? Well, I be known as Captain Redbeard the Terrible...

Model Configuration

To configure the model for more specific behavior:

from llama_index.llms.fireworks import Fireworks

llm = Fireworks(model="accounts/fireworks/models/firefunction-v1")
resp = llm.complete("Paul Graham is ")
print(resp)

Example output:

Paul Graham is an English-American computer scientist, entrepreneur, venture capitalist, and blogger.

API Key Configuration

To use separate API keys for different instances:

from llama_index.llms.fireworks import Fireworks

llm = Fireworks(
    model="accounts/fireworks/models/firefunction-v1", api_key="YOUR_API_KEY"
)
resp = llm.complete("Paul Graham is ")
print(resp)

LLM Implementation example

https://docs.llamaindex.ai/en/stable/examples/llm/fireworks/

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

llama_index_llms_fireworks-0.2.2.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file llama_index_llms_fireworks-0.2.2.tar.gz.

File metadata

  • Download URL: llama_index_llms_fireworks-0.2.2.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.12 Linux/6.8.0-1014-azure

File hashes

Hashes for llama_index_llms_fireworks-0.2.2.tar.gz
Algorithm Hash digest
SHA256 51c587c64868afb9d7c04f93740718720acdf657c35f6468de86e936772df8b2
MD5 2a0f76c680a26f0bd04ba8ca3c2375c5
BLAKE2b-256 4d0a33d4c57dff44cd40713a52344416c47e48d9524144cfb864bf69adaf8bc1

See more details on using hashes here.

File details

Details for the file llama_index_llms_fireworks-0.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for llama_index_llms_fireworks-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 cbf37408b4ccf97a366e197b4ca2f5ed9038b1ec45ea38f0c1ad658d0295eeb8
MD5 8091c78f544439935c4bdf6b4c90a71e
BLAKE2b-256 b5caca890d121708f3a49160e8851e7e9a4e4513a4779cd1db40d7a251623d7b

See more details on using hashes here.

Supported by

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