separation of concerns
This commit is contained in:
20
src/main.ts
20
src/main.ts
@ -26,7 +26,7 @@ export const prisma = new PrismaClient();
|
|||||||
export const envConfig = {
|
export const envConfig = {
|
||||||
pleromaInstanceUrl: process.env.PLEROMA_INSTANCE_URL || "",
|
pleromaInstanceUrl: process.env.PLEROMA_INSTANCE_URL || "",
|
||||||
pleromaInstanceDomain: process.env.PLEROMA_INSTANCE_DOMAIN || "",
|
pleromaInstanceDomain: process.env.PLEROMA_INSTANCE_DOMAIN || "",
|
||||||
whitelistOnly: process.env.ONLY_WHITELIST === "true" ? true : false || "true",
|
whitelistOnly: process.env.ONLY_WHITELIST === "true" ? true : false,
|
||||||
whitelistedDomains: process.env.WHITELISTED_DOMAINS
|
whitelistedDomains: process.env.WHITELISTED_DOMAINS
|
||||||
? process.env.WHITELISTED_DOMAINS.split(",")
|
? process.env.WHITELISTED_DOMAINS.split(",")
|
||||||
: [process.env.PLEROMA_INSTANCE_DOMAIN],
|
: [process.env.PLEROMA_INSTANCE_DOMAIN],
|
||||||
@ -42,9 +42,14 @@ export const envConfig = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const ollamaConfig: OllamaConfigOptions = {
|
const ollamaConfig: OllamaConfigOptions = {
|
||||||
temperature: 1.2,
|
temperature: 1.4,
|
||||||
|
top_k: 100,
|
||||||
|
top_p: 0.8,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// this could be helpful
|
||||||
|
// https://replicate.com/blog/how-to-prompt-llama
|
||||||
|
|
||||||
const generateOllamaRequest = async (
|
const generateOllamaRequest = async (
|
||||||
notification: Notification
|
notification: Notification
|
||||||
): Promise<OllamaResponse | undefined> => {
|
): Promise<OllamaResponse | undefined> => {
|
||||||
@ -68,9 +73,9 @@ const generateOllamaRequest = async (
|
|||||||
const ollamaRequestBody: OllamaRequest = {
|
const ollamaRequestBody: OllamaRequest = {
|
||||||
model: ollamaModel,
|
model: ollamaModel,
|
||||||
system: ollamaSystemPrompt,
|
system: ollamaSystemPrompt,
|
||||||
prompt: `@${notification.status.account.fqn} says: ${trimInputData(
|
prompt: `[INST] @${
|
||||||
notification.status.content
|
notification.status.account.fqn
|
||||||
)}`,
|
} says: ${trimInputData(notification.status.content)} [/INST]`,
|
||||||
stream: false,
|
stream: false,
|
||||||
options: ollamaConfig,
|
options: ollamaConfig,
|
||||||
};
|
};
|
||||||
@ -162,4 +167,9 @@ console.log(
|
|||||||
console.log(
|
console.log(
|
||||||
`Accepting prompts from: ${envConfig.whitelistedDomains.join(", ")}`
|
`Accepting prompts from: ${envConfig.whitelistedDomains.join(", ")}`
|
||||||
);
|
);
|
||||||
|
console.log(
|
||||||
|
`Using model: ${envConfig.ollamaModel}\nConfig: ${JSON.stringify(
|
||||||
|
ollamaConfig
|
||||||
|
)}`
|
||||||
|
);
|
||||||
await beginFetchCycle();
|
await beginFetchCycle();
|
||||||
|
@ -2,7 +2,6 @@ import striptags from "striptags";
|
|||||||
import { prisma } from "./main.js";
|
import { prisma } from "./main.js";
|
||||||
import { envConfig } from "./main.js";
|
import { envConfig } from "./main.js";
|
||||||
import { Notification } from "../types.js";
|
import { Notification } from "../types.js";
|
||||||
import { deleteNotification } from "./api.js";
|
|
||||||
|
|
||||||
const trimInputData = (input: string): string => {
|
const trimInputData = (input: string): string => {
|
||||||
const strippedInput = striptags(input);
|
const strippedInput = striptags(input);
|
||||||
@ -26,9 +25,7 @@ const recordPendingResponse = async (notification: Notification) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const isFromWhitelistedDomain = async (
|
const isFromWhitelistedDomain = (notification: Notification): boolean => {
|
||||||
notification: Notification
|
|
||||||
): Promise<boolean> => {
|
|
||||||
try {
|
try {
|
||||||
const domain = notification.status.account.fqn.split("@")[1];
|
const domain = notification.status.account.fqn.split("@")[1];
|
||||||
if (envConfig.whitelistedDomains.includes(domain)) {
|
if (envConfig.whitelistedDomains.includes(domain)) {
|
||||||
@ -37,8 +34,6 @@ const isFromWhitelistedDomain = async (
|
|||||||
console.log(
|
console.log(
|
||||||
`Rejecting prompt request from non-whitelisted domain: ${domain}`
|
`Rejecting prompt request from non-whitelisted domain: ${domain}`
|
||||||
);
|
);
|
||||||
// delete the notification so we don't keep trying to fetch it
|
|
||||||
await deleteNotification(notification);
|
|
||||||
return false;
|
return false;
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error(`Error with domain check: ${error.message}`);
|
console.error(`Error with domain check: ${error.message}`);
|
||||||
|
Reference in New Issue
Block a user