Skip to content

Commit 6651213

Browse files
Add suggested changes
1 parent f9f619b commit 6651213

File tree

20 files changed

+184
-24
lines changed

20 files changed

+184
-24
lines changed

src/api/providers/cerebras.ts

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import { XmlMatcher } from "../../utils/xml-matcher"
1010

1111
import type { ApiHandlerCreateMessageMetadata, SingleCompletionHandler } from "../index"
1212
import { BaseProvider } from "./base-provider"
13+
import { DEFAULT_HEADERS } from "./constants"
14+
import { t } from "../../i18n"
1315

1416
const CEREBRAS_BASE_URL = "https://api.cerebras.ai/v1"
1517
const CEREBRAS_DEFAULT_TEMPERATURE = 0
@@ -138,9 +140,9 @@ export class CerebrasHandler extends BaseProvider implements SingleCompletionHan
138140
const response = await fetch(`${CEREBRAS_BASE_URL}/chat/completions`, {
139141
method: "POST",
140142
headers: {
143+
...DEFAULT_HEADERS,
141144
"Content-Type": "application/json",
142145
Authorization: `Bearer ${this.apiKey}`,
143-
"User-Agent": "roo-cline/1.0.0",
144146
},
145147
body: JSON.stringify(requestBody),
146148
})
@@ -158,24 +160,22 @@ export class CerebrasHandler extends BaseProvider implements SingleCompletionHan
158160

159161
// Provide more actionable error messages
160162
if (response.status === 401) {
161-
throw new Error(
162-
`Cerebras API authentication failed. Please check your API key is valid and not expired.`,
163-
)
163+
throw new Error(t("common:errors.cerebras.authenticationFailed"))
164164
} else if (response.status === 403) {
165-
throw new Error(
166-
`Cerebras API access forbidden. Your API key may not have access to the requested model or feature.`,
167-
)
165+
throw new Error(t("common:errors.cerebras.accessForbidden"))
168166
} else if (response.status === 429) {
169-
throw new Error(`Cerebras API rate limit exceeded. Please wait before making another request.`)
167+
throw new Error(t("common:errors.cerebras.rateLimitExceeded"))
170168
} else if (response.status >= 500) {
171-
throw new Error(`Cerebras API server error (${response.status}). Please try again later.`)
169+
throw new Error(t("common:errors.cerebras.serverError", { status: response.status }))
172170
} else {
173-
throw new Error(`Cerebras API Error (${response.status}): ${errorMessage}`)
171+
throw new Error(
172+
t("common:errors.cerebras.genericError", { status: response.status, message: errorMessage }),
173+
)
174174
}
175175
}
176176

177177
if (!response.body) {
178-
throw new Error("Cerebras API Error: No response body")
178+
throw new Error(t("common:errors.cerebras.noResponseBody"))
179179
}
180180

181181
// Initialize XmlMatcher to parse <think>...</think> tags
@@ -262,7 +262,7 @@ export class CerebrasHandler extends BaseProvider implements SingleCompletionHan
262262
}
263263
} catch (error) {
264264
if (error instanceof Error) {
265-
throw new Error(`Cerebras API error: ${error.message}`)
265+
throw new Error(t("common:errors.cerebras.completionError", { error: error.message }))
266266
}
267267
throw error
268268
}
@@ -282,9 +282,9 @@ export class CerebrasHandler extends BaseProvider implements SingleCompletionHan
282282
const response = await fetch(`${CEREBRAS_BASE_URL}/chat/completions`, {
283283
method: "POST",
284284
headers: {
285+
...DEFAULT_HEADERS,
285286
"Content-Type": "application/json",
286287
Authorization: `Bearer ${this.apiKey}`,
287-
"User-Agent": "roo-cline/1.0.0",
288288
},
289289
body: JSON.stringify(requestBody),
290290
})
@@ -294,27 +294,25 @@ export class CerebrasHandler extends BaseProvider implements SingleCompletionHan
294294

295295
// Provide consistent error handling with createMessage
296296
if (response.status === 401) {
297-
throw new Error(
298-
`Cerebras API authentication failed. Please check your API key is valid and not expired.`,
299-
)
297+
throw new Error(t("common:errors.cerebras.authenticationFailed"))
300298
} else if (response.status === 403) {
301-
throw new Error(
302-
`Cerebras API access forbidden. Your API key may not have access to the requested model or feature.`,
303-
)
299+
throw new Error(t("common:errors.cerebras.accessForbidden"))
304300
} else if (response.status === 429) {
305-
throw new Error(`Cerebras API rate limit exceeded. Please wait before making another request.`)
301+
throw new Error(t("common:errors.cerebras.rateLimitExceeded"))
306302
} else if (response.status >= 500) {
307-
throw new Error(`Cerebras API server error (${response.status}). Please try again later.`)
303+
throw new Error(t("common:errors.cerebras.serverError", { status: response.status }))
308304
} else {
309-
throw new Error(`Cerebras API Error (${response.status}): ${errorText}`)
305+
throw new Error(
306+
t("common:errors.cerebras.genericError", { status: response.status, message: errorText }),
307+
)
310308
}
311309
}
312310

313311
const result = await response.json()
314312
return result.choices?.[0]?.message?.content || ""
315313
} catch (error) {
316314
if (error instanceof Error) {
317-
throw new Error(`Cerebras completion error: ${error.message}`)
315+
throw new Error(t("common:errors.cerebras.completionError", { error: error.message }))
318316
}
319317
throw error
320318
}

src/i18n/locales/ca/common.json

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/i18n/locales/de/common.json

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/i18n/locales/en/common.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@
8989
"generate_stream": "Gemini generate context stream error: {{error}}",
9090
"generate_complete_prompt": "Gemini completion error: {{error}}",
9191
"sources": "Sources:"
92+
},
93+
"cerebras": {
94+
"authenticationFailed": "Cerebras API authentication failed. Please check your API key is valid and not expired.",
95+
"accessForbidden": "Cerebras API access forbidden. Your API key may not have access to the requested model or feature.",
96+
"rateLimitExceeded": "Cerebras API rate limit exceeded. Please wait before making another request.",
97+
"serverError": "Cerebras API server error ({{status}}). Please try again later.",
98+
"genericError": "Cerebras API Error ({{status}}): {{message}}",
99+
"noResponseBody": "Cerebras API Error: No response body",
100+
"completionError": "Cerebras completion error: {{error}}"
92101
}
93102
},
94103
"warnings": {

src/i18n/locales/es/common.json

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/i18n/locales/fr/common.json

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/i18n/locales/hi/common.json

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/i18n/locales/id/common.json

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/i18n/locales/it/common.json

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/i18n/locales/ja/common.json

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)