Works! MVP
This commit is contained in:
@@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user