Skip to content

Commit 78960ac

Browse files
committed
human commit message:
- update daily quote generator to randomize creativity and output erroneous responses gpt commit message: - added random creativity level generation when user does not select it - updated quote generation logic to ensure category or creativity values are set randomly if not chosen by the user - improved error handling to log full response when JSON parsing fails - modified prompt construction to enhance quote output - updated UI elements to show error details and ensure proper visibility states prompt for receiving the commit message: ``` Please write a concise but technical accurate commit message in the form of bullet points with lowercase first letters in a code block for the attached changes. You might use backticks if suitable. ```
1 parent 00bbdf1 commit 78960ac

File tree

1 file changed

+37
-14
lines changed

1 file changed

+37
-14
lines changed

tools/daily_quote_generator.html

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,11 @@ <h2 class="font-semibold text-lg">How to Use Daily Quote Generator</h2>
107107
const url = "https://gptgames.dev/dqg";
108108
let quoteHistory = [];
109109
let userSelectedCategory = false;
110+
let userSelectedCreativity = false;
110111
let lastCategory = '';
111112

112113
document.getElementById('creativity').addEventListener('input', function() {
114+
userSelectedCreativity = true;
113115
const creativityValue = this.value;
114116
document.getElementById('creativity-value').textContent = `${creativityValue}%`;
115117
});
@@ -130,16 +132,27 @@ <h2 class="font-semibold text-lg">How to Use Daily Quote Generator</h2>
130132
return newCategory;
131133
}
132134

135+
function getRandomCreativity() {
136+
return Math.floor(Math.random() * 101);
137+
}
138+
133139
function setRandomCategory() {
134140
if (!userSelectedCategory) {
135141
document.getElementById('category').value = getRandomCategory();
136142
}
137143
}
138144

139-
function generateQuote() {
140-
if (!userSelectedCategory) {
141-
setRandomCategory();
145+
function setRandomCreativity() {
146+
if (!userSelectedCreativity) {
147+
let creativityValue = getRandomCreativity();
148+
document.getElementById('creativity').value = creativityValue;
149+
document.getElementById('creativity-value').textContent = `${creativityValue}%`;
142150
}
151+
}
152+
153+
function generateQuote() {
154+
setRandomCategory();
155+
setRandomCreativity();
143156
const category = document.getElementById('category').value;
144157
const author = document.getElementById('author').value;
145158
const creativity = document.getElementById('creativity').value / 100;
@@ -151,7 +164,7 @@ <h2 class="font-semibold text-lg">How to Use Daily Quote Generator</h2>
151164
toggleButtonState();
152165

153166
const botMessage = `I am currently functioning as the Daily Quote Generator API. I will provide responses in this JSON format: {"quote":"generated quote", "author":"quote author"}`;
154-
const userMessage = `Generate a ${category} quote${author ? ` by ${author}` : ''}.`;
167+
const userMessage = `Generate a quote${author ? ` by ${author}` : ` for the category ${category}`}. DO NOT use the word "${category}" in the quote. Focus on making the quote sound very profound.`;
155168

156169
fetch('https://chatgpt.tobiasmue91.workers.dev/', {
157170
method: 'POST',
@@ -172,20 +185,29 @@ <h2 class="font-semibold text-lg">How to Use Daily Quote Generator</h2>
172185
})
173186
.then(data => {
174187
const responseMessageData = data.choices[0].message.content;
175-
const responseJsonStr = responseMessageData.substring(
176-
responseMessageData.indexOf("{"),
177-
responseMessageData.lastIndexOf("}") + 1
178-
);
179-
const responseJsonData = JSON5.parse(responseJsonStr);
180-
displayQuote(responseJsonData.quote, responseJsonData.author);
181-
addToHistory(responseJsonData.quote, responseJsonData.author, category);
182-
quoteContainer.classList.remove('hidden');
183-
shareButtons.classList.remove('hidden');
184-
saveButton.classList.remove('hidden');
188+
try {
189+
const responseJsonStr = responseMessageData.substring(
190+
responseMessageData.indexOf("{"),
191+
responseMessageData.lastIndexOf("}") + 1
192+
);
193+
const responseJsonData = JSON5.parse(responseJsonStr);
194+
displayQuote(responseJsonData.quote, responseJsonData.author);
195+
addToHistory(responseJsonData.quote, responseJsonData.author, category);
196+
quoteContainer.classList.remove('hidden');
197+
shareButtons.classList.remove('hidden');
198+
saveButton.classList.remove('hidden');
199+
} catch (error) {
200+
error.response = responseMessageData;
201+
console.log(responseMessageData);
202+
throw error;
203+
}
185204
})
186205
.catch(error => {
187206
console.error('Error:', error);
188207
resultContainer.textContent = 'Failed to generate a quote. Please try again.';
208+
if (error.response) {
209+
resultContainer.innerHTML += `<br><small><strong>JSON Response:</strong> ${error.response}</small>`;
210+
}
189211
quoteContainer.classList.remove('hidden');
190212
shareButtons.classList.add('hidden');
191213
saveButton.classList.add('hidden');
@@ -317,6 +339,7 @@ <h2 class="font-semibold text-lg">How to Use Daily Quote Generator</h2>
317339
updateSavedQuotesList();
318340
loadHistory();
319341
setRandomCategory();
342+
setRandomCreativity();
320343
});
321344

322345
generateQuote();

0 commit comments

Comments
 (0)