Commit b2c925c3 authored by nanahira's avatar nanahira

fix new conversation

parent 55738829
......@@ -28,6 +28,9 @@ export class ChatgptService extends ConsoleLogger {
previousConversation?.account,
failedAccounts,
);
const isNewConversation =
!previousConversation ||
account.getEmail() !== previousConversation.account;
if (!account) {
throw new BlankReturnMessageDto(
500,
......@@ -36,12 +39,12 @@ export class ChatgptService extends ConsoleLogger {
}
this.log(`Processing chat for ${session} with ${account.getEmail()}`);
const result = await account.sendMessage(question.text, {
...(previousConversation
? {
...(isNewConversation
? {}
: {
conversationId: previousConversation.conversationId,
parentMessageId: previousConversation.messageId,
}
: {}),
}),
timeoutMs: 300000,
});
if (!result) {
......@@ -57,6 +60,7 @@ export class ChatgptService extends ConsoleLogger {
);
const dto = new ConversationDto();
dto.session = session;
dto.isNewConversation = isNewConversation;
dto.text = result.response.replace(/^<!--(.*)-->$/gm, '');
return dto;
}
......
......@@ -9,6 +9,9 @@ export class ConversationBase {
export class ConversationDto extends ConversationBase {
@ApiProperty({ description: 'Message from ChatGPT.' })
text: string;
@ApiProperty({ description: 'Whether the conversation is newly created.' })
isNewConversation: boolean;
}
export class ConversationStorage extends ConversationBase {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment