Prefect integrations for working with OpenAI.
Project description
prefect-openai
Visit the full docs here to see additional examples and the API reference.
Welcome!
Prefect integrations for working with OpenAI.
Getting Started
Python setup
Requires an installation of Python 3.7+.
We recommend using a Python virtual environment manager such as pipenv, conda or virtualenv.
These tasks are designed to work with Prefect 2.0. For more information about how to use Prefect, please refer to the Prefect documentation.
Installation
Install prefect-openai
with pip
:
pip install prefect-openai
A list of available blocks in prefect-openai
and their setup instructions can be found here.
Write and run a flow
Retrieve the flow run name to create a story about it and an image using that story.
from prefect import flow, get_run_logger
from prefect.context import get_run_context
from prefect_openai import OpenAICredentials, ImageModel, CompletionModel
@flow
def create_story_and_image_from_flow_run_name():
logger = get_run_logger()
context = get_run_context()
flow_run_name = context.flow_run.name.replace("-", " ")
credentials = OpenAICredentials.load("my-block")
text_model = CompletionModel(openai_credentials=credentials, model="text-ada-001")
text_prompt = f"Story about a {flow_run_name}"
text_result = text_model.submit_prompt(text_prompt)
image_prompt = text_result.choices[0].text.strip()
image_model = ImageModel(openai_credentials=credentials)
image_result = image_model.submit_prompt(image_prompt)
image_url = image_result.data[0]["url"]
logger.info(
f"The story behind the image, {image_prompt!r}, "
f"check it out here: {image_url}"
)
return image_url
create_image()
For example, a flow run named space-orangutan
prompted a story about "A space orangutan is a species of monkey that live in and..." yielding this image:
For more tips on how to use tasks and flows in a Collection, check out Using Collections!
Resources
If you encounter any bugs while using prefect-openai
, feel free to open an issue in the prefect-openai repository.
If you have any questions or issues while using prefect-openai
, you can find help in either the Prefect Discourse forum or the Prefect Slack community.
Feel free to star or watch prefect-openai
for updates too!
Contributing
If you'd like to help contribute to fix an issue or add a feature to prefect-openai
, please propose changes through a pull request from a fork of the repository.
Here are the steps:
- Fork the repository
- Clone the forked repository
- Install the repository and its dependencies:
pip install -e ".[dev]"
- Make desired changes
- Add tests
- Insert an entry to CHANGELOG.md
- Install
pre-commit
to perform quality checks prior to commit:
pre-commit install
git commit
,git push
, and create a pull request
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for prefect_openai-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c17ad2cc125443eb33baef5cb7ca5ec17b51eb4a83fcdcc41ca9177206c45d45 |
|
MD5 | 63653929d315fa39299cbf6c9aa117a3 |
|
BLAKE2b-256 | 83c97a88b4ec78e9a8911d0b682c2beaeb2ed3c829190e523328aeb38e3b3155 |