-
Notifications
You must be signed in to change notification settings - Fork 1
Gemma 4 Local LLM, Create Alarms And Timer from ZSWatch #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d2f354f
feat: filesystem browser, watchface backgrounds, SMP connection guard
jakkra 6e7abea
ai: add LiteRT-LM runtime for Gemma 4 E2B on-device inference
jakkra 9d42f9a
ai: add 'queued' processing status for batch AI pipeline
jakkra 3f0bb03
chore: drop generated desktop plugin registrants from PR
jakkra 99c99dd
firmware_manager: fix CI build branch visibility and add zswatch@1 board
jakkra 603eb87
Add chat, TTS, AI model settings, watchface background improvements
jakkra 0a599fe
Improve background recovery and app stability
jakkra 16f2ee3
Formatted files.
jakkra a438d79
Review comments.
jakkra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -251,7 +251,9 @@ void main(List<String> args) async { | |
|
|
||
| for (var i = 0; i < testCases.length; i++) { | ||
| final tc = testCases[i]; | ||
| print('─── Test ${i + 1}/${testCases.length}: ${tc.name} ───────────────────────'); | ||
| print( | ||
| '─── Test ${i + 1}/${testCases.length}: ${tc.name} ───────────────────────', | ||
| ); | ||
| print(' Input: "${tc.transcript}"'); | ||
|
|
||
| // Build prompt | ||
|
|
@@ -283,13 +285,15 @@ void main(List<String> args) async { | |
| } | ||
| } catch (e) { | ||
| stderr.writeln(' ERROR during generation: $e'); | ||
| results.add(TestResult( | ||
| testCase: tc, | ||
| llmDuration: genSw.elapsed, | ||
| tokenCount: tokenCount, | ||
| status: TestStatus.fail, | ||
| failures: ['LLM generation error: $e'], | ||
| )); | ||
| results.add( | ||
| TestResult( | ||
| testCase: tc, | ||
| llmDuration: genSw.elapsed, | ||
| tokenCount: tokenCount, | ||
| status: TestStatus.fail, | ||
| failures: ['LLM generation error: $e'], | ||
| ), | ||
| ); | ||
| print(''); | ||
| continue; | ||
| } | ||
|
|
@@ -300,10 +304,14 @@ void main(List<String> args) async { | |
| // Strip end-of-turn tokens | ||
| raw = raw.replaceAll('<|im_end|>', '').trim(); | ||
| // Strip thinking blocks (Qwen3 models may use these) | ||
| raw = raw.replaceAll(RegExp(r'<think>.*?</think>', dotAll: true), '').trim(); | ||
| raw = raw | ||
| .replaceAll(RegExp(r'<think>.*?</think>', dotAll: true), '') | ||
| .trim(); | ||
|
|
||
| final secs = genSw.elapsed.inMilliseconds / 1000; | ||
| print(' LLM time: ${secs.toStringAsFixed(2)}s (~${(tokenCount / secs).toStringAsFixed(1)} tok/s)'); | ||
| print( | ||
| ' LLM time: ${secs.toStringAsFixed(2)}s (~${(tokenCount / secs).toStringAsFixed(1)} tok/s)', | ||
| ); | ||
|
Comment on lines
+312
to
+314
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guard tok/s calculation against zero elapsed time. Line 313 can divide by zero when generation finishes within the same millisecond, producing Suggested fix- final secs = genSw.elapsed.inMilliseconds / 1000;
+ final secs = genSw.elapsed.inMilliseconds / 1000;
+ final tokPerSec = secs > 0 ? (tokenCount / secs) : 0.0;
print(
- ' LLM time: ${secs.toStringAsFixed(2)}s (~${(tokenCount / secs).toStringAsFixed(1)} tok/s)',
+ ' LLM time: ${secs.toStringAsFixed(2)}s (~${tokPerSec.toStringAsFixed(1)} tok/s)',
);🤖 Prompt for AI Agents |
||
|
|
||
| if (verbose) { | ||
| print(' Raw output:'); | ||
|
|
@@ -341,29 +349,31 @@ void main(List<String> args) async { | |
| if (!verbose) { | ||
| print(' Raw output: $raw'); | ||
| } | ||
| results.add(TestResult( | ||
| testCase: tc, | ||
| llmDuration: genSw.elapsed, | ||
| tokenCount: tokenCount, | ||
| status: TestStatus.fail, | ||
| failures: ['JSON parse failed: $e'], | ||
| )); | ||
| results.add( | ||
| TestResult( | ||
| testCase: tc, | ||
| llmDuration: genSw.elapsed, | ||
| tokenCount: tokenCount, | ||
| status: TestStatus.fail, | ||
| failures: ['JSON parse failed: $e'], | ||
| ), | ||
| ); | ||
| print(''); | ||
| continue; | ||
| } | ||
|
|
||
| // Resolve time expression with chrono | ||
| ResolvedTime? resolvedTime; | ||
| // Try English translation first, fall back to original expression | ||
| final timeExpr = llmResult.datetimeExpressionEnglish ?? | ||
| final timeExpr = | ||
| llmResult.datetimeExpressionEnglish ?? | ||
| llmResult.datetimeExpressionOriginal; | ||
| if (timeExpr != null) { | ||
| resolvedTime = resolver.resolve( | ||
| timeExpr, | ||
| referenceDate: referenceTime, | ||
| ); | ||
| resolvedTime = resolver.resolve(timeExpr, referenceDate: referenceTime); | ||
| if (resolvedTime != null) { | ||
| print(' Chrono parse: ${resolvedTime.dateTime} (via ${resolvedTime.method})'); | ||
| print( | ||
| ' Chrono parse: ${resolvedTime.dateTime} (via ${resolvedTime.method})', | ||
| ); | ||
| } else { | ||
| print(' Chrono parse: FAILED — could not resolve "$timeExpr"'); | ||
| } | ||
|
|
@@ -378,7 +388,8 @@ void main(List<String> args) async { | |
| final intentMatch = _intentMatches(llmResult.intent, tc.expectedIntent); | ||
| if (!intentMatch) { | ||
| failures.add( | ||
| 'Intent mismatch: got "${llmResult.intent}", expected "${tc.expectedIntent}"'); | ||
| 'Intent mismatch: got "${llmResult.intent}", expected "${tc.expectedIntent}"', | ||
| ); | ||
| } | ||
|
|
||
| // Check 2: Time expression present/absent | ||
|
|
@@ -389,7 +400,8 @@ void main(List<String> args) async { | |
| if (tc.expectedTimeEnglish == null && | ||
| llmResult.datetimeExpressionEnglish != null) { | ||
| failures.add( | ||
| 'Expected no time expression but got "${llmResult.datetimeExpressionEnglish}"'); | ||
| 'Expected no time expression but got "${llmResult.datetimeExpressionEnglish}"', | ||
| ); | ||
| } | ||
|
|
||
| // Check 3: Chrono parse succeeded when expected | ||
|
|
@@ -398,24 +410,28 @@ void main(List<String> args) async { | |
| } | ||
| if (tc.expectedDateTime == null && resolvedTime != null) { | ||
| failures.add( | ||
| 'Expected no resolved time but got ${resolvedTime.dateTime}'); | ||
| 'Expected no resolved time but got ${resolvedTime.dateTime}', | ||
| ); | ||
| } | ||
|
|
||
| // Check 4: DateTime accuracy | ||
| if (tc.expectedDateTime != null && resolvedTime != null) { | ||
| final diff = | ||
| resolvedTime.dateTime.difference(tc.expectedDateTime!).inMinutes.abs(); | ||
| final diff = resolvedTime.dateTime | ||
| .difference(tc.expectedDateTime!) | ||
| .inMinutes | ||
| .abs(); | ||
| if (diff > tc.toleranceMinutes) { | ||
| failures.add( | ||
| 'DateTime mismatch: got ${resolvedTime.dateTime}, expected ${tc.expectedDateTime} (diff: ${diff}min, tolerance: ${tc.toleranceMinutes}min)'); | ||
| 'DateTime mismatch: got ${resolvedTime.dateTime}, expected ${tc.expectedDateTime} (diff: ${diff}min, tolerance: ${tc.toleranceMinutes}min)', | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| final status = failures.isEmpty | ||
| ? TestStatus.pass | ||
| : (failures.length == 1 && !failures.first.contains('Intent')) | ||
| ? TestStatus.partial | ||
| : TestStatus.fail; | ||
| ? TestStatus.partial | ||
| : TestStatus.fail; | ||
|
|
||
| if (failures.isEmpty) { | ||
| print(' ✅ PASS'); | ||
|
|
@@ -429,15 +445,17 @@ void main(List<String> args) async { | |
| print(' Expected: ${tc.expectedDateTime}'); | ||
| } | ||
|
|
||
| results.add(TestResult( | ||
| testCase: tc, | ||
| llmResult: llmResult, | ||
| resolvedTime: resolvedTime, | ||
| llmDuration: genSw.elapsed, | ||
| tokenCount: tokenCount, | ||
| status: status, | ||
| failures: failures, | ||
| )); | ||
| results.add( | ||
| TestResult( | ||
| testCase: tc, | ||
| llmResult: llmResult, | ||
| resolvedTime: resolvedTime, | ||
| llmDuration: genSw.elapsed, | ||
| tokenCount: tokenCount, | ||
| status: status, | ||
| failures: failures, | ||
| ), | ||
| ); | ||
|
|
||
| print(''); | ||
| } | ||
|
|
@@ -449,12 +467,18 @@ void main(List<String> args) async { | |
| final partial = results.where((r) => r.status == TestStatus.partial).length; | ||
| final failed = results.where((r) => r.status == TestStatus.fail).length; | ||
| final totalLlmTime = results.fold<Duration>( | ||
| Duration.zero, (sum, r) => sum + r.llmDuration); | ||
| Duration.zero, | ||
| (sum, r) => sum + r.llmDuration, | ||
| ); | ||
|
|
||
| print('╔══════════════════════════════════════════════════════════╗'); | ||
| print('║ Results: $passed passed, $partial partial, $failed failed ' | ||
| 'out of ${testCases.length} tests'); | ||
| print('║ Total LLM time: ${(totalLlmTime.inMilliseconds / 1000).toStringAsFixed(1)}s'); | ||
| print( | ||
| '║ Results: $passed passed, $partial partial, $failed failed ' | ||
| 'out of ${testCases.length} tests', | ||
| ); | ||
| print( | ||
| '║ Total LLM time: ${(totalLlmTime.inMilliseconds / 1000).toStringAsFixed(1)}s', | ||
| ); | ||
| print('║ Model: $modelFile'); | ||
| print('╚══════════════════════════════════════════════════════════╝'); | ||
|
|
||
|
|
@@ -463,7 +487,8 @@ void main(List<String> args) async { | |
| print(''); | ||
| print('Failed/partial tests:'); | ||
| for (final r in results.where( | ||
| (r) => r.status == TestStatus.fail || r.status == TestStatus.partial)) { | ||
| (r) => r.status == TestStatus.fail || r.status == TestStatus.partial, | ||
| )) { | ||
| print(' ${r.testCase.name}:'); | ||
| for (final f in r.failures) { | ||
| print(' - $f'); | ||
|
|
||
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strip unclosed
<think>blocks too.Current cleanup only removes closed think blocks. Unclosed blocks can still poison JSON extraction.
Suggested fix
raw = raw .replaceAll(RegExp(r'<think>.*?</think>', dotAll: true), '') + .replaceAll(RegExp(r'<think>.*', dotAll: true), '') .trim();📝 Committable suggestion
🤖 Prompt for AI Agents