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());
}