add try catch for openai responses api
This commit is contained in:
@@ -91,19 +91,26 @@ async function recommendationsLoader(
|
|||||||
title,
|
title,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const response = await openAIClient.responses.create({
|
let response;
|
||||||
store: false,
|
|
||||||
prompt: {
|
try {
|
||||||
id: analysesRecommendationsPromptId,
|
response = await openAIClient.responses.create({
|
||||||
variables: {
|
store: false,
|
||||||
analyses: JSON.stringify(formattedAnalyses),
|
prompt: {
|
||||||
results: JSON.stringify(formattedAnalysisResponses),
|
id: analysesRecommendationsPromptId,
|
||||||
gender: gender.value,
|
variables: {
|
||||||
age: age.toString(),
|
analyses: JSON.stringify(formattedAnalyses),
|
||||||
weight: weight.toString(),
|
results: JSON.stringify(formattedAnalysisResponses),
|
||||||
|
gender: gender.value,
|
||||||
|
age: age.toString(),
|
||||||
|
weight: weight.toString(),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
});
|
||||||
});
|
} catch (error) {
|
||||||
|
console.error('Error calling OpenAI: ', error);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
const json = JSON.parse(response.output_text);
|
const json = JSON.parse(response.output_text);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user