OpenAI Playground API Example
This template will show you 3 basic ways you can wrap the OpenAI API
to create your own basic playground.
These are for demonstration purposes to show how easy it is to setup,
so there is plenty of room to expand and get creative with it!
Here is a breakdown of those 3 examples:
Basic chat completion
The first endpoint
/functions/basic-completion.js uses the chat completion
endpoint to generate a basic
response by taking a user
This is the most basic setup you can have when working with OpenAI.
It does not include any system prompt,
but there is a spot on line 12 for you to include one if you like.
Streaming chat completion
With the introduction of the chat completions
endpoints, we also have the ability to stream our response! This means we can
very easily emulate the ChatGPT behavior of building our response one word, or token,
at a time.
Responses from this endpoint utilize the
context.stream functionality to output
partial strings as they are received, which will show up in the Run logs panel
Image generation example
Finally, OpenAI also provides image generation with Dall-E, which we will use to return a dynamic image.
This endpoint showcases how you can use custom HTTP responses to output the generated image as your response: