Skip to content

Latest commit

 

History

History

openai-callout

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Overview

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.

Set up

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:

Running

Assume you have an OpenAI API key in the environment variable OPENAI_API_KEY

sdf run -e OPENAI_API_KEY=$OPENAI_API_KEY

Inputing text

Send the sentences you want to enrich to the topic sentence:

fluvio produce sentence
gpt-4 tell me a story about boy and wolf

Reading output

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!

Clean-up

Exit sdf terminal and clean-up. The --force flag removes the topics:

sdf clean --force