Skip to main content

Python client library for the Fireworks.ai Generative AI Platform

Project description

Fireworks.ai Python library

Fireworks.ai Python Library provides a convenient API for accessing Fireworks supported LLMs. We are targeting our API to be very similar to OpenAI's API so you can replace OpenAI usage with minimal modifications

Installation

pip install --upgrade fireworks-ai

API definitions

Please check our completion and chat completion API reference for the arguments we support and the meaning of each arguments.

Example code

List

import fireworks.client
fireworks.client.api_key = "your-key"
print(fireworks.client.Models.list())
object='list' data=[Model(id="accounts/fireworks/models/llama-v2-7b", object="model", created=0), ...]

Completion

import fireworks.client
fireworks.client.api_key = "your-key"
completion = fireworks.client.Completion.create("accounts/fireworks/models/llama-v2-7b", "Once upon a time", temperature=0.1, n=2, max_tokens=16)
print(completion)
id='cmpl-988e179fa14fbaebdf17c713' object='text_completion' created=1691602259 model='accounts/fireworks/models/llama-v2-7b' choices=[Choice(text=', there was an emperor who reigned over all the kingdoms of the', index=0, finish_reason='length'), Choice(text=', a boy lived in a small house with his mom and dad. His', index=1, finish_reason='length')]

Streaming completion

import fireworks.client
fireworks.client.api_key = "your-key"
for completion in fireworks.client.Completion.create(
    "accounts/fireworks/models/llama-v2-7b",
    prompt="Once upon a time",
    temperature=0.1,
    n=2,
    max_tokens=16
):
    print(completion)

Async completion

import asyncio
import fireworks.client
fireworks.client.api_key = "your-key"
async def main():
    response = await fireworks.client.Completion.acreate("accounts/fireworks/models/llama-v2-7b", "Once upon a time", echo=True, max_tokens=16)
    print(response.choices[0].text)
asyncio.run(main())

then run the script

$ python test.py
Once upon a time, there used to be a huge mountain that was the most famous mou

ChatCompletion

import fireworks.client
fireworks.client.api_key = "your-key"
completion = fireworks.client.ChatCompletion.create(
    "accounts/fireworks/models/llama-v2-7b-chat",
    messages=[{"role": "user", "content": "Hello there!"}],
    temperature=0.7,
    n=2,
    max_tokens=16
)
print(completion)
id='cmpl-ec241c8f5b8d50bcf792f2df' object='chat.completion' created=1691896960 model='accounts/fireworks/models/llama-v2-7b-chat' choices=[ChatCompletionResponseChoice(index=0, message=ChatMessage(role='assistant', content=" Hello! It's nice to meet you. Is there something I can"), finish_reason='length'), ChatCompletionResponseChoice(index=1, message=ChatMessage(role='assistant', content=" Hello! It's nice to meet you. Is there something I can"), finish_reason='length')] usage=UsageInfo(prompt_tokens=23, total_tokens=55, completion_tokens=32)

Requirements

  • Python 3.9

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

fireworks-ai-0.7.0.tar.gz (59.8 kB view details)

Uploaded Source

Built Distribution

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

fireworks_ai-0.7.0-py3-none-any.whl (74.0 kB view details)

Uploaded Python 3

File details

Details for the file fireworks-ai-0.7.0.tar.gz.

File metadata

  • Download URL: fireworks-ai-0.7.0.tar.gz
  • Upload date:
  • Size: 59.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.12

File hashes

Hashes for fireworks-ai-0.7.0.tar.gz
Algorithm Hash digest
SHA256 72da649f4319b88055fda07dee6ae5ce0aa6d1fef943d62bc0bd818199e2b739
MD5 6983c7813e9ea3e7517976e8f53bb592
BLAKE2b-256 c3b0675d9abbfecdd3459d7c5f4a990c6574d99bb379efd3f01169e0e26cb255

See more details on using hashes here.

File details

Details for the file fireworks_ai-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: fireworks_ai-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 74.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.12

File hashes

Hashes for fireworks_ai-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ac4f771bbae1b5cfa4a75fadf925a0caa33442429d5b8440ef3550a1d3ca6a30
MD5 f9e32aa7c0334297bcbde28c2a5eda4a
BLAKE2b-256 f1984df4dc296b0026cd46d988d56d7a94369a62b15d67d51b5df6d2956d3ae1

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