@@ -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,17 @@ 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+ console . log ( "NOT AMAZING" )
69+ throw new Error ( "PearAI models not found" )
70+ } else {
71+ console . log ( "AMAZING" )
7072 }
71- const data = ( await response . json ( ) ) as PearAiModelsResponse
72- this . pearAiModelsResponse = data
73+ const pearaiAgentModels = options . pearaiAgentModels
74+ this . pearAIAgentModels = pearaiAgentModels
7375 const underlyingModel =
74- data . models [ modelId ] ?. underlyingModelUpdated ?. underlyingModel ||
75- data . models [ modelId ] ?. underlyingModel ||
76+ pearaiAgentModels . models [ modelId ] ?. underlyingModelUpdated ?. underlyingModel ||
77+ pearaiAgentModels . models [ modelId ] ?. underlyingModel ||
7678 "claude-3-5-sonnet-20241022"
7779 if ( underlyingModel . startsWith ( "claude" ) || modelId . startsWith ( "anthropic/" ) ) {
7880 // Default to Claude
@@ -120,9 +122,9 @@ export class PearAiHandler extends BaseProvider implements SingleCompletionHandl
120122 if ( this . options . apiModelId ) {
121123 let modelInfo = null
122124 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" ]
125+ modelInfo = this . pearAIAgentModels ?. models [ this . options . apiModelId ] . underlyingModelUpdated
126+ } else if ( this . pearAIAgentModels ) {
127+ modelInfo = this . pearAIAgentModels . models [ this . options . apiModelId || "pearai-model" ]
126128 }
127129 if ( modelInfo ) {
128130 return {
0 commit comments