Fix DB schema (#135)
This commit is contained in:
@@ -87,8 +87,8 @@ export function registerLanguageModelHandlers() {
|
||||
params: CreateCustomLanguageModelParams,
|
||||
): Promise<void> => {
|
||||
const {
|
||||
id,
|
||||
name,
|
||||
apiName,
|
||||
displayName,
|
||||
providerId,
|
||||
description,
|
||||
maxOutputTokens,
|
||||
@@ -96,11 +96,11 @@ export function registerLanguageModelHandlers() {
|
||||
} = params;
|
||||
|
||||
// Validation
|
||||
if (!id) {
|
||||
throw new Error("Model ID is required");
|
||||
if (!apiName) {
|
||||
throw new Error("Model API name is required");
|
||||
}
|
||||
if (!name) {
|
||||
throw new Error("Model name is required");
|
||||
if (!displayName) {
|
||||
throw new Error("Model display name is required");
|
||||
}
|
||||
if (!providerId) {
|
||||
throw new Error("Provider ID is required");
|
||||
@@ -117,21 +117,10 @@ export function registerLanguageModelHandlers() {
|
||||
throw new Error(`Provider with ID "${providerId}" not found`);
|
||||
}
|
||||
|
||||
// Check if model ID already exists
|
||||
const existingModel = db
|
||||
.select()
|
||||
.from(languageModelsSchema)
|
||||
.where(eq(languageModelsSchema.id, id))
|
||||
.get();
|
||||
|
||||
if (existingModel) {
|
||||
throw new Error(`A model with ID "${id}" already exists`);
|
||||
}
|
||||
|
||||
// Insert the new model
|
||||
await db.insert(languageModelsSchema).values({
|
||||
id,
|
||||
name,
|
||||
displayName,
|
||||
apiName,
|
||||
provider_id: providerId,
|
||||
description: description || null,
|
||||
max_output_tokens: maxOutputTokens || null,
|
||||
|
||||
@@ -144,16 +144,26 @@ export interface LanguageModelProvider {
|
||||
type: "custom" | "local" | "cloud";
|
||||
}
|
||||
|
||||
export interface LanguageModel {
|
||||
id: string;
|
||||
name: string;
|
||||
displayName: string;
|
||||
description: string;
|
||||
tag?: string;
|
||||
maxOutputTokens?: number;
|
||||
contextWindow?: number;
|
||||
type: "local" | "cloud" | "custom";
|
||||
}
|
||||
export type LanguageModel =
|
||||
| {
|
||||
id: number;
|
||||
apiName: string;
|
||||
displayName: string;
|
||||
description: string;
|
||||
tag?: string;
|
||||
maxOutputTokens?: number;
|
||||
contextWindow?: number;
|
||||
type: "custom";
|
||||
}
|
||||
| {
|
||||
apiName: string;
|
||||
displayName: string;
|
||||
description: string;
|
||||
tag?: string;
|
||||
maxOutputTokens?: number;
|
||||
contextWindow?: number;
|
||||
type: "local" | "cloud";
|
||||
};
|
||||
|
||||
export interface CreateCustomLanguageModelProviderParams {
|
||||
id: string;
|
||||
@@ -163,8 +173,8 @@ export interface CreateCustomLanguageModelProviderParams {
|
||||
}
|
||||
|
||||
export interface CreateCustomLanguageModelParams {
|
||||
id: string;
|
||||
name: string;
|
||||
apiName: string;
|
||||
displayName: string;
|
||||
providerId: string;
|
||||
description?: string;
|
||||
maxOutputTokens?: number;
|
||||
|
||||
@@ -157,7 +157,7 @@ export async function getLanguageModels(obj: {
|
||||
const models = MODEL_OPTIONS[providerId as RegularModelProvider] || [];
|
||||
return models.map((model) => ({
|
||||
...model,
|
||||
id: model.name,
|
||||
apiName: model.name,
|
||||
type: "cloud",
|
||||
}));
|
||||
} else {
|
||||
@@ -174,7 +174,8 @@ export async function getLanguageModels(obj: {
|
||||
.select({
|
||||
id: languageModelsSchema.id,
|
||||
// Map DB columns to LanguageModel fields
|
||||
name: languageModelsSchema.name,
|
||||
displayName: languageModelsSchema.displayName,
|
||||
apiName: languageModelsSchema.apiName,
|
||||
// No display_name in DB, use name instead
|
||||
description: languageModelsSchema.description,
|
||||
// No tag in DB
|
||||
@@ -186,7 +187,6 @@ export async function getLanguageModels(obj: {
|
||||
|
||||
return customModelsDb.map((model) => ({
|
||||
...model,
|
||||
displayName: model.name, // Use name as displayName for custom models
|
||||
// Ensure possibly null fields are handled, provide defaults or undefined if needed
|
||||
description: model.description ?? "",
|
||||
tag: undefined, // No tag for custom models from DB
|
||||
|
||||
Reference in New Issue
Block a user