Public
Edited
Sep 1, 2024
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
config = modelConfig(model)
Insert cell
aiChatResponse = {
const config = modelConfig(model);
if (config.type !== "chat") return this;
const response = await fetch(config.api, {
method: "POST",
headers: {
"Content-Type": "application/json",
...config.headers()
},
body: JSON.stringify({
model: model,
messages: [
{
role: "system" in config.roles ? "system" : "user",
content: input
}
],
...config.settings
})
});

if (response.status !== 200)
throw new Error(`${response.status}: ${await response.text()}`);
return normalizeChatResponse(response.json());
}
Insert cell
normalizeChatResponse = (response) => {
if (response.content) {
response.choices = response.content.map((content) => ({
message: {
role: response.role,
content: content.text
}
}));
}
return response;
}
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