"url": this.appService.basePath + "api/providers/cloudlyte/v1/chat/completions",
"method": "POST",
"stream": { simulation: 20 }
};
setTimeout(() => {
if (this.chatElementRef) {
const chatEl = this.chatElementRef.nativeElement;
chatEl.connect = {
handler: async (body, signals) => {
const modelsToCall = [...this.selectedModelList];
await Promise.all(modelsToCall.map(async (model) => {
const requestBody = {
model,
messages: [
{
role: 'user',
content: body.messages[0].text
}
]
};
const response = await fetch(this.appService.basePath + "api/providers/cloudlyte/v1/chat/completions", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${this.keyId}`
},
body: JSON.stringify(requestBody)
},)
const result = await response.json();
if (response.status === 401) {
chatEl.addMessage({
text: `${model}:
role: 'ai'
});
} else {
const reply = result?.choices?.[0]?.message?.content || 'No reply received';
chatEl.addMessage({
text: `${model}: ${reply}`,
role: 'ai'
});
}
}))
}
}
}
});
Подробнее здесь: https://stackoverflow.com/questions/796 ... chat-angul