Skip to content

Commit 2def7d0

Browse files
committed
Abstracted prompts.create() for easier maintenance/scalability ↞ [auto-sync from https://github.com/adamlui/ai-web-extensions/tree/main/duckduckgpt]
1 parent 651e63b commit 2def7d0

File tree

1 file changed

+61
-31
lines changed

1 file changed

+61
-31
lines changed

chatgpt/duckduckgpt/duckduckgpt.user.js

Lines changed: 61 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148
// @description:zu Yengeza izimpendulo ze-AI ku-DuckDuckGo (inikwa amandla yi-GPT-4o!)
149149
// @author KudoAI
150150
// @namespace https://kudoai.com
151-
// @version 2025.1.15.10
151+
// @version 2025.1.15.11
152152
// @license MIT
153153
// @icon https://assets.ddgpt.com/images/icons/duckduckgpt/icon48.png?v=06af076
154154
// @icon64 https://assets.ddgpt.com/images/icons/duckduckgpt/icon64.png?v=06af076
@@ -2599,15 +2599,7 @@
25992599
// Add button listeners
26002600
appDiv.querySelectorAll(`.${app.cssPrefix}-chatbar-btn`).forEach(btn => {
26012601
if (btn.id.endsWith('shuffle-btn')) btn.onclick = () => {
2602-
const randQAprompt = 'Generate a single random question on any topic then answer it. '
2603-
+ 'Don\'t talk about Canberra, Tokyo, blue whales, photosynthesis, oceans, ' // OpenAI bias
2604-
+ 'deserts, mindfulness meditation, the Fibonacci sequence, the liver, '
2605-
+ 'Jupiter, the Great Wall of China, Sheakespeare or da Vinci. '
2606-
+ 'Dont\'t talk about the benefits of practicing something regularly. ' // MixerBox AI bias
2607-
+ 'Try to give an answer that is 50-100 words. '
2608-
+ 'Dont\'t provide a question you generated before. '
2609-
+ 'Do not type anything but the question and answer. Reply in markdown.'
2610-
chatTextarea.value = augmentQuery(randQAprompt)
2602+
chatTextarea.value = augmentQuery(prompts.create({ type: 'randomQA' }))
26112603
chatTextarea.dispatchEvent(new KeyboardEvent('keydown',
26122604
{ key: 'Enter', bubbles: true, cancelable: true }))
26132605
show.reply.src = 'shuffle'
@@ -2729,6 +2721,63 @@
27292721
}
27302722
}
27312723

2724+
// Define PROMPTS props/function
2725+
2726+
const prompts = {
2727+
2728+
create({ type, prevQuery }) {
2729+
const promptSrc = this[type],
2730+
modsToApply = promptSrc.mods?.flatMap(mod => typeof mod == 'string' ? mod : mod.mods)
2731+
let builtPrompt = `${promptSrc.base} ${modsToApply?.join(' ')}`.trim()
2732+
if (prevQuery) builtPrompt = builtPrompt.replace('${prevQuery}', prevQuery)
2733+
return builtPrompt
2734+
},
2735+
2736+
randomQA: {
2737+
base: 'Generate a single random question on any topic then answer it.',
2738+
mods: [
2739+
{ type: 'formatting', mods: [
2740+
'Try to give an answer that is 50-100 words.',
2741+
'Do not type anything but the question and answer.',
2742+
'Reply in markdown.'
2743+
]},
2744+
{ type: 'loopBias', mods: [
2745+
'Don\'t provide a question you generated before.',
2746+
'Don\'t talk about Canberra, Tokyo, blue whales, photosynthesis, oceans, deserts, '
2747+
+ 'mindfulness meditation, the Fibonacci sequence, the liver, Jupiter, '
2748+
+ 'the Great Wall of China, Shakespeare, or da Vinci.'
2749+
]},
2750+
{ type: 'MixerBox AI', mods: [
2751+
'Don\'t talk about the benefits of practicing something regularly.'
2752+
]}
2753+
]
2754+
},
2755+
2756+
relatedQueries: {
2757+
get base() {
2758+
return `Print me a numbered list of ${
2759+
get.related.replyIsQuestion ? 'possible answers to this question'
2760+
: 'queries related to this one' }:\n\n"\${prevQuery}"\n\n`
2761+
},
2762+
2763+
get mods() {
2764+
return get.related.replyIsQuestion ?
2765+
'Generate answers as if in reply to a search engine chatbot asking the question.'
2766+
: [{ type: 'variety', mods: [
2767+
'Make sure to suggest a variety that can even greatly deviate from the original topic.',
2768+
'For example, if the original query asked about someone\'s wife, '
2769+
+ 'a good related query could involve a different relative and using their name.',
2770+
'Another example, if the query asked about a game/movie/show, '
2771+
+ 'good related queries could involve pertinent characters.',
2772+
'Another example, if the original query asked how to learn JavaScript, '
2773+
+ 'good related queries could ask why/when/where instead, even replace JS w/ other langs.',
2774+
'But the key is variety. Do not be repetitive. '
2775+
+ 'You must entice user to want to ask one of your related queries.'
2776+
]}]
2777+
}
2778+
}
2779+
}
2780+
27322781
// Define TOGGLE functions
27332782

27342783
const toggle = {
@@ -3224,26 +3273,6 @@
32243273
config.openAIkey = await Promise.race(
32253274
[session.getOAItoken(), new Promise(reject => setTimeout(reject, 3000))])
32263275

3227-
// Init prompt
3228-
const rqPrompt = 'Print me a numbered list of '
3229-
+ `${ get.related.replyIsQuestion ? 'possible answers to this question'
3230-
: 'queries related to this one' }:\n\n"${query}"\n\n`
3231-
+ ( get.related.replyIsQuestion ?
3232-
'Generate answers as if in reply to a search engine chatbot asking the question.'
3233-
3234-
// Extended instructions for non-question queries
3235-
: ( 'Make sure to suggest a variety that can even greatly deviate from the original topic. '
3236-
+ 'For example, if the original query asked about someone\'s wife, '
3237-
+ ' a good related query could involve a different relative and using their name. '
3238-
+ 'Another example, if the query asked about a game/movie/show, '
3239-
+ ' good related queries could involve pertinent characters. '
3240-
+ 'Another example, if the original query asked how to learn JavaScript, '
3241-
+ ' good related queries could ask why/when/where instead, even replacing JS w/ other langs. '
3242-
+ 'But the key is variety. Do not be repetitive. '
3243-
+ ' You must entice user to want to ask one of your related queries.' ))
3244-
3245-
+ ` Reply in ${config.replyLang}`
3246-
32473276
// Try diff API after 7s of no response
32483277
const iniAPI = get.related.api
32493278
get.related.query = query // expose to api.tryNew() in case modded
@@ -3255,7 +3284,8 @@
32553284
}, 7000)
32563285

32573286
// Get related queries
3258-
const payload = await api.createPayload(get.related.api, [{ role: 'user', content: rqPrompt }])
3287+
const rqPrompt = augmentQuery(prompts.create({ type: 'relatedQueries', prevQuery: query })),
3288+
payload = await api.createPayload(get.related.api, [{ role: 'user', content: rqPrompt }])
32593289
return new Promise(resolve => {
32603290
const reqMethod = apis[get.related.api].method
32613291
const xhrConfig = {

0 commit comments

Comments
 (0)