fix(ai): prevent OpenAI credential error at module load time
- Moved OpenAI client initialization to a lazy getter function - Added explicit check for NEBIUS_API_KEY in the getter - Ensures Server Actions return structured errors instead of crashing when keys are missing
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
'use server';
|
||||
|
||||
import { aiClient } from '@/lib/ai-client';
|
||||
import { getNebiusClient } from '@/lib/ai-client';
|
||||
import { SYSTEM_INSTRUCTION as GEMINI_SYSTEM_INSTRUCTION } from '@/lib/gemini';
|
||||
import { BottleMetadataSchema, AnalysisResponse, BottleMetadata } from '@/types/whisky';
|
||||
import { createServerActionClient } from '@supabase/auth-helpers-nextjs';
|
||||
@@ -56,7 +56,8 @@ export async function analyzeBottleNebius(base64Image: string, tags?: string[],
|
||||
console.log(`[analyzeBottleNebius] Instruction prepared for AI: ${instruction.substring(0, 100)}...`);
|
||||
|
||||
|
||||
const response = await aiClient.chat.completions.create({
|
||||
const client = getNebiusClient();
|
||||
const response = await client.chat.completions.create({
|
||||
model: "Qwen/Qwen2.5-VL-72B-Instruct",
|
||||
messages: [
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user