history length

This commit is contained in:
ale 2024-07-15 19:16:36 +02:00
parent 4d98e3e67a
commit aede2b64a9

View File

@ -32,7 +32,8 @@ import * as config from './config.js';
if (attach.ok) {
let body = await attach.arrayBuffer(),
resized: Buffer
if (attachment.type === 'image' && (attachment.url.toString().toLowerCase().endsWith('.png') || attachment.url.toString().toLowerCase().match(/.*\.(jpe?g)$/))) {
if (attachment.type === 'image' && (attachment.url.toString().toLowerCase().endsWith('.png') ||
attachment.url.toString().toLowerCase().match(/.*\.(jpe?g)$/))) {
const image = await Jimp.read(Buffer.from(body))
if (image.getWidth() > 512) {
if (image.getMIME() === 'image/jpeg') {
@ -61,7 +62,7 @@ import * as config from './config.js';
if (status && status.visibility !== 'direct' && status.account.acct !== nick && status.content.trim() !== '') {
try {
const query = await client.search({
index: index,
index,
size: 100,
sort: [{ timestamp: { order: 'desc' } }],
query: {
@ -78,7 +79,7 @@ import * as config from './config.js';
acc.concat(h.entry.sort((a, b) => a.role < b.role ? 1 : -1)) : acc, [])
}
const content = ('' + status.content).replace(/<[^>]*>?/gm, '').trim()
let parts = []
let parts
if (content.match(new RegExp('^@' + nick + ' .* hilo.*$')) && status.inReplyToId) {
let id: string, s = await rest.v1.statuses.$select(status.id).fetch()
do {
@ -118,7 +119,7 @@ import * as config from './config.js';
}
}
const chat = model.startChat({
history: history && history.length > 0 ?
history: history.length > 0 ?
entries.length > 0 ?
[...history, ...entries] :
history :
@ -147,10 +148,10 @@ import * as config from './config.js';
role: 'model', parts: [{ text: answer }]
}
await client.index({
index: index,
index,
body: {
user: status.account.acct,
entry: entries ? [user].concat(entries.map(entry => ({
entry: entries.length > 0 ? [user].concat(entries.map(entry => ({
role: entry.role, parts: entry.parts.filter((p: { text: any; inlineData: { mimeType: string; }; }) =>
p.text || p.inlineData?.mimeType === 'image/png' || p.inlineData?.mimeType === 'image/jpeg')
}))).concat([bot]) : [user, bot],