add try catch for openai responses api
This commit is contained in:
@@ -91,19 +91,26 @@ async function recommendationsLoader(
|
||||
title,
|
||||
}));
|
||||
|
||||
const response = await openAIClient.responses.create({
|
||||
store: false,
|
||||
prompt: {
|
||||
id: analysesRecommendationsPromptId,
|
||||
variables: {
|
||||
analyses: JSON.stringify(formattedAnalyses),
|
||||
results: JSON.stringify(formattedAnalysisResponses),
|
||||
gender: gender.value,
|
||||
age: age.toString(),
|
||||
weight: weight.toString(),
|
||||
let response;
|
||||
|
||||
try {
|
||||
response = await openAIClient.responses.create({
|
||||
store: false,
|
||||
prompt: {
|
||||
id: analysesRecommendationsPromptId,
|
||||
variables: {
|
||||
analyses: JSON.stringify(formattedAnalyses),
|
||||
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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user