qwen-alpha 1.0.14 → 1.0.16
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/package.json
CHANGED
|
@@ -55,26 +55,22 @@ async function messageHandler(ctx) {
|
|
|
55
55
|
let contextMessages = [];
|
|
56
56
|
let session = ctx.state.session;
|
|
57
57
|
|
|
58
|
-
// Если сессии нет в группе - создаём новую
|
|
59
|
-
if (!session && !isPrivate) {
|
|
60
|
-
session = sessionService.create({
|
|
61
|
-
userId,
|
|
62
|
-
chatId,
|
|
63
|
-
rootMessageId: ctx.message.message_id,
|
|
64
|
-
chatType: ctx.chat.type,
|
|
65
|
-
chatTitle: ctx.chat.title,
|
|
66
|
-
});
|
|
67
|
-
ctx.state.session = session;
|
|
68
|
-
statsService.incrementSessionCreated();
|
|
69
|
-
}
|
|
70
|
-
|
|
71
58
|
if (session) {
|
|
72
|
-
// Если это reply на сообщение в сессии
|
|
59
|
+
// Если это reply на сообщение в сессии — получаем полную цепочку
|
|
73
60
|
const replyToMessageId = ctx.message?.reply_to_message?.message_id;
|
|
74
61
|
|
|
75
62
|
if (replyToMessageId && session.message_tree[replyToMessageId]) {
|
|
76
|
-
// Получаем цепочку сообщений
|
|
77
63
|
contextMessages = sessionService.getMessageChain(session, replyToMessageId);
|
|
64
|
+
} else {
|
|
65
|
+
// Если не reply, берём последние N сообщений из сессии
|
|
66
|
+
const allMessages = Object.values(session.message_tree)
|
|
67
|
+
.sort((a, b) => new Date(a.created_at) - new Date(b.created_at))
|
|
68
|
+
.slice(-10); // Последние 10 сообщений
|
|
69
|
+
|
|
70
|
+
contextMessages = allMessages.map(msg => ({
|
|
71
|
+
role: msg.user_id === 'bot' ? 'assistant' : 'user',
|
|
72
|
+
content: msg.text || '',
|
|
73
|
+
}));
|
|
78
74
|
}
|
|
79
75
|
}
|
|
80
76
|
|
|
@@ -137,9 +133,18 @@ async function messageHandler(ctx) {
|
|
|
137
133
|
text: prompt,
|
|
138
134
|
type: 'user_question',
|
|
139
135
|
});
|
|
140
|
-
|
|
141
|
-
// Добавляем ответ бота
|
|
142
|
-
//
|
|
136
|
+
|
|
137
|
+
// Добавляем ответ бота
|
|
138
|
+
const botMessageId = ctx.message.message_id + 1; // Приблизительно
|
|
139
|
+
sessionService.addMessage({
|
|
140
|
+
sessionId: session.session_id,
|
|
141
|
+
chatId,
|
|
142
|
+
messageId: botMessageId,
|
|
143
|
+
userId: 'bot',
|
|
144
|
+
text: responseText,
|
|
145
|
+
type: 'bot_response',
|
|
146
|
+
parent_id: ctx.message.message_id,
|
|
147
|
+
});
|
|
143
148
|
}
|
|
144
149
|
|
|
145
150
|
// Обновление статистики
|
|
@@ -38,27 +38,32 @@ async function sessionMiddleware(ctx, next) {
|
|
|
38
38
|
ctx.state.sessionKey = sessionKey;
|
|
39
39
|
}
|
|
40
40
|
} else {
|
|
41
|
-
// Групповой чат -
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
ctx.
|
|
51
|
-
ctx.
|
|
52
|
-
|
|
41
|
+
// Групповой чат - всегда используем последнюю активную сессию
|
|
42
|
+
const chatSessions = sessionService.getChatSessions(chatId);
|
|
43
|
+
let activeSession = chatSessions.find(s => s.status === 'active');
|
|
44
|
+
|
|
45
|
+
// Если сессии нет - создаём новую
|
|
46
|
+
if (!activeSession) {
|
|
47
|
+
activeSession = sessionService.create({
|
|
48
|
+
userId,
|
|
49
|
+
chatId,
|
|
50
|
+
rootMessageId: ctx.message?.message_id || 1,
|
|
51
|
+
chatType: ctx.chat.type,
|
|
52
|
+
chatTitle: ctx.chat.title,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (activeSession) {
|
|
57
|
+
ctx.state.session = activeSession;
|
|
58
|
+
ctx.state.sessionKey = `chat:${chatId}`;
|
|
53
59
|
}
|
|
54
60
|
|
|
55
|
-
// Если
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
if (activeSession) {
|
|
60
|
-
ctx.state.
|
|
61
|
-
ctx.state.sessionKey = `chat:${chatId}`;
|
|
61
|
+
// Если есть reply, проверяем принадлежит ли оно этой сессии
|
|
62
|
+
const replyToMessageId = ctx.message?.reply_to_message?.message_id;
|
|
63
|
+
if (replyToMessageId && activeSession) {
|
|
64
|
+
// Проверяем есть ли сообщение в дереве сессии
|
|
65
|
+
if (activeSession.message_tree[replyToMessageId]) {
|
|
66
|
+
ctx.state.replyToSession = true;
|
|
62
67
|
}
|
|
63
68
|
}
|
|
64
69
|
}
|
|
@@ -84,15 +84,18 @@ class QwenService {
|
|
|
84
84
|
.map(msg => `${msg.role === 'assistant' ? 'Assistant' : 'User'}: ${msg.content}`)
|
|
85
85
|
.join('\n');
|
|
86
86
|
|
|
87
|
-
|
|
87
|
+
// Явно указываем что это продолжение диалога
|
|
88
|
+
fullPrompt = `Продолжи диалог. Контекст:\n${contextText}\n\nUser: ${code}`;
|
|
88
89
|
}
|
|
89
90
|
|
|
90
91
|
// Создаём временный файл с промптом
|
|
91
92
|
const tempFile = path.join(os.tmpdir(), `qwen-alpha-${Date.now()}-${Math.random().toString(36).substr(2, 9)}.txt`);
|
|
92
93
|
fs.writeFileSync(tempFile, fullPrompt, 'utf-8');
|
|
93
94
|
|
|
94
|
-
// Команда для Qwen
|
|
95
|
-
const command =
|
|
95
|
+
// Команда для Qwen — без системного промпта если есть контекст
|
|
96
|
+
const command = contextMessages.length > 0
|
|
97
|
+
? `cat '${tempFile}' | qwen -o json`
|
|
98
|
+
: `cat '${tempFile}' | qwen -p "Проанализируй код и дай рекомендации" -o json`;
|
|
96
99
|
|
|
97
100
|
logger.debug({ codeLength: code.length, contextLength: contextMessages.length, tempFile }, 'Running Qwen analysis');
|
|
98
101
|
|