Contradictions explained

This commit is contained in:
AG
2025-10-12 14:57:31 +03:00
parent f42bac001d
commit e752c8d4d3
3 changed files with 16 additions and 9 deletions

View File

@@ -76,9 +76,11 @@ export class LLMService {
} }
} }
async checkForInnerContradictions(desireSet: DesireSet): Promise<boolean> { async checkForInnerContradictions(desireSet: DesireSet): Promise<string | null> {
const prompt = ` const prompt = `
You are an AI assistant that detects contradictions in a list of desires. Given a JSON object with three lists of desires (wants, accepts, noGoes), determine if there are any contradictions WITHIN each list and across the lists. For example, "I want a dog" and "I don't want any pets" in the same "wants" list is a contradiction; "Pizza" in "wants" and "food" in "do not want" is a contradiction. Respond with only "true" if a contradiction is found, and "false" otherwise. You are an AI assistant that detects contradictions in a list of desires. Given a JSON object with three lists of desires (wants, accepts, noGoes), determine if there are any contradictions WITHIN each list and across the lists. For example, "I want a dog" and "I don't want any pets" in the same "wants" list is a contradiction; "Pizza" in "wants" and "food" in "do not want" is a contradiction.
If a contradiction is found, respond with a concise, single-sentence description of the contradiction. If no contradiction is found, respond with "null".
Here is the desire set: Here is the desire set:
${JSON.stringify(desireSet)} ${JSON.stringify(desireSet)}
@@ -87,8 +89,13 @@ 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().trim().toLowerCase(); const text = response.text().trim();
return text === 'true';
if (text.toLowerCase() === 'null') {
return null;
} else {
return text;
}
} catch (error) { } catch (error) {
console.error("Error calling Gemini API for contradiction check:", error); console.error("Error calling Gemini API for contradiction check:", error);
throw error; throw error;

View File

@@ -141,9 +141,9 @@ export const createWebSocketServer = (server: any) => {
return; return;
} }
const hasContradictions = await llmService.checkForInnerContradictions(payload.response); const hasContradictionsGist = await llmService.checkForInnerContradictions(payload.response);
if (hasContradictions) { if (hasContradictionsGist) {
ws.send(JSON.stringify({ type: 'ERROR', payload: { message: 'Your submission contains inner contradictions. Please resolve them and submit again.' } })); ws.send(JSON.stringify({ type: 'ERROR', payload: { message: `Your submission contains inner contradictions: ${hasContradictionsGist} Please resolve them and submit again.` } }));
return; return;
} }

View File

@@ -56,7 +56,7 @@ describe('LLMService Refactor', () => {
candidates: [{ candidates: [{
content: { content: {
parts: [{ parts: [{
text: 'true' text: '"Ice Cream" and "No desserts" are contradictory.'
}] }]
} }
}] }]
@@ -64,6 +64,6 @@ describe('LLMService Refactor', () => {
const desireSet = { wants: ['Ice Cream', 'No desserts'], accepts: [], noGoes: [] }; const desireSet = { wants: ['Ice Cream', 'No desserts'], accepts: [], noGoes: [] };
const hasContradictions = await llmService.checkForInnerContradictions(desireSet as any); const hasContradictions = await llmService.checkForInnerContradictions(desireSet as any);
expect(hasContradictions).toBe(true); expect(hasContradictions).not.toBeNull();
}); });
}); });