samlax12 commited on
Commit
5dcb51b
·
verified ·
1 Parent(s): 0f8d1c7

Update constants.ts

Browse files
Files changed (1) hide show
  1. constants.ts +32 -47
constants.ts CHANGED
@@ -1,20 +1,3 @@
1
- // 在文件开头添加解码函数
2
- const decodePresetKey = (encoded: string): string => {
3
- if (!encoded) return '';
4
- try {
5
- // 简单的反转 + base64 解码
6
- const reversed = encoded.split('').reverse().join('');
7
- return atob(reversed);
8
- } catch {
9
- return '';
10
- }
11
- };
12
-
13
- // 获取环境变量中的预置配置
14
- const PRESET_API_URL = import.meta.env.VITE_PRESET_API_URL || '';
15
- const PRESET_API_KEY = import.meta.env.VITE_PRESET_API_KEY || '';
16
- console.log('VITE_PRESET_API_URL:', import.meta.env.VITE_PRESET_API_URL);
17
- console.log('VITE_PRESET_API_KEY:', import.meta.env.VITE_PRESET_API_KEY);
18
  // API渠道配置接口
19
  export interface ApiChannel {
20
  id: string;
@@ -53,40 +36,52 @@ export interface AiRole {
53
  isActive: boolean;
54
  }
55
 
56
- // 默认渠道配置
57
  export const DEFAULT_CHANNELS: ApiChannel[] = [
58
- // 如果有预置配置,添加预置渠道
59
- ...(PRESET_API_URL && PRESET_API_KEY ? [{
60
- id: 'preset-channel',
61
- name: '预置服务',
62
- baseUrl: PRESET_API_URL,
63
- apiKey: decodePresetKey(PRESET_API_KEY),
64
  isDefault: true,
65
  isCustom: false,
66
  timeout: 30000,
67
- description: '系统预置的API服务',
68
  createdAt: new Date()
69
- }] : []),
70
  {
71
- id: 'openai-official',
72
- name: 'OpenAI 官方',
73
  baseUrl: 'https://api.openai.com/v1',
74
- apiKey: '',
75
- isDefault: !PRESET_API_URL, // 仅在没有预置渠道时作为默认
76
  isCustom: false,
77
  timeout: 30000,
78
- description: 'OpenAI 官方API服务',
79
  createdAt: new Date()
80
  }
81
  ];
82
 
83
- // 默认预设模型配置,使用预置渠道
84
  export const DEFAULT_MODELS: AiModel[] = [
 
 
 
 
 
 
 
 
 
 
 
 
 
85
  {
86
  id: 'gpt-4-mini-default',
87
  name: 'GPT-4.1 Mini',
88
  apiName: 'gpt-4.1-mini',
89
- channelId: PRESET_API_URL ? 'preset-channel' : 'openai-official',
90
  supportsImages: true,
91
  supportsReducedCapacity: true,
92
  category: 'GPT-4系列',
@@ -115,7 +110,7 @@ export const DEFAULT_ROLES: AiRole[] = [
115
  4. 发挥你的逻辑分析专长,为讨论提供理性和系统化的观点
116
 
117
  记住:你是Cognito,独一无二的逻辑分析师。`,
118
- modelId: 'gpt-4-mini-default',
119
  isActive: true
120
  },
121
  {
@@ -215,12 +210,6 @@ export class ModelConfigManager {
215
 
216
  // 更新渠道
217
  static updateChannel(id: string, updates: Partial<ApiChannel>): void {
218
- // 阻止修改预置渠道
219
- if (id === 'preset-channel') {
220
- console.warn('预置渠道不可修改');
221
- return;
222
- }
223
-
224
  const channels = this.getChannels();
225
  const index = channels.findIndex(ch => ch.id === id);
226
  if (index !== -1) {
@@ -235,12 +224,6 @@ export class ModelConfigManager {
235
 
236
  // 删除渠道
237
  static deleteChannel(id: string): void {
238
- // 阻止删除预置渠道
239
- if (id === 'preset-channel') {
240
- console.warn('预置渠道不可删除');
241
- return;
242
- }
243
-
244
  const channels = this.getChannels();
245
  const filtered = channels.filter(ch => ch.id !== id);
246
 
@@ -283,7 +266,9 @@ export class ModelConfigManager {
283
  }
284
  }
285
 
286
- if (!channel.apiKey?.trim()) {
 
 
287
  errors.push('API密钥不能为空');
288
  }
289
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  // API渠道配置接口
2
  export interface ApiChannel {
3
  id: string;
 
36
  isActive: boolean;
37
  }
38
 
39
+ // 默认渠道配置 - 预置可用的API配置
40
  export const DEFAULT_CHANNELS: ApiChannel[] = [
41
+ {
42
+ id: 'default-free-api',
43
+ name: '免费API服务',
44
+ baseUrl: 'https://api.chatanywhere.tech/v1',
45
+ apiKey: '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',
 
46
  isDefault: true,
47
  isCustom: false,
48
  timeout: 30000,
49
+ description: '预配置的免费API服务,开箱即用',
50
  createdAt: new Date()
51
+ },
52
  {
53
+ id: 'openai-official-backup',
54
+ name: 'OpenAI 官方(备用)',
55
  baseUrl: 'https://api.openai.com/v1',
56
+ apiKey: '', // 用户需要自行配置
57
+ isDefault: false,
58
  isCustom: false,
59
  timeout: 30000,
60
+ description: 'OpenAI 官方API服务(需要用户自行配置API密钥)',
61
  createdAt: new Date()
62
  }
63
  ];
64
 
65
+ // 默认预设模型配置(关联到预置渠道)
66
  export const DEFAULT_MODELS: AiModel[] = [
67
+ {
68
+ id: 'gpt-35-turbo-default',
69
+ name: 'GPT-3.5 Turbo',
70
+ apiName: 'gpt-3.5-turbo',
71
+ channelId: 'default-free-api',
72
+ supportsImages: false,
73
+ supportsReducedCapacity: true,
74
+ category: 'GPT-3.5系列',
75
+ maxTokens: 4096,
76
+ temperature: 0.7,
77
+ isCustom: false,
78
+ createdAt: new Date()
79
+ },
80
  {
81
  id: 'gpt-4-mini-default',
82
  name: 'GPT-4.1 Mini',
83
  apiName: 'gpt-4.1-mini',
84
+ channelId: 'default-free-api',
85
  supportsImages: true,
86
  supportsReducedCapacity: true,
87
  category: 'GPT-4系列',
 
110
  4. 发挥你的逻辑分析专长,为讨论提供理性和系统化的观点
111
 
112
  记住:你是Cognito,独一无二的逻辑分析师。`,
113
+ modelId: 'gpt-35-turbo-default',
114
  isActive: true
115
  },
116
  {
 
210
 
211
  // 更新渠道
212
  static updateChannel(id: string, updates: Partial<ApiChannel>): void {
 
 
 
 
 
 
213
  const channels = this.getChannels();
214
  const index = channels.findIndex(ch => ch.id === id);
215
  if (index !== -1) {
 
224
 
225
  // 删除渠道
226
  static deleteChannel(id: string): void {
 
 
 
 
 
 
227
  const channels = this.getChannels();
228
  const filtered = channels.filter(ch => ch.id !== id);
229
 
 
266
  }
267
  }
268
 
269
+ // 对于预置渠道,API密钥可以为空(将在使用时提醒用户配置)
270
+ // 对于自定义渠道,仍然要求API密钥
271
+ if (channel.isCustom && !channel.apiKey?.trim()) {
272
  errors.push('API密钥不能为空');
273
  }
274