@@ -14,7 +14,7 @@ import { PEARAI_URL } from "../../../shared/pearaiApi"
1414interface PearAiModelsResponse {
1515 models : {
1616 [ key : string ] : {
17- underlyingModel ?: string
17+ underlyingModel ?: { [ key : string ] : any }
1818 [ key : string ] : any
1919 }
2020 }
@@ -70,7 +70,10 @@ export class PearAiHandler extends BaseProvider implements SingleCompletionHandl
7070 }
7171 const data = ( await response . json ( ) ) as PearAiModelsResponse
7272 this . pearAiModelsResponse = data
73- const underlyingModel = data . models [ modelId ] ?. underlyingModelUpdated || "claude-3-5-sonnet-20241022"
73+ const underlyingModel =
74+ data . models [ modelId ] ?. underlyingModelUpdated ?. underlyingModel ||
75+ data . models [ modelId ] ?. underlyingModel ||
76+ "claude-3-5-sonnet-20241022"
7477 if ( underlyingModel . startsWith ( "claude" ) || modelId . startsWith ( "anthropic/" ) ) {
7578 // Default to Claude
7679 this . handler = new AnthropicHandler ( {
@@ -114,25 +117,25 @@ export class PearAiHandler extends BaseProvider implements SingleCompletionHandl
114117 }
115118
116119 getModel ( ) : { id : string ; info : ModelInfo } {
117- if (
118- this . pearAiModelsResponse &&
119- this . options . apiModelId === "pearai-model" &&
120- this . pearAiModelsResponse . models
121- ) {
122- const modelInfo = this . pearAiModelsResponse . models [ this . options . apiModelId ]
123- if ( modelInfo ) {
124- return {
125- id : this . options . apiModelId ,
126- info : {
127- contextWindow : modelInfo . contextWindow || 4096 , // provide default or actual value
128- supportsPromptCache : modelInfo . supportsPromptCaching || false , // provide default or actual value
129- ...modelInfo ,
130- } ,
131- }
120+ if ( this . options . apiModelId ) {
121+ let modelInfo = null
122+ if ( this . options . apiModelId === "pearai-model" ) {
123+ modelInfo = this . pearAiModelsResponse ?. models [ "pearai-model" ] . underlyingModelUpdated
124+ } else if ( this . pearAiModelsResponse ) {
125+ modelInfo = this . pearAiModelsResponse . models [ this . options . apiModelId || "pearai-model" ]
126+ }
127+ return {
128+ id : this . options . apiModelId ,
129+ info : {
130+ contextWindow : modelInfo . contextWindow || 4096 , // provide default or actual value
131+ supportsPromptCache : modelInfo . supportsPromptCaching || false , // provide default or actual value
132+ ...modelInfo ,
133+ } ,
132134 }
135+ } else {
136+ const baseModel = this . handler . getModel ( )
137+ return baseModel
133138 }
134- const baseModel = this . handler . getModel ( )
135- return baseModel
136139 }
137140
138141 async * createMessage ( systemPrompt : string , messages : any [ ] ) : AsyncGenerator < any > {
0 commit comments