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.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
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.15.8.tar.gz
(90.3 kB
view details)
Built Distribution
fireworks_ai-0.15.8-py3-none-any.whl
(111.6 kB
view details)
File details
Details for the file fireworks_ai-0.15.8.tar.gz
.
File metadata
- Download URL: fireworks_ai-0.15.8.tar.gz
- Upload date:
- Size: 90.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ebd86cb582d30e30db018f5087ac923958f74f1e7ad3bdc955c83ef7c5e0fc2d |
|
MD5 | 24a526315d437d74476ca96b1668014a |
|
BLAKE2b-256 | 8571a5f15e80ef218beea4f32b799a66cea12742ad33b98d6261cf63a92f8592 |
File details
Details for the file fireworks_ai-0.15.8-py3-none-any.whl
.
File metadata
- Download URL: fireworks_ai-0.15.8-py3-none-any.whl
- Upload date:
- Size: 111.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7053b571b33948df341f453e878ffef9cc29a58963ad65fdf49607276448031a |
|
MD5 | da0c58d4eefd2e09ad524fae8dc3d99d |
|
BLAKE2b-256 | 9f5e7949224fa9197a2f7d30e12ccd4a351899ce337e244fccd26e0a65d72ff0 |