Public
Edited
Sep 4, 2023
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
basePath = "https://openai-proxy-xi-rose.vercel.app/v1"
Insert cell
Insert cell
defaultMaxTokens = undefined
Insert cell
defaultChatModel = "gpt-3.5-turbo"
Insert cell
defaultTextModel = "text-davinci-003"
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
async function completeText(prompt, temperature, maxTokens) {
return openai.createCompletion({
model: textModel,
prompt,
temperature: temperature || 0,
max_tokens: maxTokens || defaultMaxTokens
});
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
async function completeChat(prompts, temperature, maxTokens) {
const messages = _.map(_.isArray(prompts) ? prompts : [prompts], (prompt) => {
if (_.isString(prompt)) {
return {
role: "user",
content: prompt
};
}

return prompt;
});

return openai.createChatCompletion({
model: chatModel,
messages,
temperature: temperature || 0,
max_tokens: maxTokens || defaultMaxTokens
});
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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