Loosen provider type to a string (#144)

This commit is contained in:
Will Chen
2025-05-12 22:29:36 -07:00
committed by GitHub
parent f628c81f4c
commit d1027622b4
3 changed files with 6 additions and 21 deletions

View File

@@ -1,4 +1,4 @@
import type { LargeLanguageModel, ModelProvider } from "@/lib/schemas"; import type { LargeLanguageModel } from "@/lib/schemas";
import { Button } from "@/components/ui/button"; import { Button } from "@/components/ui/button";
import { import {
Tooltip, Tooltip,
@@ -216,7 +216,7 @@ export function ModelPicker({
onClick={() => { onClick={() => {
onModelSelect({ onModelSelect({
name: model.apiName, name: model.apiName,
provider: providerId as ModelProvider, provider: providerId,
}); });
setOpen(false); setOpen(false);
}} }}

View File

@@ -5,7 +5,6 @@ import {
} from "@/db/schema"; } from "@/db/schema";
import type { LanguageModelProvider, LanguageModel } from "@/ipc/ipc_types"; import type { LanguageModelProvider, LanguageModel } from "@/ipc/ipc_types";
import { eq } from "drizzle-orm"; import { eq } from "drizzle-orm";
import { ModelProvider } from "@/lib/schemas";
export interface ModelOption { export interface ModelOption {
name: string; name: string;
@@ -16,12 +15,7 @@ export interface ModelOption {
contextWindow?: number; contextWindow?: number;
} }
export type RegularModelProvider = Exclude< export const MODEL_OPTIONS: Record<string, ModelOption[]> = {
ModelProvider,
"ollama" | "lmstudio"
>;
export const MODEL_OPTIONS: Record<RegularModelProvider, ModelOption[]> = {
openai: [ openai: [
// https://platform.openai.com/docs/models/gpt-4.1 // https://platform.openai.com/docs/models/gpt-4.1
{ {
@@ -109,7 +103,7 @@ export const PROVIDER_TO_ENV_VAR: Record<string, string> = {
}; };
export const PROVIDERS: Record< export const PROVIDERS: Record<
RegularModelProvider, string,
{ {
displayName: string; displayName: string;
hasFreeTier?: boolean; hasFreeTier?: boolean;
@@ -286,7 +280,7 @@ export async function getLanguageModels({
let hardcodedModels: LanguageModel[] = []; let hardcodedModels: LanguageModel[] = [];
if (provider.type === "cloud") { if (provider.type === "cloud") {
if (providerId in MODEL_OPTIONS) { if (providerId in MODEL_OPTIONS) {
const models = MODEL_OPTIONS[providerId as RegularModelProvider] || []; const models = MODEL_OPTIONS[providerId] || [];
hardcodedModels = models.map((model) => ({ hardcodedModels = models.map((model) => ({
...model, ...model,
apiName: model.name, apiName: model.name,

View File

@@ -35,26 +35,17 @@ const providers = [
"ollama", "ollama",
"lmstudio", "lmstudio",
] as const; ] as const;
/**
* Zod schema for model provider
*/
export const ModelProviderSchema = z.enum(providers);
export const cloudProviders = providers.filter( export const cloudProviders = providers.filter(
(provider) => provider !== "ollama" && provider !== "lmstudio", (provider) => provider !== "ollama" && provider !== "lmstudio",
); );
/**
* Type derived from the ModelProviderSchema
*/
export type ModelProvider = z.infer<typeof ModelProviderSchema>;
/** /**
* Zod schema for large language model configuration * Zod schema for large language model configuration
*/ */
export const LargeLanguageModelSchema = z.object({ export const LargeLanguageModelSchema = z.object({
name: z.string(), name: z.string(),
provider: ModelProviderSchema, provider: z.string(),
}); });
/** /**