fix: guard AI response parse against undefined textResponse
This commit is contained in:
@@ -12248,10 +12248,12 @@ const App = () => {
|
||||
model: 'gpt-4o',
|
||||
systemInstruction: 'You are a MIDI composer. Output ONLY valid JSON array of notes. No markdown, no explanation. Use 4/4 time. pitch=C4=60, D4=62, E4=64, F4=65, G4=67, A4=69, B4=71, C5=72.'
|
||||
});
|
||||
if (!result) throw new Error('AI không phản hồi');
|
||||
let notesData = null;
|
||||
if (result.textResponse) {
|
||||
const textResp = result.textResponse || result.text || '';
|
||||
if (textResp && typeof textResp === 'string') {
|
||||
try {
|
||||
const cleaned = result.textResponse.replace(/```json?\s*/g, '').replace(/```/g, '').trim();
|
||||
const cleaned = textResp.replace(/```json?\s*/g, '').replace(/```/g, '').trim();
|
||||
notesData = JSON.parse(cleaned);
|
||||
} catch (e1) {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user