slight refactor
This commit is contained in:
26
src/main.ts
26
src/main.ts
@ -31,7 +31,7 @@ const getNotifications = async () => {
|
|||||||
|
|
||||||
const notifications = await getNotifications();
|
const notifications = await getNotifications();
|
||||||
|
|
||||||
const storeUserData = async (notification: Notification) => {
|
const storeUserData = async (notification: Notification): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const user = await prisma.user.upsert({
|
const user = await prisma.user.upsert({
|
||||||
where: { userFqn: notification.status.account.fqn },
|
where: { userFqn: notification.status.account.fqn },
|
||||||
@ -99,16 +99,13 @@ const generateOllamaRequest = async (
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (await alreadyRespondedTo(notification)) {
|
if (await alreadyRespondedTo(notification)) {
|
||||||
// console.log(
|
|
||||||
// `Already responded to notification ID ${notification.status.id}. Canceling.`
|
|
||||||
// );
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await storeUserData(notification);
|
await storeUserData(notification);
|
||||||
const ollamaRequestBody: OllamaRequest = {
|
const ollamaRequestBody: OllamaRequest = {
|
||||||
model: process.env.OLLAMA_MODEL as string,
|
model: process.env.OLLAMA_MODEL as string,
|
||||||
system: process.env.OLLAMA_SYSTEM_PROMPT 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
|
notification.status.content
|
||||||
)}`,
|
)}`,
|
||||||
stream: false,
|
stream: false,
|
||||||
@ -119,9 +116,6 @@ const generateOllamaRequest = async (
|
|||||||
});
|
});
|
||||||
const ollamaResponse: OllamaResponse = await response.json();
|
const ollamaResponse: OllamaResponse = await response.json();
|
||||||
await storePromptData(notification, ollamaResponse);
|
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);
|
||||||
}
|
}
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
@ -134,15 +128,21 @@ const postReplyToStatus = async (
|
|||||||
ollamaResponseBody: OllamaResponse
|
ollamaResponseBody: OllamaResponse
|
||||||
) => {
|
) => {
|
||||||
try {
|
try {
|
||||||
const mentions = notification.status.mentions?.map((mention) => {
|
let mentions: string[];
|
||||||
return mention.acct;
|
const statusBody: NewStatusBody = {
|
||||||
});
|
|
||||||
let statusBody: NewStatusBody = {
|
|
||||||
content_type: "text/markdown",
|
content_type: "text/markdown",
|
||||||
status: ollamaResponseBody.response,
|
status: ollamaResponseBody.response,
|
||||||
in_reply_to_id: notification.status.id,
|
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(
|
const response = await fetch(
|
||||||
`${process.env.PLEROMA_INSTANCE_URL}/api/v1/statuses`,
|
`${process.env.PLEROMA_INSTANCE_URL}/api/v1/statuses`,
|
||||||
|
Reference in New Issue
Block a user