Simple example of using the OpenAI API to generate text. It counds the number of attempts by model. The input is a model followed by sentence.
For example, the following input:
hello world
use default gpt-3.5-turbo model to generate text.
But the following input:
gpt-4 hello world
use gpt-4 model to generate text.
You must have account at OpenApi and setup an API key. You can then set the API key in the environment variable OPENAI_API_KEY
.
Before you start:
- Checkout the dataflow.yaml.
- Make sure to Install SDF and start a Fluvio cluster.
Assume you have an OpenAI API key in the environment variable OPENAI_API_KEY
sdf run -e OPENAI_API_KEY=$OPENAI_API_KEY
Send the sentences you want to enrich to the topic sentence
:
fluvio produce sentence
gpt-4 tell me a story about boy and wolf
Consume from output
to see the result:
fluvio consume output -B
{"model":"gpt-4","output":"Once upon a time, there was a boy who cried wolf...", "total_attempts": 1}
Congratulations! You've successfully built and run a dataflow!
Exit sdf
terminal and clean-up. The --force
flag removes the topics:
sdf clean --force