koishi-plugin-openai-compatible 1.0.8 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/config.ts DELETED
@@ -1,91 +0,0 @@
1
- import { Schema } from 'koishi';
2
-
3
- export interface Config {
4
- // API 配置
5
- endpoint: string;
6
- apiKey: string;
7
- model: string;
8
-
9
- // 情绪分析配置
10
- enableEmotion: boolean;
11
- emotionEndpoint: string;
12
- emotionApiKey: string;
13
- emotionModel: string;
14
- emotionImages: Record<string, string>;
15
-
16
- // 提示词配置
17
- systemPrompt: string;
18
- emotionSystemPrompt: string;
19
-
20
- // 参数配置
21
- temperature: number;
22
- maxTokens: number;
23
- topP: number;
24
- frequencyPenalty: number;
25
- presencePenalty: number;
26
-
27
- // 黑名单配置
28
- blacklist: string[];
29
-
30
- // 冷却配置
31
- cooldown: number;
32
-
33
- // 命令名配置
34
- commandName: string;
35
-
36
- // 提示配置
37
- enableMessage: boolean;
38
- }
39
-
40
- export const Config: Schema<Config> = Schema.intersect([
41
- Schema.object({
42
- endpoint: Schema.string().default('https://api.openai.com/v1/chat/completions'),
43
- apiKey: Schema.string().default('').description('OpenAI API Key'),
44
- model: Schema.string().default('gpt-3.5-turbo'),
45
- }).description('API 配置'),
46
- Schema.object({
47
- enableEmotion: Schema.boolean().default(false).description('是否启用情绪分析'),
48
- emotionEndpoint: Schema.string().default('https://api.openai.com/v1/chat/completions'),
49
- emotionApiKey: Schema.string().default('').description('情绪分析 API Key'),
50
- emotionModel: Schema.string().default('gpt-3.5-turbo').description('推荐使用较快的模型'),
51
- emotionImages: Schema.dict(
52
- Schema.string().description('情绪表情包图片链接')
53
- ).default({
54
- '快乐': 'https://example.com/happy.gif',
55
- '开心': 'https://example.com/happy.gif',
56
- '高兴': 'https://example.com/happy.gif',
57
- '伤心': 'https://example.com/sad.gif',
58
- '难过': 'https://example.com/sad.gif',
59
- '悲伤': 'https://example.com/sad.gif',
60
- '生气': 'https://example.com/angry.gif',
61
- '愤怒': 'https://example.com/angry.gif',
62
- '惊讶': 'https://example.com/surprised.gif',
63
- '疑惑': 'https://example.com/confused.gif',
64
- '害怕': 'https://example.com/afraid.gif',
65
- '恐惧': 'https://example.com/afraid.gif',
66
- '平静': 'https://example.com/calm.gif',
67
- '中立': 'https://example.com/neutral.gif',
68
- }).description('情绪名称对应的表情包图片链接'),
69
- }).description('情绪分析配置'),
70
- Schema.object({
71
- systemPrompt: Schema.string()
72
- .default('你是一个友好的 AI 助手,请用简洁、准确的语言回答用户的问题。')
73
- .description('系统提示词'),
74
- emotionSystemPrompt: Schema.string()
75
- .default('你是一个情绪分析助手。分析给定的文本内容,并判断其中表达的情绪。\n\n情绪类型包括:快乐、开心、高兴、伤心、难过、悲伤、生气、愤怒、惊讶、疑惑、害怕、恐惧、平静、中立。\n\n请直接输出一个情绪名称,不要输出任何其他内容,不要解释,不要添加标点符号。\n\n例如:\n- "今天天气真好,我很开心!" -> 快乐\n- "这次考试失败了,我好难过。" -> 伤心\n- "什么?这太不可思议了!" -> 惊讶\n- "我不知道该怎么办。" -> 疑惑\n- "这真是太可怕了!" -> 害怕\n- "一切都很平静。" -> 平静')
76
- .description('情绪分析系统提示词'),
77
- }).description('提示词配置'),
78
- Schema.object({
79
- temperature: Schema.number().min(0).max(2).default(0.7).description('温度参数'),
80
- maxTokens: Schema.number().min(1).default(2000).description('最大令牌数'),
81
- topP: Schema.number().min(0).max(1).default(1).description('Top P 参数'),
82
- frequencyPenalty: Schema.number().min(-2).max(2).default(0).description('频率惩罚'),
83
- presencePenalty: Schema.number().min(-2).max(2).default(0).description('存在惩罚'),
84
- }).description('参数配置'),
85
- Schema.object({
86
- blacklist: Schema.array(Schema.string()).default([]).description('黑名单用户 ID'),
87
- cooldown: Schema.number().min(0).default(10000).description('请求冷却时间(毫秒)'),
88
- commandName: Schema.string().default('ai').description('自定义指令名称'),
89
- enableMessage: Schema.boolean().default(true).description('是否开启提示(关闭后所有错误提示都不会输出)'),
90
- }).description('其他配置'),
91
- ])
package/src/emotion.ts DELETED
@@ -1,37 +0,0 @@
1
- import type { OpenAICompatibleAPI } from './api';
2
- import type { Config } from './config';
3
- import type { Message, ChatCompletionRequest } from './types';
4
-
5
- export class EmotionAnalyzer {
6
- private api: OpenAICompatibleAPI;
7
- private config: Config;
8
-
9
- constructor(api: OpenAICompatibleAPI, config: Config) {
10
- this.api = api;
11
- this.config = config;
12
- }
13
-
14
- async analyzeEmotion(text: string): Promise<string> {
15
- const request: ChatCompletionRequest = {
16
- model: this.config.emotionModel,
17
- messages: [
18
- { role: 'system', content: this.config.emotionSystemPrompt } as Message,
19
- { role: 'user', content: text } as Message,
20
- ],
21
- temperature: 0.3,
22
- max_tokens: 50,
23
- };
24
-
25
- try {
26
- const emotion = await this.api.chatCompletion(request);
27
- return emotion.trim();
28
- } catch (error) {
29
- console.error('情绪分析失败:', error);
30
- return '';
31
- }
32
- }
33
-
34
- getEmotionImage(emotion: string): string | null {
35
- return this.config.emotionImages[emotion] || null;
36
- }
37
- }
package/src/locales/zh.ts DELETED
@@ -1,43 +0,0 @@
1
- export default {
2
- commands: {
3
- ai: {
4
- name: 'AI 对话',
5
- description: '与 AI 进行对话',
6
- input: '请输入要聊天的内容。',
7
- cooldown: '请求过于频繁,请等待 {0} 秒后再试。',
8
- blacklist: '您在黑名单中,无法使用此功能。',
9
- error: '请求失败: {0}',
10
- },
11
- admin: {
12
- add: {
13
- description: '添加黑名单',
14
- success: '已将用户 {0} 添加到黑名单。',
15
- },
16
- remove: {
17
- description: '移除黑名单',
18
- success: '已将用户 {0} 从黑名单中移除。',
19
- notFound: '用户 {0} 不在黑名单中。',
20
- },
21
- list: {
22
- description: '查看黑名单',
23
- empty: '黑名单为空。',
24
- title: '黑名单列表:',
25
- },
26
- clearcooldown: {
27
- description: '清除用户冷却',
28
- success: '已清除用户 {0} 的冷却时间。',
29
- },
30
- status: {
31
- description: '查看插件状态',
32
- title: '插件状态:',
33
- model: '模型: {0}',
34
- endpoint: '端点: {0}',
35
- emotion: '情绪分析: {0}',
36
- enabled: '已启用',
37
- disabled: '未启用',
38
- cooldown: '冷却时间: {0} 秒',
39
- blacklistCount: '黑名单数量: {0}',
40
- },
41
- },
42
- },
43
- };
package/src/storage.ts DELETED
@@ -1,27 +0,0 @@
1
- export interface CooldownData {
2
- lastRequestTime: number;
3
- }
4
-
5
- export class Storage {
6
- private cooldowns = new Map<string, CooldownData>();
7
-
8
- getCooldown(userId: string): CooldownData | undefined {
9
- return this.cooldowns.get(userId);
10
- }
11
-
12
- setCooldown(userId: string, data: CooldownData): void {
13
- this.cooldowns.set(userId, data);
14
- }
15
-
16
- deleteCooldown(userId: string): void {
17
- this.cooldowns.delete(userId);
18
- }
19
-
20
- isOnCooldown(userId: string, cooldownTime: number): boolean {
21
- const data = this.getCooldown(userId);
22
- if (!data) return false;
23
-
24
- const elapsed = Date.now() - data.lastRequestTime;
25
- return elapsed < cooldownTime;
26
- }
27
- }