Skip to content

Commit a7b0ca1

Browse files
committed
Replace SystemMessage by AIMessage, and add the AIMessage to the history
1 parent 2642e3f commit a7b0ca1

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

src/handler.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import {
1212
import { UUID } from '@lumino/coreutils';
1313
import type { ChatMistralAI } from '@langchain/mistralai';
1414
import {
15+
AIMessage,
1516
HumanMessage,
16-
mergeMessageRuns,
17-
SystemMessage
17+
mergeMessageRuns
1818
} from '@langchain/core/messages';
1919

2020
export type ConnectionMessage = {
@@ -39,21 +39,13 @@ export class CodestralHandler extends ChatModel {
3939
};
4040
this.messageAdded(msg);
4141
this._history.messages.push(msg);
42-
// const response = await this._mistralClient.chat({
43-
// model: 'codestral-latest',
44-
// messages: this._history.messages.map(msg => {
45-
// return {
46-
// role: msg.sender === 'User' ? 'user' : 'assistant',
47-
// content: msg.body
48-
// };
49-
// })
50-
// });
42+
5143
const messages = mergeMessageRuns(
5244
this._history.messages.map(msg => {
5345
if (msg.sender.username === 'User') {
5446
return new HumanMessage(msg.body);
5547
}
56-
return new SystemMessage(msg.body);
48+
return new AIMessage(msg.body);
5749
})
5850
);
5951
const response = await this._mistralClient.invoke(messages);
@@ -67,6 +59,7 @@ export class CodestralHandler extends ChatModel {
6759
type: 'msg'
6860
};
6961
this.messageAdded(botMsg);
62+
this._history.messages.push(botMsg);
7063
return true;
7164
}
7265

0 commit comments

Comments
 (0)