Skip to content

Commit

Permalink
- parse response
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiasMue91 committed Feb 7, 2024
1 parent 7c55b5d commit 43e51a6
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion tools/opposite_finder.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,20 @@ <h1 class="text-2xl font-bold text-center mb-4">OppositeFinder</h1>
if (!response.ok) throw new Error('Network response was not ok.');

const data = await response.json();
displayOpposites(data.opposites || []);
let responseJsonData = {};

if (response.ok) {
const responseMessageData = data.choices[0].message.content;
const responseJsonStr = responseMessageData.substring(
responseMessageData.indexOf("{"),
responseMessageData.lastIndexOf("}") + 1
);
responseJsonData = JSON5.parse(responseJsonStr);
} else {
throw new Error('Error occurred while generating quote. Please try again.');
}

displayOpposites(responseJsonData.opposites || []);
} catch (error) {
console.error('Error:', error);
resultContainer.textContent = 'Failed to find opposites. Please try again.';
Expand Down

0 comments on commit 43e51a6

Please sign in to comment.