|
148 | 148 | // @description:zu Yengeza izimpendulo ze-AI ku-DuckDuckGo (inikwa amandla yi-GPT-4o!) |
149 | 149 | // @author KudoAI |
150 | 150 | // @namespace https://kudoai.com |
151 | | -// @version 2025.1.15.10 |
| 151 | +// @version 2025.1.15.11 |
152 | 152 | // @license MIT |
153 | 153 | // @icon https://assets.ddgpt.com/images/icons/duckduckgpt/icon48.png?v=06af076 |
154 | 154 | // @icon64 https://assets.ddgpt.com/images/icons/duckduckgpt/icon64.png?v=06af076 |
|
2599 | 2599 | // Add button listeners |
2600 | 2600 | appDiv.querySelectorAll(`.${app.cssPrefix}-chatbar-btn`).forEach(btn => { |
2601 | 2601 | 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' })) |
2611 | 2603 | chatTextarea.dispatchEvent(new KeyboardEvent('keydown', |
2612 | 2604 | { key: 'Enter', bubbles: true, cancelable: true })) |
2613 | 2605 | show.reply.src = 'shuffle' |
|
2729 | 2721 | } |
2730 | 2722 | } |
2731 | 2723 |
|
| 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 | + |
2732 | 2781 | // Define TOGGLE functions |
2733 | 2782 |
|
2734 | 2783 | const toggle = { |
|
3224 | 3273 | config.openAIkey = await Promise.race( |
3225 | 3274 | [session.getOAItoken(), new Promise(reject => setTimeout(reject, 3000))]) |
3226 | 3275 |
|
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 | | - |
3247 | 3276 | // Try diff API after 7s of no response |
3248 | 3277 | const iniAPI = get.related.api |
3249 | 3278 | get.related.query = query // expose to api.tryNew() in case modded |
|
3255 | 3284 | }, 7000) |
3256 | 3285 |
|
3257 | 3286 | // 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 }]) |
3259 | 3289 | return new Promise(resolve => { |
3260 | 3290 | const reqMethod = apis[get.related.api].method |
3261 | 3291 | const xhrConfig = { |
|
0 commit comments