Release v2.0.0
🚀 Major Architecture Overhaul: Explicit History Management
This is a major version update with significant architectural changes. The core design philosophy has shifted from implicit to explicit history management, providing better control, predictability, and consistency.
Changed
Breaking Changes
-
Removed
auto_historyparameter: Theauto_historyparameter has been completely removed fromChat.__init__(). History management is now always explicit.- Migration: Create a
ChatHistoryinstance and pass it explicitly to all methods:# Before (v0.5.x) chat = Chat(..., auto_history=True) result = chat("Hello") history = chat.get_history() # After (v2.0.0) history = ChatHistory() result = chat("Hello", history=history)
- Migration: Create a
-
All Chat methods now require explicit
historyparameter: All methods that interact with history now accept an explicithistory: ChatHistory | Noneparameter.Chat.__call__(messages, *, history=None, **params)Chat.stream(messages, *, history=None, **params)Chat.complete(messages, *, history: ChatHistory, **params)(now required)Chat.continue_if_needed(result, *, history: ChatHistory, **params)(now required)ChatContinue.continue_request(chat, last_result, *, history: ChatHistory, **params)(now required)ChatContinue.continue_request_stream(chat, last_result, *, history: ChatHistory, **params)(now required)
-
Removed history management methods from
Chatclass:Chat.get_history()- Use explicithistoryparameter insteadChat.clear_history()- Usehistory.clear()insteadChat.clear_last_assistant_message()- Usehistory.remove_last()instead
-
Simplified
ChatResult:ChatResultnow only contains the result of a single LLM request, without any merged history information. This makes the API more predictable and easier to understand. -
Unified Chat interface: All Chat methods now only accept a single turn's message, with history being managed explicitly. This ensures consistent behavior between streaming and non-streaming modes.
Added
-
Enhanced
ChatHistorywithMutableSequenceprotocol:ChatHistorynow implements Python'scollections.abc.MutableSequenceprotocol, enabling array-like operations:- Indexing:
history[0]- Get message by index - Slicing:
history[1:5]- Get slice as newChatHistoryinstance - Iteration:
for msg in history- Iterate over messages - Length:
len(history)- Get number of messages - Membership:
msg in history- Check if message exists - Assignment:
history[0] = new_msg- Replace message at index - Deletion:
del history[0]- Remove message at index - Insertion:
history.insert(0, msg)- Insert message at index
- Indexing:
-
New
ChatHistorymethods:clone()- Create a deep copy of the history__add__(other)- Merge twoChatHistoryinstances:history1 + history2add_system(content)- Explicitly add or update system messageremove_last()- Remove the last messageremove_at(index)- Remove message at specific indexreplace_at(index, message)- Replace message at specific indexget_user_messages()- Get all user message contents as a listget_assistant_messages()- Get all assistant message contents as a listget_last_message()- Get the last message dictionaryget_last_user_message()- Get the content of the last user message
-
Streaming complete functionality:
Chat.complete_stream(messages, *, history: ChatHistory, ...)- Streaming version ofcomplete()that ensures complete responses with real-time chunk streaming- Supports progress callbacks (
on_progress,on_continue_start,on_continue_end) for monitoring continuation progress
-
Streaming continue functionality:
ChatContinue.continue_request_stream(chat, last_result, *, history: ChatHistory, ...)- Stream continuation chunks in real-time- Automatically merges results from all continuation requests
- Provides access to accumulated result via
iterator.result.to_chat_result()
-
Convenience methods:
Chat.chat_with_history(history, message=None, **params)- Convenience method for chat with historyChat.stream_with_history(history, message=None, **params)- Convenience method for streaming with history
Improved
- Explicit history management: All history operations are now explicit, making the API more predictable and easier to debug.
- Consistency: Streaming and non-streaming modes now have identical behavior regarding history management.
- Type safety: Better type hints and validation for history parameters.
- Error handling: More precise error messages when history is required but not provided.
- Documentation: Comprehensive documentation updates reflecting the new explicit history management approach.
Fixed
- Fixed
finish_reasonpropagation in streaming responses: Corrected issue wherefinish_reasoncould be incorrectly set toNonein streaming responses, especially during continuation requests. - Fixed history update timing: User messages are now added to history before the API request, ensuring they are recorded even if the request fails.
- Fixed empty result handling in continuation: Empty
ChatResultobjects are now properly filtered out during continuation merging. - Fixed docstring formatting: Resolved reStructuredText formatting issues in docstrings that caused documentation build warnings.
Removed
- Removed
auto_historyparameter fromChat.__init__() - Removed
Chat.get_history()method - Removed
Chat.clear_history()method - Removed
Chat.clear_last_assistant_message()method - Removed obsolete test files:
test_chat_auto_history.py,test_chat_new_features.py(replaced with v2.0 tests) - Removed obsolete documentation:
auto_history.rstand related examples
Documentation
- Comprehensive documentation updates: All documentation has been updated to reflect the new explicit history management approach
- Migration guide: Detailed examples showing how to migrate from v0.5.x to v2.0.0
- New examples: Updated all examples to use the new explicit history API
- API reference: Updated API reference documentation for all changed methods
Testing
- New comprehensive test suite: Created new test files for v2.0.0 API:
test_chat_v2.py- Tests forChatclient's v2.0.0 APItest_chat_history_v2.py- Tests forChatHistory'sMutableSequenceprotocol and new methodstest_chat_continue_v2.py- Tests forChatContinue's v2.0.0 APItest_chat_streaming_continue_v2.py- Tests for streaming continue edge casestest_chat_integration_v2.py- Integration tests for v2.0.0 API
- All tests passing: Comprehensive test coverage ensuring correctness of the new architecture
Installation
pip install lexiluxOr with tokenizer support:
pip install lexilux[tokenizer]