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 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,9 +116,6 @@ 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);
|
||||
}
|
||||
} catch (error: any) {
|
||||
@ -134,15 +128,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`,
|
||||
|
Reference in New Issue
Block a user