Fireworks
Working with Fireworks AI in PixeltableΒΆ
Pixeltable's Fireworks integration enables you to access advanced large language models (LLMs) hosted on the Fireworks platform.
PrerequisitesΒΆ
- A Fireworks account with an API key (https://fireworks.ai/api-keys)
Important NotesΒΆ
- Fireworks usage may incur costs based on your Fireworks plan.
- Be mindful of sensitive data and consider security measures when integrating with external services.
InΒ [Β ]:
%pip install -q pixeltable fireworks-ai
InΒ [1]:
import pixeltable as pxt
pxt.create_dir('fireworks_demo', ignore_errors=True)
Connected to Pixeltable database at: postgresql://postgres:@/pixeltable?host=/Users/asiegel/.pixeltable/pgdata Created directory `fireworks_demo`.
Securely store your Fireworks API key by not hardcoding it into the notebook.
InΒ [2]:
import os
import getpass
if 'FIREWORKS_API_KEY' not in os.environ:
os.environ['FIREWORKS_API_KEY'] = getpass.getpass('Fireworks API Key:')
CompletionsΒΆ
Create a Table: In Pixeltable, create a table with columns to represent your input data and the columns where you want to store the results from Fireworks.
InΒ [3]:
from pixeltable.functions.fireworks import chat_completions
# Create a table in Pixeltable and pick a model hosted on Fireworks with some parameters
t = pxt.create_table('fireworks_demo.chat', {'input': pxt.StringType()})
messages = [{'role': 'user', 'content': t.input}]
t['output'] = chat_completions(
messages=messages,
model='accounts/fireworks/models/llama-v2-7b-chat',
# These parameters are optional and can be used to tune model behavior:
max_tokens=300,
top_k=40,
top_p=0.9,
temperature=0.7
)
Created table `chat`. Added 0 column values with 0 errors.
InΒ [4]:
# Parse the bot_response into a new column
t['response'] = t.output.choices[0].message.content
Added 0 column values with 0 errors.
InΒ [5]:
# Start a conversation
t.insert(input="Can you tell me who's the President of the US?")
t.select(t.input, t.response).show()
Computing cells: 100%|ββββββββββββββββββββββββββββββββββββββββββββ| 2/2 [00:00<00:00, 3.49 cells/s] Inserting rows into `chat`: 1 rows [00:00, 219.10 rows/s] Computing cells: 100%|ββββββββββββββββββββββββββββββββββββββββββββ| 2/2 [00:00<00:00, 3.42 cells/s] Inserted 1 row with 0 errors.
Out[5]:
input | response |
---|---|
Can you tell me who's the President of the US? | Of course! I'm happy to help you with that! The current President of the United States is Joe Biden. I'm just an AI, I don't have personal opinions or beliefs, and I strive to provide accurate and unbiased information. Please let me know if you have any other questions! |
Learn MoreΒΆ
To learn more about advanced techniques like RAG operations in Pixeltable, check out the RAG Operations in Pixeltable tutorial.
If you have any questions, don't hesitate to reach out.
Updated about 1 month ago