fix(document_loaders): ChatGPTLoader misses last message with default num_logs#513
Open
leoneperdigao wants to merge 2 commits intolangchain-ai:mainfrom
Conversation
Fixes langchain-ai#465 The bug was that `num_logs` defaulted to `-1`, which caused `data[:-1]` slicing (excluding the last conversation) because `-1` is truthy in Python. Changes: - Changed default `num_logs` from `-1` to `0` (load all) - Made slicing logic explicit: only slice when `num_logs > 0` - Updated docstring to clarify the default behavior - Added comprehensive unit tests for ChatGPTLoader The fix ensures that: - `ChatGPTLoader(file)` loads ALL conversations (default) - `ChatGPTLoader(file, num_logs=0)` loads ALL conversations - `ChatGPTLoader(file, num_logs=N)` loads first N conversations
libs/community/tests/unit_tests/document_loaders/test_chatgpt.py
Outdated
Show resolved
Hide resolved
Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Related Issue
Fixes #465
Issue: Bug: ChatGPTLoader misses the last message when loading default logs
URL: #465
Problem
Checked other resources
Example Code
'''python
class ChatGPTLoader(BaseLoader):
"""Load conversations from exported
ChatGPTdata."""'''
Error Message and Stack Trace (if applicable)
No response
Description
Description
I found a bug in
ChatGPTLoader. The defaultnum_logsin__init__is set to-1.In the
loadmethod, the slicing[: self.num_logs]is executed whennum_logsis not 0.Since
-1evaluates to True, it performsdata[:-1], which excludes the last record of the conversation.Reproduction Steps
ChatGPTLoader(file_path).Proposed Fix
Change the default value of
num_logsto0(which means load all), or handle-1explicitly.I have prepared a fix and unit tests for this.
Solution
Tests
Checklist
Additional Notes