mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-17 10:06:17 +08:00
refactor(server): config system (#11081)
This commit is contained in:
@@ -3,12 +3,8 @@ import { Logger } from '@nestjs/common';
|
||||
import { AiPrompt } from '@prisma/client';
|
||||
import Mustache from 'mustache';
|
||||
|
||||
import {
|
||||
getTokenEncoder,
|
||||
PromptConfig,
|
||||
PromptMessage,
|
||||
PromptParams,
|
||||
} from '../types';
|
||||
import { PromptConfig, PromptMessage, PromptParams } from '../providers';
|
||||
import { getTokenEncoder } from '../types';
|
||||
|
||||
// disable escaping
|
||||
Mustache.escape = (text: string) => text;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Logger } from '@nestjs/common';
|
||||
import { AiPrompt, PrismaClient } from '@prisma/client';
|
||||
|
||||
import { PromptConfig, PromptMessage } from '../types';
|
||||
import { PromptConfig, PromptMessage } from '../providers';
|
||||
|
||||
type Prompt = Omit<
|
||||
AiPrompt,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Injectable, OnModuleInit } from '@nestjs/common';
|
||||
import { Injectable, OnApplicationBootstrap } from '@nestjs/common';
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
|
||||
import {
|
||||
@@ -6,17 +6,17 @@ import {
|
||||
PromptConfigSchema,
|
||||
PromptMessage,
|
||||
PromptMessageSchema,
|
||||
} from '../types';
|
||||
} from '../providers';
|
||||
import { ChatPrompt } from './chat-prompt';
|
||||
import { refreshPrompts } from './prompts';
|
||||
|
||||
@Injectable()
|
||||
export class PromptService implements OnModuleInit {
|
||||
export class PromptService implements OnApplicationBootstrap {
|
||||
private readonly cache = new Map<string, ChatPrompt>();
|
||||
|
||||
constructor(private readonly db: PrismaClient) {}
|
||||
|
||||
async onModuleInit() {
|
||||
async onApplicationBootstrap() {
|
||||
this.cache.clear();
|
||||
await refreshPrompts(this.db);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user