chore(context): refactor for consistency, optimize formatting, and simplify logic
- Cleaned up unnecessary comments in `__all__` definitions for better readability. - Adjusted indentation and formatting across modules for improved clarity (e.g., long lines, logical grouping). - Simplified conditional expressions and inline comments for context scoring and ranking. - Replaced some hard-coded values with type-safe annotations (e.g., `ClassVar`). - Removed unused imports and ensured consistent usage across test files. - Updated `test_score_not_cached_on_context` to clarify caching behavior. - Improved truncation strategy logic and marker handling.
This commit is contained in:
@@ -5,10 +5,9 @@ from datetime import UTC, datetime
|
||||
import pytest
|
||||
|
||||
from app.services.context.assembly import ContextPipeline, PipelineMetrics
|
||||
from app.services.context.budget import BudgetAllocator, TokenBudget
|
||||
from app.services.context.budget import TokenBudget
|
||||
from app.services.context.types import (
|
||||
AssembledContext,
|
||||
ContextType,
|
||||
ConversationContext,
|
||||
KnowledgeContext,
|
||||
MessageRole,
|
||||
@@ -354,7 +353,10 @@ class TestContextPipelineFormatting:
|
||||
|
||||
if result.context_count > 0:
|
||||
assert "<conversation_history>" in result.content
|
||||
assert '<message role="user">' in result.content or 'role="user"' in result.content
|
||||
assert (
|
||||
'<message role="user">' in result.content
|
||||
or 'role="user"' in result.content
|
||||
)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_format_tool_results(self) -> None:
|
||||
@@ -474,6 +476,10 @@ class TestContextPipelineIntegration:
|
||||
assert system_pos < task_pos
|
||||
if task_pos >= 0 and knowledge_pos >= 0:
|
||||
assert task_pos < knowledge_pos
|
||||
if knowledge_pos >= 0 and conversation_pos >= 0:
|
||||
assert knowledge_pos < conversation_pos
|
||||
if conversation_pos >= 0 and tool_pos >= 0:
|
||||
assert conversation_pos < tool_pos
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_excluded_contexts_tracked(self) -> None:
|
||||
|
||||
Reference in New Issue
Block a user