You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

58 lines
2.2 KiB

import { sqliteTable, text, integer, index } from "drizzle-orm/sqlite-core";
export const LlmProviderStatuses = ["active", "disabled"] as const;
export type LlmProviderStatus = (typeof LlmProviderStatuses)[number];
export const LlmParseModes = ["openai", "anthropic"] as const;
export type LlmParseMode = (typeof LlmParseModes)[number];
export const LlmModelTypes = ["text", "vision", "multimodal"] as const;
export type LlmModelType = (typeof LlmModelTypes)[number];
export const llmProviders = sqliteTable(
"llm_providers",
{
id: integer("id").primaryKey({ autoIncrement: true }),
name: text("name", { length: 100 }).notNull().unique(),
slug: text("slug", { length: 100 }).notNull().unique(),
baseUrl: text("base_url", { length: 500 }),
parseMode: text("parse_mode", { enum: LlmParseModes }).notNull().default("openai"),
apiKey: text("api_key"),
status: text("status", { enum: LlmProviderStatuses }).notNull().default("active"),
description: text("description"),
createdAt: integer("created_at", { mode: "timestamp_ms" }).defaultNow().notNull(),
updatedAt: integer("updated_at", { mode: "timestamp_ms" })
.defaultNow()
.$onUpdate(() => new Date())
.notNull(),
},
(table) => [
index("idx_llm_provider_slug").on(table.slug),
index("idx_llm_provider_status").on(table.status),
],
);
export const llmModels = sqliteTable(
"llm_models",
{
id: integer("id").primaryKey({ autoIncrement: true }),
providerId: integer("provider_id")
.notNull()
.references(() => llmProviders.id, { onDelete: "cascade" }),
name: text("name", { length: 200 }).notNull(),
modelId: text("model_id", { length: 200 }).notNull(),
type: text("type", { enum: LlmModelTypes }).notNull().default("text"),
enabled: integer("enabled").default(1).notNull(),
description: text("description"),
maxTokens: integer("max_tokens"),
createdAt: integer("created_at", { mode: "timestamp_ms" }).defaultNow().notNull(),
updatedAt: integer("updated_at", { mode: "timestamp_ms" })
.defaultNow()
.$onUpdate(() => new Date())
.notNull(),
},
(table) => [
index("idx_llm_model_provider").on(table.providerId),
index("idx_llm_model_type").on(table.type),
],
);