Works! MVP

This commit is contained in:
aodulov
2025-10-10 15:50:27 +03:00
parent 2fdc83091f
commit 9896742868

View File

@@ -41,10 +41,22 @@ export class LLMService {
try { try {
const result = await this.model.generateContent(prompt); const result = await this.model.generateContent(prompt);
const response = result.response; const response = result.response;
const text = response.text(); let text = response.text();
const newLocal = text.match(/\{.*?\}/s);
// Clean the response to ensure it is valid JSON
const jsonMatch = newLocal;
if (jsonMatch) {
text = jsonMatch[0];
} else {
// Handle cases where no JSON is found
console.error("LLM did not return a valid JSON object. Response:", text);
throw new Error('Failed to parse LLM response as JSON.');
}
return JSON.parse(text); return JSON.parse(text);
} catch (error) { } catch (error) {
console.error("Error calling Gemini API:", error); console.error("Error calling Gemini API or parsing response:", error);
throw error; throw error;
} }
} }