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.4.1.tar.gz (5.9 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.1-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for llama_index_llms_fireworks-0.4.1.tar.gz
Algorithm Hash digest
SHA256 ed961d5727c02811c8983a5187d34f7a84200fca8c5916f0bcd1f7fc87a608f3
MD5 abaf5acf1d007e7356df1323bf323608
BLAKE2b-256 7e8434c529230fcdf1f9fd198b2da934e54c4570f45081554890742880ff0467

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llama_index_llms_fireworks-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5351e9ffca1885d39a9ac82cd0d69a9d0a8ca6a1eeb751ef27dadf1cda159be9
MD5 634d5e8cb1a293632235c6b339ebfca3
BLAKE2b-256 1c494ad4ab2db5fc948f347254039b6d7b98e269c8708de9f8df1ff6f3ef55d0

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