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/kimi-k2-instruct-0905")
resp = llm.complete("Paul Graham is ")
print(resp)

Example output:

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

For a full list of models, check the Fireworks website.

API Key Configuration

To use separate API keys for different instances:

from llama_index.llms.fireworks import Fireworks

llm = Fireworks(
    model="accounts/fireworks/models/kimi-k2-instruct-0905",
    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.4.5.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

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

llama_index_llms_fireworks-0.4.5-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for llama_index_llms_fireworks-0.4.5.tar.gz
Algorithm Hash digest
SHA256 5635230fdd96b16e573a5b1c010bc2d687a2f3171387f06113169964b5fd6b35
MD5 0331b5f163d9fac16e9087f8c9dbb442
BLAKE2b-256 ec1b1e50b9b644f64767c2e305c1ea19fd8dd6bdd1f0c1cd4684196200108e87

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llama_index_llms_fireworks-0.4.5-py3-none-any.whl
Algorithm Hash digest
SHA256 5381c8dd0184da6a2514cb476be4b5ba5526fa3805a51d746bc6e65c9638c890
MD5 d6d3f8b0e63098a964f815b407f107dc
BLAKE2b-256 0a88ac9b18c0f6edbe6cce291dadaee0b6e088f8d27ac41df9f1b6b4905973e9

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