Skip to content

Commit 88665df

Browse files
author
lrhh123
committed
fix: 修复连接相关的问题
1 parent 90cc4de commit 88665df

File tree

4 files changed

+66
-64
lines changed

4 files changed

+66
-64
lines changed

src/main/backend/backend.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,7 @@ class BKServer {
212212
);
213213
}
214214

215-
if (isKeywordMatch) {
216-
this.messageService.updateKeywordMatch(isKeywordMatch, isUseGptReply);
217-
}
218-
215+
this.messageService.updateKeywordMatch(isKeywordMatch, isUseGptReply);
219216
await this.strategyService.updateStrategies(ids);
220217

221218
res.json({ success: true });

src/main/backend/services/configService.ts

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,30 +33,31 @@ export class ConfigService {
3333
await this.platformConfigController.getByPlatformId(platformId);
3434

3535
const { settings } = platformConfig;
36-
if (!settings || !settings.active) {
36+
const settingsVal =
37+
typeof settings === 'string' ? JSON.parse(settings) : settings;
38+
if (!settingsVal || !settingsVal.active) {
3739
return this.configController.getConfig();
3840
}
3941

4042
const config = await this.configController.getConfig();
4143

4244
return {
4345
id: config.id,
44-
extract_phone: settings.extract_phone ?? config.extract_phone,
45-
extract_product: settings.extract_product ?? config.extract_product,
46-
save_path: settings.save_path ?? config.save_path,
47-
reply_speed: settings.reply_speed ?? config.reply_speed,
48-
reply_random_speed:
49-
settings.reply_random_speed ?? config.reply_random_speed,
50-
context_count: settings.context_count ?? config.context_count,
51-
wait_humans_time: settings.wait_humans_time ?? config.wait_humans_time,
52-
gpt_base_url: settings.gpt_base_url ?? config.gpt_base_url,
53-
gpt_key: settings.gpt_key ?? config.gpt_key,
54-
use_dify: settings.use_dify ?? config.use_dify,
55-
gpt_model: settings.gpt_model ?? config.gpt_model,
56-
gpt_temperature: settings.gpt_temperature ?? config.gpt_temperature,
57-
gpt_top_p: settings.gpt_top_p ?? config.gpt_top_p,
58-
stream: settings.stream ?? config.stream,
59-
default_reply: settings.default_reply ?? config.default_reply,
46+
extract_phone: config.extract_phone,
47+
extract_product: config.extract_product,
48+
save_path: config.save_path,
49+
reply_speed: config.reply_speed,
50+
reply_random_speed: config.reply_random_speed,
51+
wait_humans_time: config.wait_humans_time,
52+
context_count: settingsVal.contextCount ?? config.context_count,
53+
gpt_base_url: settingsVal.proxyAddress ?? config.gpt_base_url,
54+
gpt_key: settingsVal.apiKey ?? config.gpt_key,
55+
use_dify: settingsVal.useDify ?? config.use_dify,
56+
gpt_model: settingsVal.model ?? config.gpt_model,
57+
default_reply: settingsVal.defaultReply ?? config.default_reply,
58+
gpt_temperature: config.gpt_temperature,
59+
gpt_top_p: config.gpt_top_p,
60+
stream: config.stream,
6061
} as any;
6162
}
6263

src/main/backend/services/messageService.ts

Lines changed: 47 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,8 @@ export class MessageService {
316316
messages: MessageDTO[],
317317
session: Session,
318318
) {
319+
console.warn('getReplyTask', messages, session);
320+
319321
// 提前定义好回复内容
320322
let replyContent = null;
321323

@@ -333,29 +335,31 @@ export class MessageService {
333335
}
334336
}
335337

336-
// 如果关键词匹配无效或未启用关键词匹配,调用 OpenAI 生成回复
337-
if (!replyContent && this.isUseGptReply) {
338-
console.log(
339-
'Keyword matching failed or not used, using OpenAI to generate reply...',
340-
);
341-
if (config.use_dify) {
342-
replyContent = await this.getDifyResponse(
343-
config,
344-
messages,
345-
session.platform_id,
338+
if (!replyContent) {
339+
// 如果关键词匹配无效或未启用关键词匹配,调用 OpenAI 生成回复
340+
if (this.isUseGptReply) {
341+
console.log(
342+
'Keyword matching failed or not used, using OpenAI to generate reply...',
346343
);
344+
if (config.use_dify) {
345+
replyContent = await this.getDifyResponse(
346+
config,
347+
messages,
348+
session.platform_id,
349+
);
350+
} else {
351+
replyContent = await this.getOpenAIResponse(
352+
config,
353+
messages,
354+
session.platform_id,
355+
);
356+
}
347357
} else {
348-
replyContent = await this.getOpenAIResponse(
349-
config,
350-
messages,
351-
session.platform_id,
352-
);
358+
replyContent = {
359+
content: config.default_reply,
360+
msg_type: 'text' as MessageType,
361+
};
353362
}
354-
} else {
355-
replyContent = {
356-
content: config.default_reply,
357-
msg_type: 'text' as MessageType,
358-
};
359363
}
360364

361365
replyContent.msg_type = this.getMsgType(replyContent);
@@ -478,6 +482,7 @@ export class MessageService {
478482
found: true,
479483
};
480484
}
485+
481486
return {
482487
content: { content: '', msg_type: 'text' },
483488
found: false,
@@ -494,22 +499,40 @@ export class MessageService {
494499
return this.matchKeyword(pattern, msg);
495500
}
496501

497-
private matchKeyword(pattern: string, msg: string) {
502+
private matchKeyword(ptt: string, msg: string): boolean {
503+
let pattern = ptt.trim();
504+
505+
// 如果模式只是一个星号,它应该匹配任何消息。
506+
if (pattern === '*') {
507+
return true;
508+
}
509+
510+
// 合并连续的 '*' 字符为一个 '*'
511+
pattern = pattern.replace(/\*+/g, '*');
512+
513+
// 如果模式不包含 '*',则直接比较是否相等
498514
if (!pattern.includes('*')) {
499515
return pattern === msg;
500516
}
501517

502518
const parts = pattern.split('*');
503519
let lastIndex = 0;
520+
504521
// eslint-disable-next-line no-restricted-syntax
505522
for (const part of parts) {
506-
// eslint-disable-next-line no-continue
523+
// 跳过空字符串(它们来自模式开始、结束或连续 '*')
507524
if (part === '') continue;
525+
508526
const index = msg.indexOf(part, lastIndex);
509-
if (index === -1 || index < lastIndex) return false;
527+
// 如果找不到部分或部分不是按顺序出现,则匹配失败
528+
if (index === -1 || index < lastIndex) {
529+
return false;
530+
}
510531
lastIndex = index + part.length;
511532
}
512-
return true;
533+
534+
// 确保消息的剩余部分可以被模式尾部的 '*' 匹配
535+
return parts[parts.length - 1] === '' || lastIndex <= msg.length;
513536
}
514537

515538
private replaceSpecialTokens(replyMsg: string) {

src/renderer/pages/Settings/GptSettings.tsx

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515
SliderFilledTrack,
1616
SliderThumb,
1717
SliderTrack,
18-
HStack,
1918
InputGroup,
2019
InputRightElement,
2120
Button,
@@ -200,24 +199,6 @@ const GptSettings = () => {
200199
<SliderThumb />
201200
</Slider>
202201
</FormControl>
203-
204-
<FormControl>
205-
<HStack mb="4" mt="8px">
206-
<FormLabel htmlFor="stream" width="30%">
207-
Stream(可选)
208-
</FormLabel>
209-
<Switch
210-
id="stream"
211-
isChecked={gptSettings.stream}
212-
onChange={(e) => {
213-
setGptSettings({
214-
...gptSettings,
215-
stream: e.target.checked,
216-
});
217-
}}
218-
/>
219-
</HStack>
220-
</FormControl>
221202
</>
222203

223204
<FormControl>

0 commit comments

Comments
 (0)