NLP-IBM-Debater / src /app /services /argument.service.ts
Yassine Mhirsi
argument generation
ee3eb53
export type ArgumentRequest = {
topic: string;
position: string;
};
export type ArgumentResponse = {
topic: string;
position: string;
original_argument: string;
enhanced_argument: string;
process: string;
};
/**
* Calls the external N8N webhook to generate enhanced arguments
*/
export async function generateEnhancedArgument(request: ArgumentRequest): Promise<ArgumentResponse> {
const webhookUrl = process.env.REACT_APP_N8N_WEBHOOK_URL;
if (!webhookUrl) {
throw new Error('REACT_APP_N8N_WEBHOOK_URL environment variable is not set');
}
try {
const response = await fetch(`${webhookUrl}/generate-argument-enhanced`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(request),
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data: ArgumentResponse = await response.json();
return data;
} catch (error) {
if (error instanceof Error) {
throw error;
}
throw new Error('Failed to generate enhanced argument');
}
}