From cf907da7ba30bea08b1bd1854eaff2c6296ddbd3 Mon Sep 17 00:00:00 2001 From: Josh Creek <8179928+jcreek@users.noreply.github.com> Date: Thu, 24 Apr 2025 20:31:51 +0100 Subject: [PATCH] fix(*): Ensure fallback data works correctly --- src/lib/agent/services/agentService.ts | 29 +++++++++++++------------- src/lib/utils/ai.ts | 7 ++++++- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/lib/agent/services/agentService.ts b/src/lib/agent/services/agentService.ts index c64fd2e..bd55199 100644 --- a/src/lib/agent/services/agentService.ts +++ b/src/lib/agent/services/agentService.ts @@ -23,10 +23,9 @@ if (!safeModel && !isTestEnv) { throw new Error('AI_MODEL is not set'); } -export const client = AIProjectsClient.fromConnectionString( - safeConnString!, - new DefaultAzureCredential() -); +export const client = !isTestEnv && safeConnString + ? AIProjectsClient.fromConnectionString(safeConnString, new DefaultAzureCredential()) + : undefined; // const codeInterpreterTool = ToolUtility.createCodeInterpreterTool([]); @@ -71,13 +70,15 @@ export const toolResources = allTools.reduce>((map, t) => { return map; }, {}); -export const agent = await client.agents.createAgent(AI_MODEL, { - name: `assessment-feedback-agent`, - instructions, - temperature: 0.5, - tools, - toolResources, - requestOptions: { - headers: { 'x-ms-enable-preview': 'true' } - } -}); \ No newline at end of file +export const agent = client + ? await client.agents.createAgent(AI_MODEL, { + name: `assessment-feedback-agent`, + instructions, + temperature: 0.5, + tools, + toolResources, + requestOptions: { + headers: { 'x-ms-enable-preview': 'true' } + } + }) + : undefined; \ No newline at end of file diff --git a/src/lib/utils/ai.ts b/src/lib/utils/ai.ts index b3edd3f..b8eaf3a 100644 --- a/src/lib/utils/ai.ts +++ b/src/lib/utils/ai.ts @@ -145,7 +145,12 @@ export async function gradeSubmissionWithAgent( task: string, roomId: string ): Promise { - if (!client || !agent) { + if (!client) { + // In test/CI mode, return fallback data + return fallbackGrade(submission, task); + } + + if (!agent) { throw new Error('Agent not available'); }