Added image inputs; Version 1.0.0
This commit is contained in:
parent
a5d6163ef9
commit
a8e1a83e63
5 changed files with 54 additions and 9 deletions
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "aslobot-matrix",
|
||||
"version": "0.9.0",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"license": "ISC",
|
||||
"author": "",
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ const onAI = async (
|
|||
sender: string,
|
||||
repliedMessage?: string,
|
||||
repliedSender?: string,
|
||||
image?: Buffer<ArrayBuffer>,
|
||||
) => {
|
||||
if (text.startsWith(`${config.app.triggerPrefix}aileaderboard`)) {
|
||||
return;
|
||||
|
|
@ -87,6 +88,7 @@ const onAI = async (
|
|||
instructions,
|
||||
`${username}: ${textMod}`,
|
||||
`${repliedUsername}: ${repliedMessage}`,
|
||||
image,
|
||||
);
|
||||
|
||||
user.aiCost += responseAI.tokens * prices.text;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import {
|
||||
MatrixClient,
|
||||
MatrixEvent,
|
||||
MsgType,
|
||||
RoomEvent,
|
||||
type IContent,
|
||||
} from "matrix-js-sdk";
|
||||
|
|
@ -83,6 +84,30 @@ const registerModules = (client: MatrixClient) => {
|
|||
return;
|
||||
}
|
||||
|
||||
let image: Buffer<ArrayBuffer> | undefined;
|
||||
if (content.msgtype === MsgType.Image) {
|
||||
if (typeof content.url === "string") {
|
||||
const httpUrl = client.mxcUrlToHttp(
|
||||
content.url,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
true,
|
||||
true,
|
||||
);
|
||||
if (httpUrl) {
|
||||
const imageResponse = await fetch(httpUrl, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${client.getAccessToken()}`,
|
||||
},
|
||||
});
|
||||
const arrayBuffer = await imageResponse.arrayBuffer();
|
||||
image = Buffer.from(new Uint8Array(arrayBuffer));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const relatesTo = event.getContent()["m.relates_to"];
|
||||
const replyToId = relatesTo?.["m.in_reply_to"]?.event_id;
|
||||
let repliedMessage: string | undefined;
|
||||
|
|
@ -122,6 +147,7 @@ const registerModules = (client: MatrixClient) => {
|
|||
sender,
|
||||
repliedMessage,
|
||||
repliedSender,
|
||||
image,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ interface ICallback {
|
|||
sender: string,
|
||||
repliedMessage?: string,
|
||||
repliedSender?: string,
|
||||
image?: Buffer<ArrayBuffer>,
|
||||
) => void;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,8 +20,24 @@ const getTextGemini = async (
|
|||
instructions: IAIInstructions,
|
||||
input: string,
|
||||
oldInput?: string,
|
||||
inputImage?: Buffer<ArrayBuffer>,
|
||||
): Promise<AIResponseText> => {
|
||||
const inputContent: Content = {
|
||||
const inputContent: Content = inputImage
|
||||
? {
|
||||
role: "user",
|
||||
parts: [
|
||||
{
|
||||
text: input,
|
||||
},
|
||||
{
|
||||
inlineData: {
|
||||
mimeType: "image/png",
|
||||
data: Buffer.from(inputImage).toString("base64"),
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
: {
|
||||
role: "user",
|
||||
parts: [
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue