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
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.7, 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')]
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 Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
File details
Details for the file fireworks_ai-0.3.2a1-py3-none-any.whl
.
File metadata
- Download URL: fireworks_ai-0.3.2a1-py3-none-any.whl
- Upload date:
- Size: 41.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.66.1 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ecf76af7efde81e3a76f1891898442ae781ad832becc9ea2a1d2082319513d1 |
|
MD5 | c7d1af4e74cca189fd319f53629f307a |
|
BLAKE2b-256 | ba3333ce4cf1b63a5a35d27a55b64053627cd0d98229afb29038fd627a7a317e |