-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_streaming_fix.lua
More file actions
140 lines (111 loc) · 4.35 KB
/
test_streaming_fix.lua
File metadata and controls
140 lines (111 loc) · 4.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
-- Test streaming and completion fixes
local M = {}
function M.test_prompt_improvements()
print("Testing prompt improvements...")
local prompts = require("localnest.prompts")
-- Test chat system prompt
if prompts.chat_system then
print("✓ Chat system prompt loaded")
if prompts.chat_system:find("concise but thorough") then
print("✓ Prompt encourages balanced responses")
end
end
-- Test explain template
local explain = string.format(prompts.explain_template, "python", "def test(): pass")
if explain:find("Explain this code concisely but completely") then
print("✓ Explain template encourages complete responses")
end
-- Test fix template
local fix = string.format(prompts.fix_template, "python", "def test(): pass", "test")
if fix:find("Analyze and fix this code") then
print("✓ Fix template has clear structure")
end
return true
end
function M.test_error_handling()
print("\nTesting error handling improvements...")
-- Test error sanitization
local test_error = "Bearer sk-1234567890abcdef curl error: connection failed"
local sanitized = test_error:gsub("Bearer%s+[%w%-_]+", "Bearer [REDACTED]")
if sanitized == "Bearer [REDACTED] curl error: connection failed" then
print("✓ Error sanitization working")
else
print("✗ Error sanitization failed")
return false
end
-- Test truncated response detection
local test_truncated = "This is a response that ends abruptly"
local test_complete = "This is a complete response. It ends properly."
local function check_truncation(text)
local last_sentence = text:match("[^.!?]+[.!?]%s*$")
local has_unclosed_code = text:match("```[^`]*$")
local has_unclosed_bracket = text:match("%[.*%]$") and not text:match("%]%s*$")
return not last_sentence or has_unclosed_code or has_unclosed_bracket
end
if check_truncation(test_truncated) then
print("✓ Truncation detection for incomplete sentences")
end
if not check_truncation(test_complete) then
print("✓ Complete sentences not flagged as truncated")
end
return true
end
function M.test_configuration()
print("\nTesting configuration updates...")
local config = require("localnest.config")
-- Check chat configuration
local chat_config = config.get("chat")
if chat_config then
print("✓ Chat configuration loaded")
if chat_config.system_prompt and chat_config.system_prompt:find("LocalNest") then
print("✓ Using updated system prompt")
end
local deepseek_chat = config.get("chat.deepseek_chat")
if deepseek_chat then
if deepseek_chat.frequency_penalty == 0.1 then
print("✓ Frequency penalty configured to reduce repetition")
end
if deepseek_chat.presence_penalty == 0.1 then
print("✓ Presence penalty configured for diversity")
end
end
end
return true
end
function M.run_all_tests()
print("=== Streaming and Completion Fix Tests ===\n")
local tests = {
{ name = "Prompt Improvements", func = M.test_prompt_improvements },
{ name = "Error Handling", func = M.test_error_handling },
{ name = "Configuration", func = M.test_configuration },
}
local passed = 0
local total = #tests
for _, test in ipairs(tests) do
local success, result = pcall(test.func)
if success and result then
print("✓ " .. test.name .. " PASSED\n")
passed = passed + 1
else
print("✗ " .. test.name .. " FAILED")
if not success then
print(" Error: " .. tostring(result))
end
print()
end
end
print("=== Test Results ===")
print("Passed: " .. passed .. "/" .. total)
if passed == total then
print("✓ All tests passed! Streaming fixes are ready.")
return true
else
print("✗ Some tests failed. Please check the implementation.")
return false
end
end
-- Run tests if this file is executed directly
if arg and arg[0] and arg[0]:match("test_streaming_fix.lua") then
M.run_all_tests()
end
return M