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",
|
"name": "aslobot-matrix",
|
||||||
"version": "0.9.0",
|
"version": "1.0.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"author": "",
|
"author": "",
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ const onAI = async (
|
||||||
sender: string,
|
sender: string,
|
||||||
repliedMessage?: string,
|
repliedMessage?: string,
|
||||||
repliedSender?: string,
|
repliedSender?: string,
|
||||||
|
image?: Buffer<ArrayBuffer>,
|
||||||
) => {
|
) => {
|
||||||
if (text.startsWith(`${config.app.triggerPrefix}aileaderboard`)) {
|
if (text.startsWith(`${config.app.triggerPrefix}aileaderboard`)) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -87,6 +88,7 @@ const onAI = async (
|
||||||
instructions,
|
instructions,
|
||||||
`${username}: ${textMod}`,
|
`${username}: ${textMod}`,
|
||||||
`${repliedUsername}: ${repliedMessage}`,
|
`${repliedUsername}: ${repliedMessage}`,
|
||||||
|
image,
|
||||||
);
|
);
|
||||||
|
|
||||||
user.aiCost += responseAI.tokens * prices.text;
|
user.aiCost += responseAI.tokens * prices.text;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import {
|
import {
|
||||||
MatrixClient,
|
MatrixClient,
|
||||||
MatrixEvent,
|
MatrixEvent,
|
||||||
|
MsgType,
|
||||||
RoomEvent,
|
RoomEvent,
|
||||||
type IContent,
|
type IContent,
|
||||||
} from "matrix-js-sdk";
|
} from "matrix-js-sdk";
|
||||||
|
|
@ -83,6 +84,30 @@ const registerModules = (client: MatrixClient) => {
|
||||||
return;
|
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 relatesTo = event.getContent()["m.relates_to"];
|
||||||
const replyToId = relatesTo?.["m.in_reply_to"]?.event_id;
|
const replyToId = relatesTo?.["m.in_reply_to"]?.event_id;
|
||||||
let repliedMessage: string | undefined;
|
let repliedMessage: string | undefined;
|
||||||
|
|
@ -122,6 +147,7 @@ const registerModules = (client: MatrixClient) => {
|
||||||
sender,
|
sender,
|
||||||
repliedMessage,
|
repliedMessage,
|
||||||
repliedSender,
|
repliedSender,
|
||||||
|
image,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ interface ICallback {
|
||||||
sender: string,
|
sender: string,
|
||||||
repliedMessage?: string,
|
repliedMessage?: string,
|
||||||
repliedSender?: string,
|
repliedSender?: string,
|
||||||
|
image?: Buffer<ArrayBuffer>,
|
||||||
) => void;
|
) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,24 @@ const getTextGemini = async (
|
||||||
instructions: IAIInstructions,
|
instructions: IAIInstructions,
|
||||||
input: string,
|
input: string,
|
||||||
oldInput?: string,
|
oldInput?: string,
|
||||||
|
inputImage?: Buffer<ArrayBuffer>,
|
||||||
): Promise<AIResponseText> => {
|
): 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",
|
role: "user",
|
||||||
parts: [
|
parts: [
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue