Skip to content

Commit 3b5d84f

Browse files
committed
Added fallback model
1 parent 39e16a6 commit 3b5d84f

2 files changed

Lines changed: 30 additions & 17 deletions

File tree

src/api/providers/anthropic.ts

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -259,20 +259,8 @@ export class AnthropicHandler extends BaseProvider implements SingleCompletionHa
259259
defaultMaxTokens: ANTHROPIC_DEFAULT_MAX_TOKENS,
260260
}),
261261
}
262-
if (result.info.contextWindow === undefined) {
263-
result.info = {
264-
maxTokens: 8192,
265-
contextWindow: 200_000,
266-
supportsImages: true,
267-
supportsComputerUse: true,
268-
supportsPromptCache: true,
269-
inputPrice: 3.0,
270-
outputPrice: 15.0,
271-
cacheWritesPrice: 3.75,
272-
cacheReadsPrice: 0.3,
273-
}
274-
}
275-
if (result.info.contextWindow === undefined) {
262+
// If model info is missing or has undefined context window, use fallback
263+
if (!result.info || !result.info.contextWindow) {
276264
result.info = fallbackModelInfo
277265
}
278266
return result
@@ -285,7 +273,7 @@ export class AnthropicHandler extends BaseProvider implements SingleCompletionHa
285273
virtualId, // Include the original ID to use for header selection
286274
...getModelParams({ options: this.options, model: info, defaultMaxTokens: ANTHROPIC_DEFAULT_MAX_TOKENS }),
287275
}
288-
if (result.info.contextWindow === undefined) {
276+
if (!result.info || !result.info.contextWindow) {
289277
result.info = fallbackModelInfo
290278
}
291279
return result

src/api/providers/pearai/pearaiGeneric.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,20 @@ export class PearAIGenericHandler extends BaseProvider implements SingleCompleti
222222

223223
override getModel(): { id: string; info: ModelInfo } {
224224
const modelId = this.options.openAiModelId ?? "none"
225+
226+
// PATCH for issue with update
227+
const fallbackModelInfo: ModelInfo = {
228+
maxTokens: 8192,
229+
contextWindow: 200_000,
230+
supportsImages: true,
231+
supportsComputerUse: true,
232+
supportsPromptCache: true,
233+
inputPrice: 3.0,
234+
outputPrice: 15.0,
235+
cacheWritesPrice: 3.75,
236+
cacheReadsPrice: 0.3,
237+
}
238+
225239
// Prioritize serverside model info
226240
if (this.options.apiModelId && this.options.pearaiAgentModels) {
227241
let modelInfo = null
@@ -231,16 +245,27 @@ export class PearAIGenericHandler extends BaseProvider implements SingleCompleti
231245
modelInfo = this.options.pearaiAgentModels.models[this.options.apiModelId || "pearai-model"]
232246
}
233247
if (modelInfo) {
234-
return {
248+
const result = {
235249
id: this.options.apiModelId,
236250
info: modelInfo,
237251
}
252+
// If model info is missing or has undefined context window, use fallback
253+
if (!result.info || !result.info.contextWindow) {
254+
result.info = fallbackModelInfo
255+
}
256+
return result
238257
}
239258
}
240-
return {
259+
260+
const result = {
241261
id: modelId,
242262
info: allModels[modelId],
243263
}
264+
// If model info is missing or has undefined context window, use fallback
265+
if (!result.info || !result.info.contextWindow) {
266+
result.info = fallbackModelInfo
267+
}
268+
return result
244269
}
245270

246271
async completePrompt(prompt: string): Promise<string> {

0 commit comments

Comments
 (0)