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

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