Public
Edited
Feb 14, 2023
Paused
2 forks
5 stars
Insert cell
Insert cell
Insert cell
import {
viewof openaiApiKey,
completions,
text_edits,
code_edits,
images
} from "@osteele/openai-api"
Insert cell
Insert cell
viewof openaiApiKey
Insert cell
Insert cell
## 3. Text Completion

Use `completions(prompt)` to create a completion for the provided (string) prompt.

The following example wraps the result in `md` in order to format the output.
Insert cell
md`${await completions("Ten ways of using ObservableHQ:")}`

Insert cell
Insert cell
Insert cell
image_urls = await images("A cute baby sea otter", { n: 3, size: 256 })
Insert cell
html`<div style="display:flex;flex-wrap:wrap; justify-content:space-between">${image_urls.map(
(url) => `<img style="padding:5px" src="${url}"/>`
)}</div>`
Insert cell
Insert cell
text_edits("What day of the wek is it?") // OpenAI will correct the typo in "wek"
Insert cell
Insert cell
html`<pre>${await code_edits("print a list of string lengths", {
input: "def print_lengths"
})}</pre>`
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more