Compare commits

..

2 Commits

Author SHA1 Message Date
c4a5de31f3 refactor to make a little more sense at a glance 2025-06-30 17:19:24 -04:00
396ef9d2be slight refactor 2025-06-30 17:11:54 -04:00

View File

@ -31,7 +31,7 @@ const getNotifications = async () => {
const notifications = await getNotifications();
const storeUserData = async (notification: Notification) => {
const storeUserData = async (notification: Notification): Promise<void> => {
try {
const user = await prisma.user.upsert({
where: { userFqn: notification.status.account.fqn },
@ -99,16 +99,13 @@ const generateOllamaRequest = async (
return;
}
if (await alreadyRespondedTo(notification)) {
// console.log(
// `Already responded to notification ID ${notification.status.id}. Canceling.`
// );
return;
}
await storeUserData(notification);
const ollamaRequestBody: OllamaRequest = {
model: process.env.OLLAMA_MODEL as string,
system: process.env.OLLAMA_SYSTEM_PROMPT as string,
prompt: `@${notification.status.account.fqn} asks: ${striptags(
prompt: `@${notification.status.account.fqn} says: ${striptags(
notification.status.content
)}`,
stream: false,
@ -119,10 +116,8 @@ const generateOllamaRequest = async (
});
const ollamaResponse: OllamaResponse = await response.json();
await storePromptData(notification, ollamaResponse);
// console.log(
// `${notification.status.account.fqn} asked:\n${notification.status.content}\nResponse:\n${ollamaResponse.response}`
// );
await postReplyToStatus(notification, ollamaResponse);
// await postReplyToStatus(notification, ollamaResponse);
return ollamaResponse;
}
} catch (error: any) {
throw new Error(error.message);
@ -134,15 +129,21 @@ const postReplyToStatus = async (
ollamaResponseBody: OllamaResponse
) => {
try {
const mentions = notification.status.mentions?.map((mention) => {
return mention.acct;
});
let statusBody: NewStatusBody = {
let mentions: string[];
const statusBody: NewStatusBody = {
content_type: "text/markdown",
status: ollamaResponseBody.response,
in_reply_to_id: notification.status.id,
to: mentions,
};
if (
notification.status.mentions &&
notification.status.mentions.length > 0
) {
mentions = notification.status.mentions.map((mention) => {
return mention.acct;
});
statusBody.to = mentions;
}
const response = await fetch(
`${process.env.PLEROMA_INSTANCE_URL}/api/v1/statuses`,
@ -166,8 +167,11 @@ const postReplyToStatus = async (
if (notifications) {
await Promise.all(
notifications.map((notification) => {
generateOllamaRequest(notification);
notifications.map(async (notification) => {
const ollamaResponse = await generateOllamaRequest(notification);
if (ollamaResponse) {
postReplyToStatus(notification, ollamaResponse);
}
})
);
}