Skip to content

Commit

Permalink
adding fast ai switching feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Leask committed Jan 8, 2025
1 parent 7fd6afe commit 2f3ce51
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
12 changes: 12 additions & 0 deletions skills/10_engine.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { alan, bot, utilitas } from 'utilitas';

const NAME_HACK = {
'ChatGPT': '⚛️', 'Gemini': '♊️', 'Claude': '✴️', 'Mistral': 'Ⓜ️',
};

const NAME_HACK_REVERSE = utilitas.reverseKeyValues(NAME_HACK);

let configuredAi;

const action = async (ctx, next) => {
Expand All @@ -8,6 +14,11 @@ const action = async (ctx, next) => {
k => [k, ctx._.ai[k].priority]
).sort((x, y) => x[1] - y[1]);
ctx.firstAi = arrSort[0][0];
if (ctx.carry?.keyboards?.length) {
ctx.carry.keyboards.unshift(configuredAi.slice(0, 3).map(
x => ({ text: `/set --ai=${NAME_HACK[x] || x}` })
));
}
switch (ctx.session.config?.ai) {
case '@': ctx.selectedAi = configuredAi; break;
default:
Expand Down Expand Up @@ -49,6 +60,7 @@ const action = async (ctx, next) => {

const validateAi = val => {
assert(configuredAi, 'Preparing data for this option. Please try later.');
NAME_HACK_REVERSE[val] && (val = NAME_HACK_REVERSE[val]);
for (let name of [...configuredAi, '', '@']) {
if (utilitas.insensitiveCompare(val, name)) { return name; }
}
Expand Down
4 changes: 1 addition & 3 deletions skills/30_wording.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ export const { name, run, priority, func, cmds, help } = {
'¶ Set your default language.',
'Example 1: /lang Français',
'¶ Prompt the AI engine to translate or polish your text.',
'If `TO_LANG` is not specified, `config.lang` is used by default.',
"If `config.lang` not found, the bot's default language is used.",
'If bot has no default language, English is used by default.',
"Fallback order: `TO_LANG`, `config.lang`, `bot's lang`, `English`.",
'Example 2: /translate Chinese',
]),
cmds: {
Expand Down

0 comments on commit 2f3ce51

Please sign in to comment.