Skip to content

Commit 738e6be

Browse files
authored
Merge pull request #54 from trypear/server-config
Added use config from server
2 parents 2215266 + 58a6061 commit 738e6be

3 files changed

Lines changed: 34 additions & 21 deletions

File tree

src/api/providers/pearai/pearai.ts

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { PEARAI_URL } from "../../../shared/pearaiApi"
1414
interface 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> {

src/shared/api.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,9 @@ export interface ModelInfo {
159159
description?: string
160160
reasoningEffort?: "low" | "medium" | "high"
161161
thinking?: boolean
162+
underlyingModel?: string
163+
underlyingModelUpdated?: Record<string, any>
162164
}
163-
164165
// Anthropic
165166
// https://docs.anthropic.com/en/docs/about-claude/models
166167
export type AnthropicModelId = keyof typeof anthropicModels

webview-ui/src/components/settings/ApiOptions.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1598,7 +1598,16 @@ export function normalizeApiConfiguration(
15981598

15991599
if (modelId && modelId in models) {
16001600
selectedModelId = modelId
1601-
selectedModelInfo = models[modelId]
1601+
if (modelId === "pearai-model" && models[modelId].underlyingModelUpdated) {
1602+
let modelInfo = models[modelId].underlyingModelUpdated
1603+
selectedModelInfo = {
1604+
contextWindow: modelInfo.contextWindow || 4096, // provide default or actual value
1605+
supportsPromptCache: modelInfo.supportsPromptCaching || false, // provide default or actual value
1606+
...modelInfo,
1607+
}
1608+
} else {
1609+
selectedModelInfo = models[modelId]
1610+
}
16021611
} else {
16031612
selectedModelId = defaultId
16041613
selectedModelInfo = models[defaultId]

0 commit comments

Comments
 (0)