Align OpenAI key settings with local model profiles

This commit is contained in:
“BeeRad”
2026-05-02 11:49:06 +10:00
parent 16d222e3b4
commit cdad9d3931
3 changed files with 130 additions and 4 deletions
+24
View File
@@ -11,10 +11,23 @@ export const runtime = 'nodejs';
function buildResponse(key: string | null) {
const configured = isValidOpenAiKey(key);
const llmProfile = process.env.LLM_PROFILE || 'openai';
const embeddingProfile = process.env.EMBEDDING_PROFILE || 'openai';
const openAiKeyWritable = llmProfile === 'openai' || embeddingProfile === 'openai';
return {
configured,
maskedKey: configured ? maskOpenAiKey(key) : null,
envPath: getEnvLocalPath(),
openAiKeyWritable,
activeProfile: {
llmProfile,
llmModel: process.env.LLM_MODEL || (llmProfile === 'openai' ? 'gpt-4o-mini' : null),
llmBaseUrl: process.env.LLM_BASE_URL || null,
embeddingProfile,
embeddingModel: process.env.EMBEDDING_MODEL || (embeddingProfile === 'openai' ? 'text-embedding-3-small' : null),
embeddingBaseUrl: process.env.EMBEDDING_BASE_URL || process.env.LLM_BASE_URL || null,
embeddingDimensions: process.env.EMBEDDING_DIMENSIONS || (embeddingProfile === 'openai' ? '1536' : '1024'),
},
};
}
@@ -37,6 +50,17 @@ export async function POST(request: NextRequest) {
try {
const body = await request.json();
const key = typeof body?.key === 'string' ? body.key.trim() : '';
const currentState = buildResponse(await readStoredOpenAiKey());
if (!currentState.openAiKeyWritable) {
return NextResponse.json(
{
error: 'OpenAI key entry is disabled because this install is using a local model profile. Change .env.local and rebuild embeddings to switch providers.',
...currentState,
},
{ status: 409 }
);
}
if (!isValidOpenAiKey(key)) {
return NextResponse.json(