Skip to content

Commit 0d55bc9

Browse files
committed
Progress
1 parent 96afcfb commit 0d55bc9

4 files changed

Lines changed: 28 additions & 11 deletions

File tree

src/api/providers/pearai/pearai.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ interface PearAiModelsResponse {
2323

2424
export class PearAiHandler extends BaseProvider implements SingleCompletionHandler {
2525
private handler!: AnthropicHandler | PearAIGenericHandler
26+
private pearAiModelsResponse: PearAiModelsResponse | null = null
27+
private options: ApiHandlerOptions
2628

2729
constructor(options: ApiHandlerOptions) {
2830
super()
@@ -42,6 +44,7 @@ export class PearAiHandler extends BaseProvider implements SingleCompletionHandl
4244
} else {
4345
vscode.commands.executeCommand("pearai.checkPearAITokens", undefined)
4446
}
47+
this.options = options
4548

4649
this.handler = new PearAIGenericHandler({
4750
...options,
@@ -66,6 +69,7 @@ export class PearAiHandler extends BaseProvider implements SingleCompletionHandl
6669
throw new Error(`Failed to fetch models: ${response.statusText}`)
6770
}
6871
const data = (await response.json()) as PearAiModelsResponse
72+
this.pearAiModelsResponse = data
6973
const underlyingModel = data.models[modelId]?.underlyingModelUpdated || "claude-3-5-sonnet-20241022"
7074
if (underlyingModel.startsWith("claude") || modelId.startsWith("anthropic/")) {
7175
// Default to Claude
@@ -110,6 +114,23 @@ export class PearAiHandler extends BaseProvider implements SingleCompletionHandl
110114
}
111115

112116
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+
}
132+
}
133+
}
113134
const baseModel = this.handler.getModel()
114135
return baseModel
115136
}

src/shared/pearaiApi.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,4 @@ export const allModels: { [key: string]: ModelInfo } = {
130130

131131
// Unbound models (single default model)
132132
[`unbound/${unboundDefaultModelId}`]: unboundDefaultModelInfo,
133-
134-
// PearAI models
135-
...Object.entries(pearAiModels).reduce(
136-
(acc, [key, value]) => ({
137-
...acc,
138-
[key]: value,
139-
}),
140-
{},
141-
),
142133
} as const satisfies Record<string, ModelInfo>

webview-ui/src/components/chat/TaskHeader.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import Thumbnails from "../common/Thumbnails"
1818
import { normalizeApiConfiguration } from "../settings/ApiOptions"
1919
import { DeleteTaskDialog } from "../history/DeleteTaskDialog"
2020
import { vscBadgeBackground, vscEditorBackground, vscInputBackground } from "../ui"
21+
import { usePearAiModels } from "@/hooks/usePearAiModels"
2122

2223
interface TaskHeaderProps {
2324
task: ClineMessage
@@ -44,7 +45,11 @@ const TaskHeader: React.FC<TaskHeaderProps> = ({
4445
}) => {
4546
const { t } = useTranslation()
4647
const { apiConfiguration, currentTaskItem } = useExtensionState()
47-
const { selectedModelInfo } = useMemo(() => normalizeApiConfiguration(apiConfiguration), [apiConfiguration])
48+
const pearAiModels = usePearAiModels(apiConfiguration)
49+
const { selectedModelInfo } = useMemo(() => {
50+
return normalizeApiConfiguration(apiConfiguration, pearAiModels)
51+
}, [apiConfiguration, pearAiModels])
52+
4853
const [isTaskExpanded, setIsTaskExpanded] = useState(true)
4954
const [isTextExpanded, setIsTextExpanded] = useState(false)
5055
const [showSeeMore, setShowSeeMore] = useState(false)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1692,7 +1692,7 @@ export function normalizeApiConfiguration(
16921692
// Always use the models from the hook which are fetched when provider is selected
16931693
let query = pearAiModelsQuery
16941694
console.log("query", query)
1695-
return getProviderData(pearAiModelsQuery || allModels, pearAiDefaultModelId)
1695+
return getProviderData(pearAiModelsQuery || {}, pearAiDefaultModelId)
16961696
}
16971697
default:
16981698
return getProviderData(anthropicModels, anthropicDefaultModelId)

0 commit comments

Comments
 (0)