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.Model.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-v3-8b-instruct", "Once upon a time", temperature=0.1, n=2, max_tokens=16)
print(completion)
id='8bd3ac8f-a7d3-4dab-a19e-cea3f9c83f1e' object='text_completion' created=1714831539 model='accounts/fireworks/models/llama-v3-8b-instruct' choices=[Choice(index=0, text=', there was a young girl named Sophia who lived in a small village surrounded by', logprobs=None, finish_reason='length', raw_output=None), Choice(index=1, text=', there was a small village nestled in the heart of a dense forest. The', logprobs=None, finish_reason='length', raw_output=None)] usage=UsageInfo(prompt_tokens=4, total_tokens=36, completion_tokens=32)
Streaming completion
import fireworks.client
fireworks.client.api_key = "your-key"
for completion in fireworks.client.Completion.create(
"accounts/fireworks/models/llama-v3-8b-instruct",
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-v3-8b-instruct", "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-v3-8b-instruct",
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.7
Metadata
Release files for fireworks-ai 0.15.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| fireworks_ai-0.15.5.tar.gz | 87.7 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| fireworks_ai-0.15.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 196.5 kB
Release files / fireworks_ai-0.15.5.tar.gz
| Download URL | fireworks_ai-0.15.5.tar.gz |
|---|---|
| Size | 87.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
19c2e30db205fd2f1d7fa269489d0106fe50cdb60dbc2c4d9da59a89b1b97e63
|
|
BLAKE2b-256 checksum How to use checksums |
f32be3747a6c9ad58968bde32052b58cc53eb9eb2e970337f9c1c9d2de79ca9f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
Release files / fireworks_ai-0.15.5-py3-none-any.whl
| Download URL | fireworks_ai-0.15.5-py3-none-any.whl |
|---|---|
| Size | 108.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8231a23e632034258e337df1383e4a95018df7778b9abaf57e43cf31866c06f4
|
|
BLAKE2b-256 checksum How to use checksums |
2bda7113e21ae471c062a634b613392682bf2c086b4632ac7b9e07c3301076a4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
Security for fireworks-ai 0.15.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.