Skip to content

Commit 2a743ca

Browse files
committed
Implement my own review feedback
1 parent 94b18f0 commit 2a743ca

File tree

24 files changed

+90
-55
lines changed

24 files changed

+90
-55
lines changed

.changeset/pretty-hornets-brake.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
---
2-
"@roo-code/types": minor
32
"kilo-code": minor
43
---
54

6-
feat: add DeepInfra provider with dynamic model fetching and prompt caching
5+
Added DeepInfra provider with dynamic model fetching and prompt caching

packages/types/src/global-settings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,11 @@ export const SECRET_STATE_KEYS = [
203203
"groqApiKey",
204204
"chutesApiKey",
205205
"litellmApiKey",
206-
"deepInfraApiKey",
207206
"codeIndexOpenAiKey",
208207
"codeIndexQdrantApiKey",
209208
// kilocode_change start
210209
"kilocodeToken",
210+
"deepInfraApiKey",
211211
// kilocode_change end
212212
"codebaseIndexOpenAiCompatibleApiKey",
213213
"codebaseIndexGeminiApiKey",

packages/types/src/provider-settings.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ export const providerNames = [
5353
"fake-ai",
5454
"xai",
5555
"groq",
56-
"deepinfra",
5756
"chutes",
5857
"litellm",
5958
// kilocode_change start
6059
"kilocode",
60+
"deepinfra",
6161
"gemini-cli",
6262
"virtual-quota-fallback",
6363
"qwen-code",
@@ -249,12 +249,6 @@ const deepSeekSchema = apiModelIdProviderModelSchema.extend({
249249
deepSeekApiKey: z.string().optional(),
250250
})
251251

252-
const deepInfraSchema = apiModelIdProviderModelSchema.extend({
253-
deepInfraBaseUrl: z.string().optional(),
254-
deepInfraApiKey: z.string().optional(),
255-
deepInfraModelId: z.string().optional(),
256-
})
257-
258252
const doubaoSchema = apiModelIdProviderModelSchema.extend({
259253
doubaoBaseUrl: z.string().optional(),
260254
doubaoApiKey: z.string().optional(),
@@ -327,6 +321,12 @@ const kilocodeSchema = baseProviderSettingsSchema.extend({
327321
openRouterProviderSort: openRouterProviderSortSchema.optional(),
328322
})
329323

324+
const deepInfraSchema = apiModelIdProviderModelSchema.extend({
325+
deepInfraBaseUrl: z.string().optional(),
326+
deepInfraApiKey: z.string().optional(),
327+
deepInfraModelId: z.string().optional(),
328+
})
329+
330330
export const virtualQuotaFallbackProfileDataSchema = z.object({
331331
profileName: z.string().optional(),
332332
profileId: z.string().optional(),
@@ -392,7 +392,6 @@ export const providerSettingsSchemaDiscriminated = z.discriminatedUnion("apiProv
392392
openAiNativeSchema.merge(z.object({ apiProvider: z.literal("openai-native") })),
393393
mistralSchema.merge(z.object({ apiProvider: z.literal("mistral") })),
394394
deepSeekSchema.merge(z.object({ apiProvider: z.literal("deepseek") })),
395-
deepInfraSchema.merge(z.object({ apiProvider: z.literal("deepinfra") })),
396395
doubaoSchema.merge(z.object({ apiProvider: z.literal("doubao") })),
397396
moonshotSchema.merge(z.object({ apiProvider: z.literal("moonshot") })),
398397
unboundSchema.merge(z.object({ apiProvider: z.literal("unbound") })),
@@ -401,6 +400,7 @@ export const providerSettingsSchemaDiscriminated = z.discriminatedUnion("apiProv
401400
fakeAiSchema.merge(z.object({ apiProvider: z.literal("fake-ai") })),
402401
xaiSchema.merge(z.object({ apiProvider: z.literal("xai") })),
403402
// kilocode_change start
403+
deepInfraSchema.merge(z.object({ apiProvider: z.literal("deepinfra") })),
404404
geminiCliSchema.merge(z.object({ apiProvider: z.literal("gemini-cli") })),
405405
kilocodeSchema.merge(z.object({ apiProvider: z.literal("kilocode") })),
406406
virtualQuotaFallbackSchema.merge(z.object({ apiProvider: z.literal("virtual-quota-fallback") })),
@@ -438,11 +438,11 @@ export const providerSettingsSchema = z.object({
438438
...kilocodeSchema.shape,
439439
...virtualQuotaFallbackSchema.shape,
440440
...qwenCodeSchema.shape,
441+
...deepInfraSchema.shape,
441442
// kilocode_change end
442443
...openAiNativeSchema.shape,
443444
...mistralSchema.shape,
444445
...deepSeekSchema.shape,
445-
...deepInfraSchema.shape,
446446
...doubaoSchema.shape,
447447
...moonshotSchema.shape,
448448
...unboundSchema.shape,
@@ -487,7 +487,7 @@ export const MODEL_ID_KEYS: Partial<keyof ProviderSettings>[] = [
487487
"litellmModelId",
488488
"huggingFaceModelId",
489489
"ioIntelligenceModelId",
490-
"deepInfraModelId",
490+
"deepInfraModelId", // kilocode_change
491491
]
492492

493493
export const getModelId = (settings: ProviderSettings): string | undefined => {
@@ -603,12 +603,12 @@ export const MODELS_BY_PROVIDER: Record<
603603
openrouter: { id: "openrouter", label: "OpenRouter", models: [] },
604604
requesty: { id: "requesty", label: "Requesty", models: [] },
605605
unbound: { id: "unbound", label: "Unbound", models: [] },
606-
deepinfra: { id: "deepinfra", label: "DeepInfra", models: [] },
607606

608607
// kilocode_change start
609608
kilocode: { id: "kilocode", label: "Kilocode", models: [] },
610609
"virtual-quota-fallback": { id: "virtual-quota-fallback", label: "Virtual Quota Fallback", models: [] },
611610
"qwen-code": { id: "qwen-code", label: "Qwen Code", models: [] },
611+
deepinfra: { id: "deepinfra", label: "DeepInfra", models: [] },
612612
// kilocode_change end
613613
}
614614

@@ -619,10 +619,10 @@ export const dynamicProviders = [
619619
"openrouter",
620620
"requesty",
621621
"unbound",
622-
"deepinfra",
623622
// kilocode_change start
624623
"kilocode",
625624
"virtual-quota-fallback",
625+
"deepinfra",
626626
// kilocode_change end
627627
] as const satisfies readonly ProviderName[]
628628

packages/types/src/providers/deepinfra.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// kilocode_change: provider added
2+
13
import type { ModelInfo } from "../model.js"
24

35
// Default fallback values for DeepInfra when model metadata is not yet loaded.

packages/types/src/providers/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ export * from "./doubao.js"
88
export * from "./featherless.js"
99
export * from "./fireworks.js"
1010
export * from "./gemini.js"
11-
export * from "./gemini-cli.js" // kilocode_change
11+
// kilocode_change start
12+
export * from "./gemini-cli.js"
13+
export * from "./qwen-code.js"
14+
export * from "./deepinfra.js"
15+
// kilocode_change end
1216
export * from "./glama.js"
1317
export * from "./groq.js"
1418
export * from "./huggingface.js"
@@ -21,12 +25,10 @@ export * from "./ollama.js"
2125
export * from "./openai.js"
2226
export * from "./openrouter.js"
2327
export * from "./requesty.js"
24-
export * from "./qwen-code.js" // kilocode_change
2528
export * from "./roo.js"
2629
export * from "./sambanova.js"
2730
export * from "./unbound.js"
2831
export * from "./vertex.js"
2932
export * from "./vscode-llm.js"
3033
export * from "./xai.js"
3134
export * from "./zai.js"
32-
export * from "./deepinfra.js"

src/api/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {
3434
VirtualQuotaFallbackHandler,
3535
GeminiCliHandler,
3636
QwenCodeHandler,
37+
DeepInfraHandler,
3738
// kilocode_change end
3839
ClaudeCodeHandler,
3940
SambaNovaHandler,
@@ -43,7 +44,6 @@ import {
4344
FireworksHandler,
4445
RooHandler,
4546
FeatherlessHandler,
46-
DeepInfraHandler,
4747
} from "./providers"
4848
// kilocode_change start
4949
import { KilocodeOpenrouterHandler } from "./providers/kilocode-openrouter"
@@ -99,6 +99,8 @@ export function buildApiHandler(configuration: ProviderSettings): ApiHandler {
9999
return new VirtualQuotaFallbackHandler(options)
100100
case "qwen-code":
101101
return new QwenCodeHandler(options)
102+
case "deepinfra":
103+
return new DeepInfraHandler(options)
102104
// kilocode_change end
103105
case "anthropic":
104106
return new AnthropicHandler(options)
@@ -146,8 +148,6 @@ export function buildApiHandler(configuration: ProviderSettings): ApiHandler {
146148
return new XAIHandler(options)
147149
case "groq":
148150
return new GroqHandler(options)
149-
case "deepinfra":
150-
return new DeepInfraHandler(options)
151151
case "huggingface":
152152
return new HuggingFaceHandler(options)
153153
case "chutes":

src/api/providers/deepinfra.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// kilocode_change - provider added
2+
13
import { Anthropic } from "@anthropic-ai/sdk" // for message param types
24
import OpenAI from "openai"
35

@@ -61,19 +63,19 @@ export class DeepInfraHandler extends RouterProvider implements SingleCompletion
6163
_metadata?: ApiHandlerCreateMessageMetadata,
6264
): ApiStream {
6365
const { id: modelId, info, reasoningEffort: reasoning_effort } = await this.fetchModel()
64-
let prompt_cache_key = undefined;
66+
let prompt_cache_key = undefined
6567
if (info.supportsPromptCache && _metadata?.taskId) {
66-
prompt_cache_key = _metadata.taskId;
68+
prompt_cache_key = _metadata.taskId
6769
}
6870

69-
const requestOptions: OpenAI.Chat.Completions.ChatCompletionCreateParamsStreaming = {
71+
const requestOptions = {
7072
model: modelId,
7173
messages: [{ role: "system", content: systemPrompt }, ...convertToOpenAiMessages(messages)],
7274
stream: true,
7375
stream_options: { include_usage: true },
7476
reasoning_effort,
7577
prompt_cache_key,
76-
}
78+
} as OpenAI.Chat.Completions.ChatCompletionCreateParamsStreaming
7779

7880
if (this.supportsTemperature(modelId)) {
7981
requestOptions.temperature = this.options.modelTemperature ?? 0

src/api/providers/fetchers/modelCache.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { getKiloBaseUriFromToken } from "../../../shared/kilocode/token"
1919
import { getOllamaModels } from "./ollama"
2020
import { getLMStudioModels } from "./lmstudio"
2121
import { getIOIntelligenceModels } from "./io-intelligence"
22-
import { getDeepInfraModels } from "./deepinfra"
22+
import { getDeepInfraModels } from "./deepinfra" // kilocode_change
2323
const memoryCache = new NodeCache({ stdTTL: 5 * 60, checkperiod: 5 * 60 })
2424

2525
export /*kilocode_change*/ async function writeModels(router: RouterName, data: ModelRecord) {
@@ -79,9 +79,6 @@ export const getModels = async (options: GetModelsOptions): Promise<ModelRecord>
7979
// Type safety ensures apiKey and baseUrl are always provided for litellm
8080
models = await getLiteLLMModels(options.apiKey, options.baseUrl)
8181
break
82-
case "deepinfra":
83-
models = await getDeepInfraModels(options.apiKey, options.baseUrl)
84-
break
8582
// kilocode_change start
8683
case "kilocode-openrouter":
8784
models = await getOpenRouterModels({
@@ -93,6 +90,9 @@ export const getModels = async (options: GetModelsOptions): Promise<ModelRecord>
9390
headers: options.kilocodeToken ? { Authorization: `Bearer ${options.kilocodeToken}` } : undefined,
9491
})
9592
break
93+
case "deepinfra":
94+
models = await getDeepInfraModels(options.apiKey, options.baseUrl)
95+
break
9696
case "cerebras":
9797
models = cerebrasModels
9898
break

src/api/providers/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export { SambaNovaHandler } from "./sambanova"
2626
export { UnboundHandler } from "./unbound"
2727
export { VertexHandler } from "./vertex"
2828
// kilocode_change start
29+
export { DeepInfraHandler } from "./deepinfra"
2930
export { GeminiCliHandler } from "./gemini-cli"
3031
export { QwenCodeHandler } from "./qwen-code"
3132
export { VirtualQuotaFallbackHandler } from "./virtual-quota-fallback"
@@ -36,4 +37,3 @@ export { ZAiHandler } from "./zai"
3637
export { FireworksHandler } from "./fireworks"
3738
export { RooHandler } from "./roo"
3839
export { FeatherlessHandler } from "./featherless"
39-
export { DeepInfraHandler } from "./deepinfra"

src/core/webview/__tests__/ClineProvider.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2728,6 +2728,7 @@ describe("ClineProvider - Router Models", () => {
27282728
"kilocode-openrouter": mockModels,
27292729
ollama: mockModels, // kilocode_change
27302730
lmstudio: {},
2731+
deepinfra: mockModels, // kilocode_change
27312732
},
27322733
})
27332734
})
@@ -2760,6 +2761,7 @@ describe("ClineProvider - Router Models", () => {
27602761
.mockRejectedValueOnce(new Error("Unbound API error")) // unbound fail
27612762
.mockRejectedValueOnce(new Error("Kilocode-OpenRouter API error")) // kilocode-openrouter fail
27622763
.mockRejectedValueOnce(new Error("Ollama API error")) // kilocode_change
2764+
.mockRejectedValueOnce(new Error("DeepInfra API error")) // kilocode_change
27632765
.mockRejectedValueOnce(new Error("LiteLLM connection failed")) // litellm fail
27642766

27652767
await messageHandler({ type: "requestRouterModels" })
@@ -2776,6 +2778,7 @@ describe("ClineProvider - Router Models", () => {
27762778
lmstudio: {},
27772779
litellm: {},
27782780
"kilocode-openrouter": {},
2781+
deepinfra: {}, // kilocode_change
27792782
},
27802783
})
27812784

@@ -2892,6 +2895,7 @@ describe("ClineProvider - Router Models", () => {
28922895
unbound: mockModels,
28932896
litellm: {},
28942897
"kilocode-openrouter": mockModels,
2898+
deepinfra: mockModels, // kilocode_change
28952899
ollama: mockModels, // kilocode_change
28962900
lmstudio: {},
28972901
},

0 commit comments

Comments
 (0)