Skip to content

Commit 5470e94

Browse files
dpageclaude
andcommitted
Fix missing compaction module and SQL extraction test.
- Replace compaction module imports with inline history deserialization and filtering since compaction.py is on a different branch. - Add rstrip(';') to SQL extraction test to match production code, fixing double-semicolon assertion failure. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 4c69595 commit 5470e94

File tree

2 files changed

+31
-23
lines changed

2 files changed

+31
-23
lines changed

web/pgadmin/tools/sqleditor/__init__.py

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2886,10 +2886,7 @@ def nlq_chat_stream(trans_id):
28862886
def generate():
28872887
"""Generator for SSE events."""
28882888
import secrets as py_secrets
2889-
from pgadmin.llm.compaction import (
2890-
deserialize_history, compact_history
2891-
)
2892-
from pgadmin.llm.utils import get_default_provider
2889+
from pgadmin.llm.models import Message, Role
28932890

28942891
try:
28952892
# Send thinking status
@@ -2898,15 +2895,22 @@ def generate():
28982895
'message': gettext('Analyzing your request...')
28992896
})
29002897

2901-
# Deserialize and compact conversation history
2898+
# Deserialize conversation history if provided
29022899
conversation_history = None
29032900
if history_data:
2904-
conversation_history = deserialize_history(history_data)
2905-
provider = get_default_provider() or 'openai'
2906-
conversation_history = compact_history(
2907-
conversation_history,
2908-
provider=provider
2909-
)
2901+
conversation_history = []
2902+
for item in (history_data or []):
2903+
if not isinstance(item, dict):
2904+
continue
2905+
role_str = item.get('role', '')
2906+
content = item.get('content', '')
2907+
try:
2908+
role = Role(role_str)
2909+
except ValueError:
2910+
continue
2911+
conversation_history.append(
2912+
Message(role=role, content=content)
2913+
)
29102914

29112915
# Stream the LLM response with database tools
29122916
response_text = ''
@@ -2965,17 +2969,21 @@ def generate():
29652969
else:
29662970
new_conversation_id = conversation_id
29672971

2968-
# Filter and serialize the conversation history so the
2969-
# client can round-trip it on follow-up turns
2970-
from pgadmin.llm.compaction import filter_conversational
2971-
filtered = filter_conversational(updated_messages)
2972-
history = [
2973-
{
2974-
'role': m.role.value,
2975-
'content': m.content,
2976-
}
2977-
for m in filtered
2978-
]
2972+
# Serialize the conversation history so the client can
2973+
# round-trip it on follow-up turns. Only keep user
2974+
# messages and final assistant responses (no tool calls).
2975+
history = []
2976+
for m in updated_messages:
2977+
if m.role == Role.USER:
2978+
history.append({
2979+
'role': m.role.value,
2980+
'content': m.content,
2981+
})
2982+
elif m.role == Role.ASSISTANT and not m.tool_calls:
2983+
history.append({
2984+
'role': m.role.value,
2985+
'content': m.content,
2986+
})
29792987

29802988
# Send the final result with full response content
29812989
yield _nlq_sse_event({

web/pgadmin/tools/sqleditor/tests/test_nlq_chat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ def runTest(self):
283283
re.DOTALL | re.IGNORECASE
284284
)
285285
sql = ';\n\n'.join(
286-
block.strip() for block in sql_blocks
286+
block.strip().rstrip(';') for block in sql_blocks
287287
) if sql_blocks else None
288288

289289
# JSON fallback

0 commit comments

Comments
 (0)