// Step 1: Create the project
const projectOptions = {
method: 'POST',
headers: {
accept: 'application/json',
'content-type': 'application/json',
'X-API-KEY': "<YOUR_API_KEY>"
},
body: JSON.stringify({ name: 'test-project' }),
};
let projectId: string | undefined;
fetch('https://api.patronus.ai/v1/projects', projectOptions)
.then((res) => res.json())
.then((res) => {
console.log('Project created:', res);
projectId = res.id;
// Step 2: Now create the experiment
return fetch('https://api.patronus.ai/v1/experiments', {
method: 'POST',
headers: {
accept: 'application/json',
'content-type': 'application/json',
'X-API-KEY': "<YOUR_API_KEY>"
},
body: JSON.stringify({ project_id: projectId, name: 'test-experiment' }),
});
})
.then((res) => res.json())
.then((res) => {
console.log('Experiment created:', res);
const experimentId = res.experiment.id;
// Step 3: Now evaluate the experiment
return fetch('https://api.patronus.ai/v1/evaluate', {
method: 'POST',
headers: {
'X-API-KEY': "<YOUR_API_KEY>",
'content-type': 'application/json',
},
body: JSON.stringify({
evaluators: [
{
evaluator: 'lynx',
criteria: 'patronus:hallucination',
},
],
evaluated_model_input: 'What color is the ocean?',
evaluated_model_retrieved_context: 'The ocean is blue',
evaluated_model_output: 'The ocean is red',
experiment_id: experimentId,
}),
});
})
.then((res) => res.text())
.then((result) => {
console.log('Evaluation result:', result);
})
.catch((err) => {
console.error('Error:', err);
});