mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-10 07:03:08 -04:00
move commands, fix bard issue
This commit is contained in:
parent
1011f2ff56
commit
8f2727456b
4 changed files with 1 additions and 1 deletions
77
commands/message/genai/ask.js
Normal file
77
commands/message/genai/ask.js
Normal file
|
@ -0,0 +1,77 @@
|
|||
const { createEmbed } = require('../../../labscore/utils/embed')
|
||||
const { editOrReply } = require('../../../labscore/utils/message')
|
||||
|
||||
const { iconPill, smallIconPill } = require('../../../labscore/utils/markdown')
|
||||
|
||||
const { Permissions } = require("detritus-client/lib/constants");
|
||||
const { STATIC_ICONS } = require('../../../labscore/utils/statics');
|
||||
const { webAsk } = require('../../../labscore/api/obelisk');
|
||||
const { hasFeature } = require('../../../labscore/utils/testing');
|
||||
|
||||
const URL_REGEX = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([^> \n]*)/
|
||||
|
||||
module.exports = {
|
||||
name: 'ask',
|
||||
label: 'text',
|
||||
metadata: {
|
||||
description: `${iconPill("generative_ai", "LIMITED TESTING")}\n${smallIconPill("reply", "Supports Replies")}\n\nAsk questions about web pages and videos. You have to **reply** to a message or embed containing a link to ask questions about it.`,
|
||||
description_short: 'Website prompts.',
|
||||
examples: ['ask why do they call it oven when you of in the cold food of out hot eat the food'],
|
||||
category: 'limited',
|
||||
usage: 'ask <question>'
|
||||
},
|
||||
permissionsClient: [Permissions.EMBED_LINKS, Permissions.SEND_MESSAGES, Permissions.USE_EXTERNAL_EMOJIS, Permissions.READ_MESSAGE_HISTORY],
|
||||
run: async (context, args) => {
|
||||
if(!await hasFeature(context, "flamingo/summary")) return;
|
||||
context.triggerTyping();
|
||||
|
||||
if(!args.text) return editOrReply(context, createEmbed("warning", context, "You need to ask a question."))
|
||||
if(!context.message.messageReference) return editOrReply(context, createEmbed("warning", context, "You need to reply to a message containing a link."))
|
||||
|
||||
let msg = await context.message.channel.fetchMessage(context.message.messageReference.messageId);
|
||||
|
||||
if(msg.content && msg.content.length) content = msg.content
|
||||
else if(msg.embeds?.length) for(const e of msg.embeds){
|
||||
if(e[1].description?.length) content = e[1].description;
|
||||
if(e[1].author?.url) content = e[1].author?.url;
|
||||
if(e[1].url) content = e[1].url
|
||||
}
|
||||
|
||||
let webUrl = content.match(URL_REGEX)
|
||||
if(!webUrl) return editOrReply(context, createEmbed("warning", context, `No URLs found.`))
|
||||
try{
|
||||
await editOrReply(context, createEmbed("ai_custom", "Generating response...", STATIC_ICONS.ai_summary))
|
||||
|
||||
let res = await webAsk(context, webUrl[0], args.text)
|
||||
if(!res.response.body.response) return editOrReply(context, createEmbed("error", context, "Unable to generate answer. Try again later."))
|
||||
|
||||
let description = "";
|
||||
let files = [];
|
||||
if(res.response.body.response.length <= 4000) description = res.response.body.response
|
||||
else {
|
||||
files.push({
|
||||
filename: `ask.${Date.now().toString(36)}.txt`,
|
||||
value: Buffer.from(res.response.body.response)
|
||||
})
|
||||
}
|
||||
|
||||
return editOrReply(context, {
|
||||
embeds: [createEmbed("defaultNoFooter", context, {
|
||||
author: {
|
||||
iconUrl: STATIC_ICONS.ai_summary,
|
||||
name: res.response.body.title || 'Answer from the page',
|
||||
url: webUrl[0]
|
||||
},
|
||||
description,
|
||||
footer: {
|
||||
text: "Generative AI is experimental. Response may be factually wrong or completely made up."
|
||||
}
|
||||
})],
|
||||
files
|
||||
})
|
||||
}catch(e){
|
||||
console.log(e)
|
||||
return editOrReply(context, createEmbed("error", context, e.response.body.message))
|
||||
}
|
||||
}
|
||||
};
|
159
commands/message/genai/bard.js
Normal file
159
commands/message/genai/bard.js
Normal file
|
@ -0,0 +1,159 @@
|
|||
const { createEmbed } = require('../../../labscore/utils/embed')
|
||||
const { editOrReply } = require('../../../labscore/utils/message')
|
||||
|
||||
const { STATIC_ICONS } = require('../../../labscore/utils/statics');
|
||||
|
||||
const superagent = require('superagent')
|
||||
const { iconPill, stringwrap } = require('../../../labscore/utils/markdown')
|
||||
|
||||
const { Permissions, InteractionCallbackTypes } = require("detritus-client/lib/constants");
|
||||
const { Components } = require('detritus-client/lib/utils');
|
||||
const { bard } = require('../../../labscore/api/obelisk');
|
||||
const { hasFeature } = require('../../../labscore/utils/testing');
|
||||
|
||||
module.exports = {
|
||||
name: 'bard',
|
||||
label: 'text',
|
||||
metadata: {
|
||||
description: `${iconPill("generative_ai", "LIMITED TESTING")}\n\nChat with <:bard:1163200801871765504> Bard.`,
|
||||
description_short: 'Chat with Bard.',
|
||||
examples: ['bard How many otter species are there?'],
|
||||
category: 'limited',
|
||||
usage: 'bard <input>'
|
||||
},
|
||||
args: [],
|
||||
permissionsClient: [Permissions.EMBED_LINKS, Permissions.SEND_MESSAGES, Permissions.ATTACH_FILES, Permissions.USE_EXTERNAL_EMOJIS, Permissions.READ_MESSAGE_HISTORY],
|
||||
run: async (context, args) => {
|
||||
if(!await hasFeature(context, "ai/bard")) return;
|
||||
|
||||
context.triggerTyping();
|
||||
if(!args.text) return editOrReply(context, createEmbed("warning", context, `Missing Parameter (text).`))
|
||||
|
||||
let input = args.text;
|
||||
|
||||
try{
|
||||
await editOrReply(context, createEmbed("ai_custom", context, STATIC_ICONS.ai_bard))
|
||||
|
||||
let res = await bard(context, input)
|
||||
res = res.response
|
||||
|
||||
let description = []
|
||||
let files = [];
|
||||
|
||||
if(!res.body.drafts) return editOrReply(context, createEmbed("error", context, `Bard returned an error. Try again later.`))
|
||||
|
||||
if(res.body.drafts[0].length <= 4000) description.push(res.body.drafts[0])
|
||||
else {
|
||||
files.push({
|
||||
filename: `chat.${Date.now().toString(36)}.txt`,
|
||||
value: Buffer.from(res.body.drafts[0])
|
||||
})
|
||||
}
|
||||
|
||||
if(!res.body.drafts || res.body.drafts?.length <= 1) return editOrReply(context, {
|
||||
embeds:[createEmbed("defaultNoFooter", context, {
|
||||
author: {
|
||||
name: stringwrap(args.text, 50, false),
|
||||
iconUrl: STATIC_ICONS.ai_bard_idle
|
||||
},
|
||||
description: description.join('\n'),
|
||||
footer: {
|
||||
text: `Bard • Generative AI is experimental. Response may be factually wrong or completely made up.`
|
||||
}
|
||||
})],
|
||||
files
|
||||
})
|
||||
// Draft support
|
||||
else {
|
||||
|
||||
let currentView;
|
||||
|
||||
const components = new Components({
|
||||
timeout: 100000,
|
||||
run: async (ctx) => {
|
||||
if (ctx.userId !== context.userId) return await ctx.respond(InteractionCallbackTypes.DEFERRED_UPDATE_MESSAGE);
|
||||
|
||||
// this sucks but works, ensures the newly selected option stays selected
|
||||
for (let i = 0; i < components.components[0].components[0].options.length; i++) {
|
||||
components.components[0].components[0].options[i].default = (components.components[0].components[0].options[i].value == ctx.data.values[0])
|
||||
}
|
||||
|
||||
draft = res.body.drafts[parseInt(ctx.data.values[0].replace('draft-', ''))]
|
||||
|
||||
description = []
|
||||
files = [];
|
||||
|
||||
if(draft.length <= 4000) description.push(draft)
|
||||
else {
|
||||
files.push({
|
||||
filename: `chat.${Date.now().toString(36)}.txt`,
|
||||
value: Buffer.from(draft)
|
||||
})
|
||||
}
|
||||
|
||||
currentView = createEmbed("defaultNoFooter", context, {
|
||||
author: {
|
||||
name: stringwrap(args.text, 50, false),
|
||||
iconUrl: STATIC_ICONS.ai_bard_idle
|
||||
},
|
||||
description: description.join('\n'),
|
||||
footer: {
|
||||
text: `Bard • Generative AI is experimental. Response may be factually wrong or completely made up.`
|
||||
}
|
||||
})
|
||||
|
||||
await ctx.editOrRespond({
|
||||
embeds:[currentView],
|
||||
files,
|
||||
components
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
let draftOptions = [];
|
||||
for (let i = 0; i < res.body.drafts.length; i++) {
|
||||
draftOptions.push({
|
||||
label: `Draft ${i + 1}: ${stringwrap(res.body.drafts[i], 50, false)}`,
|
||||
value: "draft-" + (i),
|
||||
default: false
|
||||
})
|
||||
}
|
||||
|
||||
components.addSelectMenu({
|
||||
placeholder: "View other drafts",
|
||||
customId: "bard-drafts",
|
||||
options: draftOptions
|
||||
})
|
||||
|
||||
setTimeout(()=>{
|
||||
editOrReply(context, {
|
||||
embeds:[currentView],
|
||||
components:[]
|
||||
})
|
||||
}, 100000)
|
||||
|
||||
currentView = createEmbed("defaultNoFooter", context, {
|
||||
author: {
|
||||
name: stringwrap(args.text, 50, false),
|
||||
iconUrl: STATIC_ICONS.ai_bard_idle
|
||||
},
|
||||
description: description.join('\n'),
|
||||
footer: {
|
||||
text: `Bard • Generative AI is experimental. Response may be factually wrong or completely made up.`
|
||||
}
|
||||
})
|
||||
|
||||
return editOrReply(context, {
|
||||
embeds:[currentView],
|
||||
files,
|
||||
components
|
||||
})
|
||||
}
|
||||
}catch(e){
|
||||
if(e.response?.body?.message) return editOrReply(context, createEmbed("warning", context, e.response.body.message))
|
||||
|
||||
console.log(e)
|
||||
return editOrReply(context, createEmbed("error", context, `Unable to generate text.`))
|
||||
}
|
||||
}
|
||||
};
|
94
commands/message/genai/palm.js
Normal file
94
commands/message/genai/palm.js
Normal file
|
@ -0,0 +1,94 @@
|
|||
const { createEmbed } = require('../../../labscore/utils/embed')
|
||||
const { editOrReply } = require('../../../labscore/utils/message')
|
||||
|
||||
const { STATIC_ICONS } = require('../../../labscore/utils/statics');
|
||||
|
||||
const superagent = require('superagent')
|
||||
const { iconPill, stringwrap, smallIconPill } = require('../../../labscore/utils/markdown')
|
||||
|
||||
const { Permissions } = require("detritus-client/lib/constants");
|
||||
const { palm2 } = require('../../../labscore/api/obelisk');
|
||||
const { hasFeature } = require('../../../labscore/utils/testing');
|
||||
|
||||
module.exports = {
|
||||
name: 'palm',
|
||||
label: 'text',
|
||||
aliases: ['palm2'],
|
||||
metadata: {
|
||||
description: `${iconPill("generative_ai", "LIMITED TESTING")}\n${smallIconPill("reply", "Supports Replies")}\n\nTalk to <:palm2:1163200685177839666> PaLM 2.`,
|
||||
description_short: 'Chat with PaLM 2.',
|
||||
examples: ['palm How many otter species are there?'],
|
||||
category: 'limited',
|
||||
usage: 'palm <input> [-prompt <prompt override>]'
|
||||
},
|
||||
args: [
|
||||
{ name: 'prompt', default: '', required: false, help: "The starting system prompt." },
|
||||
{ name: 'temperature', default: 0.25, required: false, help: "Model temperature." },
|
||||
],
|
||||
permissionsClient: [Permissions.EMBED_LINKS, Permissions.SEND_MESSAGES, Permissions.ATTACH_FILES, Permissions.USE_EXTERNAL_EMOJIS, Permissions.READ_MESSAGE_HISTORY],
|
||||
run: async (context, args) => {
|
||||
if(!await hasFeature(context, "ai/palm")) return;
|
||||
|
||||
context.triggerTyping();
|
||||
if(!args.text) return editOrReply(context, createEmbed("warning", context, `Missing Parameter (text).`))
|
||||
|
||||
let input = args.text;
|
||||
|
||||
let prompt = `You are a friendly chat bot designed to help people.\n- Today\'s date is ${new Date().toLocaleDateString('en-us', { weekday:"long", year:"numeric", month:"long", day:"numeric"})}\n- You should always use gender neutral pronouns when possible.\n- When answering a question, be concise and to the point.\n- Try to keep responses below 1000 characters. This does not apply to subjects that require more exhaustive or in-depth explanation.`
|
||||
if(args.prompt !== "") prompt = args.prompt
|
||||
|
||||
// Get content if the user replies to anything
|
||||
if(context.message.messageReference) {
|
||||
let msg = await context.message.channel.fetchMessage(context.message.messageReference.messageId);
|
||||
|
||||
if(msg.content && msg.content.length) input = msg.content
|
||||
else if(msg.embeds?.length) for(const e of msg.embeds) if(e[1].description?.length) { input = e[1].description; break; }
|
||||
|
||||
prompt = args.text
|
||||
if(args.prompt !== "") return editOrReply(context, createEmbed("warning", context, `Prompt parameter is unsupported for message replies.`))
|
||||
}
|
||||
|
||||
let model = "chat-bison-001"
|
||||
if(args.model && isLimitedTestUser(context.user)) model = args.model
|
||||
|
||||
let temperature = "0.25"
|
||||
if(args.temperature !== 0.25) temperature = parseFloat(args.temperature)
|
||||
|
||||
try{
|
||||
await editOrReply(context, createEmbed("ai_custom", context, STATIC_ICONS.ai_palm_idle))
|
||||
|
||||
let res = await palm2(context, prompt, input)
|
||||
res = res.response;
|
||||
|
||||
let description = []
|
||||
let files = [];
|
||||
|
||||
if(!res.body.output) return editOrReply(context, createEmbed("error", context, `PaLM 2 returned an error. Try again later.`))
|
||||
|
||||
if(res.body.output.length <= 4000) description.push(res.body.output)
|
||||
else {
|
||||
files.push({
|
||||
filename: `chat.${Date.now().toString(36)}.txt`,
|
||||
value: Buffer.from(res.body.output)
|
||||
})
|
||||
}
|
||||
|
||||
return editOrReply(context, {
|
||||
embeds:[createEmbed("defaultNoFooter", context, {
|
||||
author: {
|
||||
name: stringwrap(prompt, 50, false),
|
||||
iconUrl: STATIC_ICONS.ai_palm_idle
|
||||
},
|
||||
description: description.join('\n'),
|
||||
footer: {
|
||||
text: `PaLM 2 • Generative AI is experimental. Response may be factually wrong or completely made up.`
|
||||
}
|
||||
})],
|
||||
files
|
||||
})
|
||||
}catch(e){
|
||||
if(e.response.body?.message) return editOrReply(context, createEmbed("warning", context, e.response.body.message))
|
||||
return editOrReply(context, createEmbed("error", context, `Unable to generate text.`))
|
||||
}
|
||||
}
|
||||
};
|
69
commands/message/genai/summarize.js
Normal file
69
commands/message/genai/summarize.js
Normal file
|
@ -0,0 +1,69 @@
|
|||
const { createEmbed } = require('../../../labscore/utils/embed')
|
||||
const { editOrReply } = require('../../../labscore/utils/message')
|
||||
|
||||
const { iconPill, smallIconPill, citation } = require('../../../labscore/utils/markdown')
|
||||
|
||||
const { Permissions } = require("detritus-client/lib/constants");
|
||||
const { STATIC_ICONS } = require('../../../labscore/utils/statics');
|
||||
const { summarizeWebpage } = require('../../../labscore/api/obelisk');
|
||||
const { hasFeature } = require('../../../labscore/utils/testing');
|
||||
|
||||
const URL_REGEX = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([^> \n]*)/
|
||||
|
||||
module.exports = {
|
||||
name: 'summarize',
|
||||
aliases: ['summary','tldr'],
|
||||
label: 'text',
|
||||
metadata: {
|
||||
description: `${iconPill("generative_ai", "LIMITED TESTING")}\n${smallIconPill("reply", "Supports Replies")}\n\nSummarize web pages and articles.`,
|
||||
description_short: 'Website summaries.',
|
||||
examples: ['tldr https://www.theverge.com/2023/11/17/23965185/discord-is-shutting-down-its-ai-chatbot-clyde'],
|
||||
category: 'limited',
|
||||
usage: 'summarize'
|
||||
},
|
||||
permissionsClient: [Permissions.EMBED_LINKS, Permissions.SEND_MESSAGES, Permissions.USE_EXTERNAL_EMOJIS, Permissions.READ_MESSAGE_HISTORY],
|
||||
run: async (context, args) => {
|
||||
if(!await hasFeature(context, "flamingo/summary")) return;
|
||||
context.triggerTyping();
|
||||
|
||||
let content = args.text;
|
||||
if(context.message.messageReference) {
|
||||
let msg = await context.message.channel.fetchMessage(context.message.messageReference.messageId);
|
||||
|
||||
if(msg.content && msg.content.length) content = msg.content
|
||||
else if(msg.embeds?.length) for(const e of msg.embeds){
|
||||
if(e[1].description?.length) content = e[1].description;
|
||||
if(e[1].author?.url) content = e[1].author?.url;
|
||||
if(e[1].url) content = e[1].url
|
||||
}
|
||||
}
|
||||
|
||||
let webUrl = content.match(URL_REGEX)
|
||||
if(!webUrl) return editOrReply(context, createEmbed("warning", context, `No URLs found.`))
|
||||
try{
|
||||
await editOrReply(context, createEmbed("ai_custom", "Generating page summary...", STATIC_ICONS.ai_summary))
|
||||
|
||||
let res = await summarizeWebpage(context, webUrl[0])
|
||||
if(!res.response.body.summaries) return editOrReply(context, createEmbed("error", context, "Summary generation failed."))
|
||||
|
||||
let summaries = [];
|
||||
if(res.response.body.summary_type == 0) summaries = res.response.body.summaries
|
||||
else if (res.response.body.summary_type == 1) summaries = res.response.body.summaries.map((s, i)=>s.content + citation(i + 1, s.reference, 'Reference'))
|
||||
|
||||
return editOrReply(context, createEmbed("defaultNoFooter", context, {
|
||||
author: {
|
||||
iconUrl: STATIC_ICONS.ai_summary,
|
||||
name: res.response.body.title || 'Key points from the page',
|
||||
url: webUrl[0]
|
||||
},
|
||||
description: '- ' + summaries.join('\n- '),
|
||||
footer: {
|
||||
text: "Generative AI is experimental. Response may be factually incorrect or biased."
|
||||
}
|
||||
}))
|
||||
}catch(e){
|
||||
console.log(e)
|
||||
return editOrReply(context, createEmbed("error", context, e.response.body.message))
|
||||
}
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue