@@ -11,7 +11,7 @@ import { OpenAiHandler } from "../openai"
1111import { PearAIGenericHandler } from "./pearaiGeneric"
1212import { PEARAI_URL } from "../../../shared/pearaiApi"
1313
14- interface PearAiModelsResponse {
14+ export interface PearAIAgentModelsConfig {
1515 models : {
1616 [ key : string ] : {
1717 underlyingModel ?: { [ key : string ] : any }
@@ -23,7 +23,7 @@ interface PearAiModelsResponse {
2323
2424export class PearAiHandler extends BaseProvider implements SingleCompletionHandler {
2525 private handler ! : AnthropicHandler | PearAIGenericHandler
26- private pearAiModelsResponse : PearAiModelsResponse | null = null
26+ private pearAIAgentModels : PearAIAgentModelsConfig | null = null
2727 private options : ApiHandlerOptions
2828
2929 constructor ( options : ApiHandlerOptions ) {
@@ -64,15 +64,13 @@ export class PearAiHandler extends BaseProvider implements SingleCompletionHandl
6464
6565 if ( modelId . startsWith ( "pearai" ) ) {
6666 try {
67- const response = await fetch ( `${ PEARAI_URL } /getPearAIAgentModels` )
68- if ( ! response . ok ) {
69- throw new Error ( `Failed to fetch models: ${ response . statusText } ` )
67+ if ( ! options . pearaiAgentModels ) {
68+ throw new Error ( "PearAI models not found" )
7069 }
71- const data = ( await response . json ( ) ) as PearAiModelsResponse
72- this . pearAiModelsResponse = data
70+ const pearaiAgentModels = options . pearaiAgentModels
7371 const underlyingModel =
74- data . models [ modelId ] ?. underlyingModelUpdated ?. underlyingModel ||
75- data . models [ modelId ] ?. underlyingModel ||
72+ pearaiAgentModels . models [ modelId ] ?. underlyingModelUpdated ?. underlyingModel ||
73+ pearaiAgentModels . models [ modelId ] ?. underlyingModel ||
7674 "claude-3-5-sonnet-20241022"
7775 if ( underlyingModel . startsWith ( "claude" ) || modelId . startsWith ( "anthropic/" ) ) {
7876 // Default to Claude
@@ -116,26 +114,7 @@ export class PearAiHandler extends BaseProvider implements SingleCompletionHandl
116114 }
117115 }
118116
119- getModel ( ) : { id : string ; info : ModelInfo } {
120- if ( this . options . apiModelId ) {
121- let modelInfo = null
122- if ( this . options . apiModelId . startsWith ( "pearai" ) ) {
123- modelInfo = this . pearAiModelsResponse ?. models [ this . options . apiModelId ] . underlyingModelUpdated
124- } else if ( this . pearAiModelsResponse ) {
125- modelInfo = this . pearAiModelsResponse . models [ this . options . apiModelId || "pearai-model" ]
126- }
127- if ( modelInfo ) {
128- return {
129- id : this . options . apiModelId ,
130- info : {
131- contextWindow : modelInfo . contextWindow || 4096 , // provide default or actual value
132- supportsPromptCache : modelInfo . supportsPromptCaching || false , // provide default or actual value
133- ...modelInfo ,
134- } ,
135- }
136- }
137- }
138-
117+ public getModel ( ) : { id : string ; info : ModelInfo } {
139118 // Fallback to using what's available on client side
140119 const baseModel = this . handler . getModel ( )
141120 return baseModel
0 commit comments