Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: jumps over deleted messages in history when calling api #350

Merged
merged 4 commits into from
Oct 20, 2023
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 26 additions & 15 deletions service/src/chatgpt/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { SocksProxyAgent } from 'socks-proxy-agent'
import httpsProxyAgent from 'https-proxy-agent'
import fetch from 'node-fetch'
import type { AuditConfig, CHATMODEL, KeyConfig, UserInfo } from 'src/storage/model'
import { Status } from "src/storage/model";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


import { Status } from '../storage/model'

麻烦改为这样呢,一个是都单引号,统一一下,否则校验感觉过不去, 另一个 我跑你这样会报错,../ 就不会
image
image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

哦好。ide自动加的我也就没管了

import jwt_decode from 'jwt-decode'
import dayjs from 'dayjs'
import type { TextAuditService } from '../utils/textAudit'
Expand Down Expand Up @@ -346,22 +347,32 @@ async function getMessageById(id: string): Promise<ChatMessage | undefined> {
const chatInfo = await getChatByMessageId(isPrompt ? id.substring(7) : id)

if (chatInfo) {
if (isPrompt) { // prompt
return {
id,
conversationId: chatInfo.options.conversationId,
parentMessageId: chatInfo.options.parentMessageId,
role: 'user',
text: chatInfo.prompt,
const parentMessageId = isPrompt
? chatInfo.options.parentMessageId
: `prompt_${id}` // parent message is the prompt

if (chatInfo.status !== Status.Normal) { // jumps over deleted messages
return parentMessageId
? getMessageById(parentMessageId)
: undefined
} else {
if (isPrompt) { // prompt
return {
id,
conversationId: chatInfo.options.conversationId,
parentMessageId: parentMessageId,
role: 'user',
text: chatInfo.prompt,
}
}
}
else {
return { // completion
id,
conversationId: chatInfo.options.conversationId,
parentMessageId: `prompt_${id}`, // parent message is the prompt
role: 'assistant',
text: chatInfo.response,
else {
return { // completion
id,
conversationId: chatInfo.options.conversationId,
parentMessageId: parentMessageId,
role: 'assistant',
text: chatInfo.response,
}
}
}
}
Expand Down