Skip to content

Instantly share code, notes, and snippets.

@taktran
Last active April 18, 2024 19:08
Show Gist options
  • Save taktran/07f2ea88d350c854e61340f1495ef42c to your computer and use it in GitHub Desktop.
Save taktran/07f2ea88d350c854e61340f1495ef42c to your computer and use it in GitHub Desktop.
Extract Chat GPT Logs

Extract Chat GPT Logs

Made this to help me extract Chat GPT logs, for future reference.

Chat GPT did help in helping me write this :)

To use

  • Go to Chat GPT
  • Type some questions
  • Open dev tools, and paste whatever you need from extract-gpt-chat-logs.js into the dev tools console
// Get the avatar elements, so we can find the content,
// which is the next sibling
avatarClassSelector = '[class*="items-end"]'; // NOTE: This can easily break in the future
elements = document.querySelectorAll(avatarClassSelector);
isQuestion = (index) => index % 2 === 0;
// All the data
questionsAndAnswers = Array.from(elements)
.map((element, index) => {
const contentEl = element.nextElementSibling;
const item = {
contentHtml: contentEl.innerHTML,
text: contentEl.textContent,
};
if (isQuestion(index)) {
return { question: item };
} else {
return { answer: item };
}
})
.reduce((accumulator, currentValue) => {
if (currentValue.hasOwnProperty("question")) {
accumulator.push(currentValue);
} else {
const lastObject = accumulator[accumulator.length - 1];
const mergedObject = Object.assign(lastObject, currentValue);
accumulator[accumulator.length - 1] = mergedObject;
}
return accumulator;
}, []);
// Simplified data
questionsAndAnswersText = questionsAndAnswers.map(({ question, answer }) => {
return {
question: question.text,
answer: answer.text,
}
});
// Show text in the console in groups
questionsAndAnswersText.forEach(({ question, answer }) => {
console.groupCollapsed(question);
console.log(answer);
console.groupEnd();
});
// Show text in the console as a table
console.table(questionsAndAnswersText);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment