u
This commit is contained in:
@@ -5,7 +5,7 @@ import jwt from 'jsonwebtoken';
|
||||
import { defineTool, ToolError, OpenRouterProvider } from 'libllmorbiter';
|
||||
import env from '../config/env.js';
|
||||
import { prepareVfs } from './vfs.js';
|
||||
import { resolveOpenRouterKey } from './llm-key.js';
|
||||
import { resolveOpenRouterKey, resolveImageModel } from './llm-key.js';
|
||||
|
||||
/**
|
||||
* analyze_image — lets a vision model actually LOOK at images held in the VFS.
|
||||
@@ -365,9 +365,10 @@ export function createAnalyzeImageTool({ googleAuthId, model }) {
|
||||
: question || 'Describe this image, judge its visual quality, flag any watermark, text overlay or defect, and say whether it is usable as a product or category image.';
|
||||
|
||||
const apiKey = await resolveOpenRouterKey(googleAuthId);
|
||||
const imageModel = (await resolveImageModel(googleAuthId)) || model;
|
||||
const provider = new OpenRouterProvider({ apiKey, apiUrl: env.openrouterApiUrl });
|
||||
const response = await provider.chatCompletions({
|
||||
model,
|
||||
model: imageModel,
|
||||
messages: [
|
||||
{
|
||||
role: 'user',
|
||||
|
||||
@@ -45,11 +45,19 @@ export async function hasConfiguredOpenRouterKey(googleAuthId) {
|
||||
}
|
||||
}
|
||||
|
||||
export const DEFAULT_MODEL_SETTINGS = {
|
||||
modelslug: 'openai/gpt-6-luna',
|
||||
modelslugflag: 'floor',
|
||||
modelreasoning: 'medium',
|
||||
modelslugimage: 'meta/muse-image',
|
||||
};
|
||||
|
||||
/**
|
||||
* Resolve the default model for a user/company:
|
||||
* - If companysetting `default-model` is set, return it (works in both paid and no-key modes).
|
||||
* - Otherwise, if the user/company has configured `keys.openrouter`, use `env.openrouterPaidModel`
|
||||
* (which defaults to 'openai/gpt-6-luna:floor').
|
||||
* - Otherwise, if the user/company has configured `keys.openrouter`, construct from
|
||||
* companysetting `modelslug` (default 'openai/gpt-6-luna') and `modelslugflag` (default 'floor').
|
||||
* If flag is 'floor' or 'nitro', it is attached as `${slug}:${flag}`. If empty string, no flag is attached.
|
||||
* - Otherwise (no key set / free mode), use `env.openrouterFreeModel`
|
||||
* (which defaults to 'openrouter/free').
|
||||
*
|
||||
@@ -67,7 +75,72 @@ export async function resolveDefaultModel(googleAuthId) {
|
||||
}
|
||||
}
|
||||
const hasKey = await hasConfiguredOpenRouterKey(googleAuthId);
|
||||
return hasKey
|
||||
? (env.openrouterPaidModel || 'openai/gpt-6-luna:floor')
|
||||
: (env.openrouterFreeModel || 'openrouter/free');
|
||||
if (!hasKey) {
|
||||
return env.openrouterFreeModel || 'openrouter/free';
|
||||
}
|
||||
|
||||
let slug = '';
|
||||
let flag = null;
|
||||
if (googleAuthId) {
|
||||
try {
|
||||
const slugSetting = await dbCompanySetting.getByKey(googleAuthId, 'modelslug', { maskWriteonly: false });
|
||||
slug = slugSetting?.value?.trim() || '';
|
||||
const flagSetting = await dbCompanySetting.getByKey(googleAuthId, 'modelslugflag', { maskWriteonly: false });
|
||||
if (flagSetting !== undefined && flagSetting.value !== undefined && flagSetting.value !== null) {
|
||||
flag = flagSetting.value.trim();
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('modelslug: failed to read company setting:', err.message);
|
||||
}
|
||||
}
|
||||
if (!slug) {
|
||||
slug = DEFAULT_MODEL_SETTINGS.modelslug;
|
||||
}
|
||||
if (flag === null) {
|
||||
flag = DEFAULT_MODEL_SETTINGS.modelslugflag;
|
||||
}
|
||||
const baseSlug = slug.replace(/:(floor|nitro)$/, '');
|
||||
return flag ? `${baseSlug}:${flag}` : baseSlug;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the reasoning effort for a user/company:
|
||||
* Reads companysetting `modelreasoning` (default 'medium'), returning 'none' | 'low' | 'medium' | 'high'.
|
||||
*
|
||||
* @param {number} [googleAuthId]
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
export async function resolveModelReasoning(googleAuthId) {
|
||||
if (googleAuthId) {
|
||||
try {
|
||||
const setting = await dbCompanySetting.getByKey(googleAuthId, 'modelreasoning', { maskWriteonly: false });
|
||||
const val = setting?.value?.trim();
|
||||
if (val && ['none', 'low', 'medium', 'high'].includes(val)) {
|
||||
return val;
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('modelreasoning: failed to read company setting:', err.message);
|
||||
}
|
||||
}
|
||||
return DEFAULT_MODEL_SETTINGS.modelreasoning;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the vision/image model for a user/company:
|
||||
* Reads companysetting `modelslugimage` (default 'meta/muse-image').
|
||||
*
|
||||
* @param {number} [googleAuthId]
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
export async function resolveImageModel(googleAuthId) {
|
||||
if (googleAuthId) {
|
||||
try {
|
||||
const setting = await dbCompanySetting.getByKey(googleAuthId, 'modelslugimage', { maskWriteonly: false });
|
||||
const val = setting?.value?.trim();
|
||||
if (val) return val;
|
||||
} catch (err) {
|
||||
console.error('modelslugimage: failed to read company setting:', err.message);
|
||||
}
|
||||
}
|
||||
return DEFAULT_MODEL_SETTINGS.modelslugimage;
|
||||
}
|
||||
Reference in New Issue
Block a user