INNER CODE UNIT · JavaScript

copyConversation

waylaidwanderer/node-chatgpt-api · bin/cli.js:268

async function copyConversation() {
    if (clientToUse !== 'chatgpt') {
        logWarning('Copying conversations is only supported for ChatGPT client.');
        return conversation();
    }
    if (!conversationData.conversationId) {
        logWarning('No conversation to copy.');
        return conversation();
    }
    const { messages } = await client.conversationsCache.get(conversationData.conversationId);
    // get the last message ID
    const lastMessageId = messages[messages.length - 1].id;
    const orderedMessages = ChatGPTClient.getMessagesForConversation(messages, lastMessageId);
    const conversationString = orderedMessages.map(message => `#### ${message.role}:\n${message.message}`).join('\n\n');
    try {
        await clipboard.write(`${conversationString}\n\n----\nMade with ChatGPT CLI: <https://github.com/waylaidwanderer/node-chatgpt-api>`);
        logSuccess('Copied conversation to clipboard.');
    } catch (error) {

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…