Skip to content

Commit

Permalink
fix: some chats cannot be exported because of missing message parts
Browse files Browse the repository at this point in the history
  • Loading branch information
pionxzh committed Apr 20, 2023
1 parent d18bf3f commit 2e7ece8
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/userscript/src/exporter/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function conversationToHtml(conversation: ConversationResult, avatar: string, me
const avatarEl = author === 'ChatGPT'
? '<svg width="41" height="41"><use xlink:href="#chatgpt" /></svg>'
: `<img alt="${author}" />`
const content = item.message?.content.parts.join('\n') ?? ''
const content = item.message?.content.parts?.join('\n') ?? ''
let conversationContent = content

if (author === 'ChatGPT') {
Expand Down
2 changes: 1 addition & 1 deletion packages/userscript/src/exporter/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function conversationToMarkdown(conversation: ConversationResult, metaList?: Exp

const content = conversationNodes.map((item) => {
const author = item.message?.author.role === 'assistant' ? 'ChatGPT' : 'You'
const content = item.message?.content.parts.join('\n') ?? ''
const content = item.message?.content.parts?.join('\n') ?? ''
let message = content

// User's message will not be reformatted
Expand Down
4 changes: 2 additions & 2 deletions packages/userscript/src/exporter/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export async function exportToText() {
const { conversationNodes } = processConversation(rawConversation, conversationChoices)
const text = conversationNodes.map((item) => {
const author = item.message?.author.role === 'assistant' ? 'ChatGPT' : 'You'
const content = item.message?.content.parts.join('\n') ?? ''
const content = item.message?.content.parts?.join('\n') ?? ''
let message = content

// User's message will not be reformatted
Expand Down Expand Up @@ -53,7 +53,7 @@ export async function exportToTextFromIndex(index: number) {
const conversationChoices = getConversationChoice()
const { conversationNodes } = processConversation(rawConversation, conversationChoices)

const text = conversationNodes[index].message?.content.parts.join('\n') ?? ''
const text = conversationNodes[index].message?.content.parts?.join('\n') ?? ''

copyToClipboard(standardizeLineBreaks(text))
return true
Expand Down

0 comments on commit 2e7ece8

Please sign in to comment.