mirror of
https://github.com/pacnpal/Roo-Code.git
synced 2025-12-20 12:21:13 -05:00
Handles error messages
This commit is contained in:
committed by
Vignesh Subbiah
parent
20d9a88bb4
commit
698ae6566d
@@ -12,32 +12,39 @@ export class UnboundHandler implements ApiHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async *createMessage(systemPrompt: string, messages: Anthropic.Messages.MessageParam[]): ApiStream {
|
async *createMessage(systemPrompt: string, messages: Anthropic.Messages.MessageParam[]): ApiStream {
|
||||||
const response = await fetch(`${this.unboundBaseUrl}/chat/completions`, {
|
try {
|
||||||
method: "POST",
|
const response = await fetch(`${this.unboundBaseUrl}/chat/completions`, {
|
||||||
headers: {
|
method: "POST",
|
||||||
Authorization: `Bearer ${this.options.unboundApiKey}`,
|
headers: {
|
||||||
"Content-Type": "application/json",
|
Authorization: `Bearer ${this.options.unboundApiKey}`,
|
||||||
},
|
"Content-Type": "application/json",
|
||||||
body: JSON.stringify({
|
},
|
||||||
model: this.getModel().id,
|
body: JSON.stringify({
|
||||||
messages: [{ role: "system", content: systemPrompt }, ...messages],
|
model: this.getModel().id,
|
||||||
}),
|
messages: [{ role: "system", content: systemPrompt }, ...messages],
|
||||||
})
|
}),
|
||||||
|
})
|
||||||
|
|
||||||
if (!response.ok) {
|
const data = await response.json()
|
||||||
throw new Error(`HTTP error! status: ${response.status}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
const data = await response.json()
|
if (!response.ok) {
|
||||||
|
throw new Error(data.error)
|
||||||
|
}
|
||||||
|
|
||||||
yield {
|
yield {
|
||||||
type: "text",
|
type: "text",
|
||||||
text: data.choices[0]?.message?.content || "",
|
text: data.choices[0]?.message?.content || "",
|
||||||
}
|
}
|
||||||
yield {
|
yield {
|
||||||
type: "usage",
|
type: "usage",
|
||||||
inputTokens: data.usage?.prompt_tokens || 0,
|
inputTokens: data.usage?.prompt_tokens || 0,
|
||||||
outputTokens: data.usage?.completion_tokens || 0,
|
outputTokens: data.usage?.completion_tokens || 0,
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
throw new Error(`Unbound Gateway completion error: ${error.message}`)
|
||||||
|
}
|
||||||
|
throw error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user