Public
Edited
Oct 19, 2023
Insert cell
Insert cell
Insert cell
Insert cell
openaiAPIKey = Secret("OPENAI_API_KEY")
Insert cell
Insert cell
Insert cell
Insert cell
async function getChatGPTCompletionStream(
prompt,
{ model = "gpt-3.5-turbo", temperature = 0.0 } = {}
) {
const outputElement = document.getElementById("chatgpt-output");
outputElement.textContent = "";

if (prompt.length == 0) {
return;
}

const messages = [{ role: "user", content: prompt }];
const stream = await openai.chat.completions.create({
model: model,
messages: messages,
temperature: temperature,
stream: true
});

for await (const part of stream) {
const text = part.choices[0]?.delta?.content || "";
outputElement.textContent += text;
}
}
Insert cell
getChatGPTCompletionStream(chatgptParams.prompt, {
temperature: chatgptParams.temperature,
model: chatgptParams.model
})
Insert cell
Insert cell
openai = {
const openai = await import("https://cdn.skypack.dev/openai@4.10.0?min");
return new openai.OpenAI({
apiKey: openaiAPIKey,
dangerouslyAllowBrowser: true
});
}
Insert cell
models = {
const listModels = await openai.models.list();
return listModels.data.map((d) => d.id).filter((s) => s.startsWith("gpt"));
}
Insert cell
import { guard } from "@mootari/inputs-submit"
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more