lint
This commit is contained in:
parent
9ef78e2b86
commit
9256eb3638
|
@ -665,12 +665,12 @@ export class MiMeta {
|
||||||
})
|
})
|
||||||
public googleAnalyticsMeasurementId: string | null;
|
public googleAnalyticsMeasurementId: string | null;
|
||||||
|
|
||||||
@Column('boolean',{
|
@Column('boolean', {
|
||||||
default: false,
|
default: false,
|
||||||
})
|
})
|
||||||
public enableLlmTranslator: boolean;
|
public enableLlmTranslator: boolean;
|
||||||
|
|
||||||
@Column('boolean',{
|
@Column('boolean', {
|
||||||
default: false,
|
default: false,
|
||||||
})
|
})
|
||||||
public enableLlmTranslatorRedisCache: boolean;
|
public enableLlmTranslatorRedisCache: boolean;
|
||||||
|
|
|
@ -187,15 +187,15 @@ export const paramDef = {
|
||||||
},
|
},
|
||||||
enableLlmTranslator: { type: 'boolean' },
|
enableLlmTranslator: { type: 'boolean' },
|
||||||
enableLlmTranslatorRedisCache: { type: 'boolean' },
|
enableLlmTranslatorRedisCache: { type: 'boolean' },
|
||||||
llmTranslatorRedisCacheTtl: { type: 'integer' , nullable: true},
|
llmTranslatorRedisCacheTtl: { type: 'integer' },
|
||||||
llmTranslatorBaseUrl: { type: 'string' , nullable: true},
|
llmTranslatorBaseUrl: { type: 'string', nullable: true },
|
||||||
llmTranslatorApiKey: { type: 'string' , nullable: true},
|
llmTranslatorApiKey: { type: 'string', nullable: true },
|
||||||
llmTranslatorModel: { type: 'string' , nullable: true},
|
llmTranslatorModel: { type: 'string', nullable: true },
|
||||||
llmTranslatorTemperature: { type: 'number' , nullable: true},
|
llmTranslatorTemperature: { type: 'number', nullable: true },
|
||||||
llmTranslatorTopP: { type: 'number' , nullable: true},
|
llmTranslatorTopP: { type: 'number', nullable: true },
|
||||||
llmTranslatorMaxTokens: { type: 'integer' , nullable: true},
|
llmTranslatorMaxTokens: { type: 'integer', nullable: true },
|
||||||
llmTranslatorSysPrompt: { type: 'string' , nullable: true},
|
llmTranslatorSysPrompt: { type: 'string', nullable: true },
|
||||||
llmTranslatorUserPrompt: { type: 'string' , nullable: true},
|
llmTranslatorUserPrompt: { type: 'string', nullable: true },
|
||||||
},
|
},
|
||||||
required: [],
|
required: [],
|
||||||
} as const;
|
} as const;
|
||||||
|
|
|
@ -5,16 +5,16 @@
|
||||||
|
|
||||||
import { URLSearchParams } from 'node:url';
|
import { URLSearchParams } from 'node:url';
|
||||||
import { Inject, Injectable } from '@nestjs/common';
|
import { Inject, Injectable } from '@nestjs/common';
|
||||||
|
import { OpenAI } from 'openai';
|
||||||
|
import * as Redis from 'ioredis';
|
||||||
import { Endpoint } from '@/server/api/endpoint-base.js';
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
||||||
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
|
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
|
||||||
import { HttpRequestService } from '@/core/HttpRequestService.js';
|
import { HttpRequestService } from '@/core/HttpRequestService.js';
|
||||||
import { GetterService } from '@/server/api/GetterService.js';
|
import { GetterService } from '@/server/api/GetterService.js';
|
||||||
import { RoleService } from '@/core/RoleService.js';
|
import { RoleService } from '@/core/RoleService.js';
|
||||||
import { ApiError } from '../../error.js';
|
|
||||||
import { MiMeta } from '@/models/_.js';
|
import { MiMeta } from '@/models/_.js';
|
||||||
import { DI } from '@/di-symbols.js';
|
import { DI } from '@/di-symbols.js';
|
||||||
import { OpenAI } from "openai";
|
import { ApiError } from '../../error.js';
|
||||||
import * as Redis from 'ioredis';
|
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
tags: ['notes'],
|
tags: ['notes'],
|
||||||
|
@ -96,7 +96,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
const res = await this.llmTranslate(note.text, ps.targetLang, note.id);
|
const res = await this.llmTranslate(note.text, ps.targetLang, note.id);
|
||||||
return {
|
return {
|
||||||
text: res,
|
text: res,
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.serverSettings.deeplAuthKey == null) {
|
if (this.serverSettings.deeplAuthKey == null) {
|
||||||
|
@ -136,26 +136,24 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async llmTranslate(text: string, targetLang: string, noteId: string): Promise<string | null> {
|
private async llmTranslate(text: string, targetLang: string, noteId: string): Promise<string> {
|
||||||
if (this.serverSettings.enableLlmTranslatorRedisCache) {
|
if (this.serverSettings.enableLlmTranslatorRedisCache) {
|
||||||
const key = `llmTranslate:${targetLang}:${noteId}`;
|
const key = `llmTranslate:${targetLang}:${noteId}`;
|
||||||
const cached = await this.redisClient.get(key);
|
const cached = await this.redisClient.get(key);
|
||||||
if (cached != null) {
|
if (cached != null) {
|
||||||
this.redisClient.expire(key, this.serverSettings.llmTranslatorRedisCacheTtl*60);
|
this.redisClient.expire(key, this.serverSettings.llmTranslatorRedisCacheTtl * 60);
|
||||||
return cached;
|
return cached;
|
||||||
}
|
}
|
||||||
const res = await this.getLlmRes(text, targetLang);
|
const res = await this.getLlmRes(text, targetLang);
|
||||||
await this.redisClient.set(key, res ?? '');
|
await this.redisClient.set(key, res);
|
||||||
this.redisClient.expire(key, this.serverSettings.llmTranslatorRedisCacheTtl*60);
|
this.redisClient.expire(key, this.serverSettings.llmTranslatorRedisCacheTtl * 60);
|
||||||
return res;
|
return res;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return this.getLlmRes(text, targetLang);
|
return this.getLlmRes(text, targetLang);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async getLlmRes(text: string, targetLang: string): Promise<string> {
|
||||||
private async getLlmRes(text: string, targetLang: string): Promise<string | null> {
|
|
||||||
const client = new OpenAI({
|
const client = new OpenAI({
|
||||||
baseURL: this.serverSettings.llmTranslatorBaseUrl,
|
baseURL: this.serverSettings.llmTranslatorBaseUrl,
|
||||||
apiKey: this.serverSettings.llmTranslatorApiKey ?? '',
|
apiKey: this.serverSettings.llmTranslatorApiKey ?? '',
|
||||||
|
@ -173,8 +171,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
temperature: this.serverSettings.llmTranslatorTemperature,
|
temperature: this.serverSettings.llmTranslatorTemperature,
|
||||||
max_tokens: this.serverSettings.llmTranslatorMaxTokens,
|
max_tokens: this.serverSettings.llmTranslatorMaxTokens,
|
||||||
top_p: this.serverSettings.llmTranslatorTopP,
|
top_p: this.serverSettings.llmTranslatorTopP,
|
||||||
})
|
});
|
||||||
|
|
||||||
return completion.choices[0].message.content
|
return completion.choices[0].message.content ?? '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,7 +125,6 @@ const llmTranslatorUserPrompt = ref<string>('');
|
||||||
const llmTranslatorRedisCacheEnabled = ref<boolean>(false);
|
const llmTranslatorRedisCacheEnabled = ref<boolean>(false);
|
||||||
const llmTranslatorRedisCacheTtl = ref<number>(0);
|
const llmTranslatorRedisCacheTtl = ref<number>(0);
|
||||||
|
|
||||||
|
|
||||||
async function init() {
|
async function init() {
|
||||||
const meta = await misskeyApi('admin/meta');
|
const meta = await misskeyApi('admin/meta');
|
||||||
deeplAuthKey.value = meta.deeplAuthKey ?? '';
|
deeplAuthKey.value = meta.deeplAuthKey ?? '';
|
||||||
|
|
Loading…
Reference in New Issue