From be3eb610a0d8c078f2bdec893b2f6e4e17207637 Mon Sep 17 00:00:00 2001 From: arkml Date: Fri, 21 Feb 2025 16:45:22 +0530 Subject: [PATCH] copilot: fixed response --- apps/copilot/copilot.py | 2 +- apps/rowboat/app/actions/copilot_actions.ts | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/apps/copilot/copilot.py b/apps/copilot/copilot.py index 573d5236..2266cfe8 100644 --- a/apps/copilot/copilot.py +++ b/apps/copilot/copilot.py @@ -480,7 +480,7 @@ You are responsible for providing delivery information to the user. output format: ```json { - "response": "" + "agent_instructions": "" } ``` """ diff --git a/apps/rowboat/app/actions/copilot_actions.ts b/apps/rowboat/app/actions/copilot_actions.ts index a093330a..d677d599 100644 --- a/apps/rowboat/app/actions/copilot_actions.ts +++ b/apps/rowboat/app/actions/copilot_actions.ts @@ -200,10 +200,15 @@ export async function getCopilotAgentInstructions( // parse and return response const json = await response.json(); + console.log(`copilot response`, JSON.stringify(json, null, 2)); let copilotResponse: z.infer; + let agent_instructions: string; try { copilotResponse = CopilotAPIResponse.parse(json); + const content = json.response.replace(/^```json\n/, '').replace(/\n```$/, ''); + agent_instructions = JSON.parse(content).agent_instructions; + } catch (e) { console.error('Failed to parse copilot response', e); throw new Error(`Failed to parse copilot response: ${e}`); @@ -213,5 +218,5 @@ export async function getCopilotAgentInstructions( } // return response - return copilotResponse.response; + return agent_instructions; } \ No newline at end of file