Skip to content

Commit 97966db

Browse files
committed
Abstracted prompts.create() for easier maintenance/scalability
1 parent 87baf5e commit 97966db

File tree

4 files changed

+183
-102
lines changed

4 files changed

+183
-102
lines changed

amazongpt/greasemonkey/amazongpt.user.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// @description Adds the magic of AI to Amazon shopping
44
// @author KudoAI
55
// @namespace https://kudoai.com
6-
// @version 2025.1.15.6
6+
// @version 2025.1.15.7
77
// @license MIT
88
// @icon https://amazongpt.kudoai.com/assets/images/icons/amazongpt/black-gold-teal/icon48.png?v=0fddfc7
99
// @icon64 https://amazongpt.kudoai.com/assets/images/icons/amazongpt/black-gold-teal/icon64.png?v=0fddfc7
@@ -2153,15 +2153,7 @@
21532153
// Add button listeners
21542154
appDiv.querySelectorAll(`.${app.cssPrefix}-chatbar-btn`).forEach(btn => {
21552155
if (btn.id.endsWith('shuffle-btn')) btn.onclick = () => {
2156-
const randQAprompt = 'Generate a single random question on any topic then answer it. '
2157-
+ 'Don\'t talk about Canberra, Tokyo, blue whales, photosynthesis, oceans, ' // OpenAI bias
2158-
+ 'deserts, mindfulness meditation, the Fibonacci sequence, the liver, '
2159-
+ 'Jupiter, the Great Wall of China, Sheakespeare or da Vinci. '
2160-
+ 'Dont\'t talk about the benefits of practicing something regularly. ' // MixerBox AI bias
2161-
+ 'Try to give an answer that is 50-100 words. '
2162-
+ 'Dont\'t provide a question you generated before. '
2163-
+ 'Do not type anything but the question and answer. Reply in markdown.'
2164-
chatTextarea.value = augmentQuery(randQAprompt)
2156+
chatTextarea.value = augmentQuery(prompts.create({ type: 'randomQA' }))
21652157
chatTextarea.dispatchEvent(new KeyboardEvent('keydown',
21662158
{ key: 'Enter', bubbles: true, cancelable: true }))
21672159
}

bravegpt/greasemonkey/bravegpt.user.js

Lines changed: 59 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148
// @description:zu Yengeza izimpendulo ze-AI ku-Brave Search (inikwa amandla yi-GPT-4o!)
149149
// @author KudoAI
150150
// @namespace https://kudoai.com
151-
// @version 2025.1.15.7
151+
// @version 2025.1.15.8
152152
// @license MIT
153153
// @icon https://assets.bravegpt.com/images/icons/bravegpt/icon48.png?v=df624b0
154154
// @icon64 https://assets.bravegpt.com/images/icons/bravegpt/icon64.png?v=df624b0
@@ -2714,15 +2714,7 @@
27142714
// Add button listeners
27152715
appDiv.querySelectorAll(`.${app.cssPrefix}-chatbar-btn`).forEach(btn => {
27162716
if (btn.id.endsWith('shuffle-btn')) btn.onclick = () => {
2717-
const randQAprompt = 'Generate a single random question on any topic then answer it. '
2718-
+ 'Don\'t talk about Canberra, Tokyo, blue whales, photosynthesis, oceans, ' // OpenAI bias
2719-
+ 'deserts, mindfulness meditation, the Fibonacci sequence, the liver, '
2720-
+ 'Jupiter, the Great Wall of China, Sheakespeare or da Vinci. '
2721-
+ 'Dont\'t talk about the benefits of practicing something regularly. ' // MixerBox AI bias
2722-
+ 'Try to give an answer that is 50-100 words. '
2723-
+ 'Dont\'t provide a question you generated before. '
2724-
+ 'Do not type anything but the question and answer. Reply in markdown.'
2725-
chatTextarea.value = augmentQuery(randQAprompt)
2717+
chatTextarea.value = augmentQuery(prompts.create({ type: 'randomQA' }))
27262718
chatTextarea.dispatchEvent(new KeyboardEvent('keydown',
27272719
{ key: 'Enter', bubbles: true, cancelable: true }))
27282720
show.reply.src = 'shuffle'
@@ -2843,6 +2835,63 @@
28432835
}
28442836
}
28452837

2838+
// Define PROMPTS props/function
2839+
2840+
const prompts = {
2841+
2842+
create({ type, prevQuery }) {
2843+
const promptSrc = this[type],
2844+
modsToApply = promptSrc.mods?.flatMap(mod => typeof mod == 'string' ? mod : mod.mods)
2845+
let builtPrompt = `${promptSrc.base} ${modsToApply?.join(' ')}`.trim()
2846+
if (prevQuery) builtPrompt = builtPrompt.replace('${prevQuery}', prevQuery)
2847+
return builtPrompt
2848+
},
2849+
2850+
randomQA: {
2851+
base: 'Generate a single random question on any topic then answer it.',
2852+
mods: [
2853+
{ type: 'formatting', mods: [
2854+
'Try to give an answer that is 50-100 words.',
2855+
'Do not type anything but the question and answer.',
2856+
'Reply in markdown.'
2857+
]},
2858+
{ type: 'loopBias', mods: [
2859+
'Don\'t provide a question you generated before.',
2860+
'Don\'t talk about Canberra, Tokyo, blue whales, photosynthesis, oceans, deserts, '
2861+
+ 'mindfulness meditation, the Fibonacci sequence, the liver, Jupiter, '
2862+
+ 'the Great Wall of China, Shakespeare, or da Vinci.'
2863+
]},
2864+
{ type: 'MixerBox AI', mods: [
2865+
'Don\'t talk about the benefits of practicing something regularly.'
2866+
]}
2867+
]
2868+
},
2869+
2870+
relatedQueries: {
2871+
get base() {
2872+
return `Print me a numbered list of ${
2873+
get.related.replyIsQuestion ? 'possible answers to this question'
2874+
: 'queries related to this one' }:\n\n"\${prevQuery}"\n\n`
2875+
},
2876+
2877+
get mods() {
2878+
return get.related.replyIsQuestion ?
2879+
'Generate answers as if in reply to a search engine chatbot asking the question.'
2880+
: [{ type: 'variety', mods: [
2881+
'Make sure to suggest a variety that can even greatly deviate from the original topic.',
2882+
'For example, if the original query asked about someone\'s wife, '
2883+
+ 'a good related query could involve a different relative and using their name.',
2884+
'Another example, if the query asked about a game/movie/show, '
2885+
+ 'good related queries could involve pertinent characters.',
2886+
'Another example, if the original query asked how to learn JavaScript, '
2887+
+ 'good related queries could ask why/when/where instead, even replace JS w/ other langs.',
2888+
'But the key is variety. Do not be repetitive. '
2889+
+ 'You must entice user to want to ask one of your related queries.'
2890+
]}]
2891+
}
2892+
}
2893+
}
2894+
28462895
// Define TOGGLE functions
28472896

28482897
const toggle = {
@@ -3340,26 +3389,6 @@
33403389
config.openAIkey = await Promise.race(
33413390
[session.getOAItoken(), new Promise(reject => setTimeout(reject, 3000))])
33423391

3343-
// Init prompt
3344-
const rqPrompt = 'Print me a numbered list of '
3345-
+ `${ get.related.replyIsQuestion ? 'possible answers to this question'
3346-
: 'queries related to this one' }:\n\n"${query}"\n\n`
3347-
+ ( get.related.replyIsQuestion ?
3348-
'Generate answers as if in reply to a search engine chatbot asking the question.'
3349-
3350-
// Extended instructions for non-question queries
3351-
: ( 'Make sure to suggest a variety that can even greatly deviate from the original topic. '
3352-
+ 'For example, if the original query asked about someone\'s wife, '
3353-
+ ' a good related query could involve a different relative and using their name. '
3354-
+ 'Another example, if the query asked about a game/movie/show, '
3355-
+ ' good related queries could involve pertinent characters. '
3356-
+ 'Another example, if the original query asked how to learn JavaScript, '
3357-
+ ' good related queries could ask why/when/where instead, even replacing JS w/ other langs. '
3358-
+ 'But the key is variety. Do not be repetitive. '
3359-
+ ' You must entice user to want to ask one of your related queries.' ))
3360-
3361-
+ ` Reply in ${config.replyLang}`
3362-
33633392
// Try diff API after 7s of no response
33643393
const iniAPI = get.related.api
33653394
get.related.query = query // expose to api.tryNew() in case modded

duckduckgpt/greasemonkey/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)