Skip to content

Commit

Permalink
Replace SystemMessage by AIMessage, and add the AIMessage to the history
Browse files Browse the repository at this point in the history
  • Loading branch information
brichet committed Oct 25, 2024
1 parent 2642e3f commit a7b0ca1
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions src/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import {
import { UUID } from '@lumino/coreutils';
import type { ChatMistralAI } from '@langchain/mistralai';
import {
AIMessage,
HumanMessage,
mergeMessageRuns,
SystemMessage
mergeMessageRuns
} from '@langchain/core/messages';

export type ConnectionMessage = {
Expand All @@ -39,21 +39,13 @@ export class CodestralHandler extends ChatModel {
};
this.messageAdded(msg);
this._history.messages.push(msg);
// const response = await this._mistralClient.chat({
// model: 'codestral-latest',
// messages: this._history.messages.map(msg => {
// return {
// role: msg.sender === 'User' ? 'user' : 'assistant',
// content: msg.body
// };
// })
// });

const messages = mergeMessageRuns(
this._history.messages.map(msg => {
if (msg.sender.username === 'User') {
return new HumanMessage(msg.body);
}
return new SystemMessage(msg.body);
return new AIMessage(msg.body);
})
);
const response = await this._mistralClient.invoke(messages);
Expand All @@ -67,6 +59,7 @@ export class CodestralHandler extends ChatModel {
type: 'msg'
};
this.messageAdded(botMsg);
this._history.messages.push(botMsg);
return true;
}

Expand Down

0 comments on commit a7b0ca1

Please sign in to comment.