Skip to content

feat: optimize Foundation Models backend for on-device model#63

Merged
chigichan24 merged 2 commits into
mainfrom
improve-usage-of-foundationmodel
Apr 6, 2026
Merged

feat: optimize Foundation Models backend for on-device model#63
chigichan24 merged 2 commits into
mainfrom
improve-usage-of-foundationmodel

Conversation

@chigichan24
Copy link
Copy Markdown
Owner

Summary

  • Foundation Models (Apple Intelligence) バックエンドの応答品質を改善
  • GenerationOptions(temperature: 0.5) で出力の一貫性を向上
  • 4,096トークン制限に対応するチャット履歴のtruncation(最大4件/各300文字)
  • オンデバイス3Bモデルが英語で返答する問題を解決するため、日本語システムプロンプトを導入
    • InstructionLanguage enum + SystemPromptProvider で型安全にEN/JAプロンプトを管理
    • PasteContext.buildSystemPromptlanguage: パラメータ追加
    • LLMBackend.current のTOCTOU問題を修正(1回キャプチャ)
  • CLI バックエンドを isDevelopmentMode フラグで設定画面から非表示化

Test plan

  • 119テスト全通過
  • SwiftLint --strict 違反ゼロ
  • Foundation Models バックエンドで inline suggestion が日本語で返ることを確認
  • Foundation Models バックエンドで chat が日本語で返ることを確認
  • CLI バックエンド非表示を確認(isDevelopmentMode = false

🤖 Generated with Claude Code

chigichan24 and others added 2 commits April 7, 2026 03:30
- Add GenerationOptions with temperature 0.5 for consistent output
- Limit chat history to 4 messages / 300 chars to fit 4,096-token window
- Add tests for history truncation

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The on-device 3B model strongly follows instruction language, causing
English responses even for Japanese input. Introduce InstructionLanguage
enum and SystemPromptProvider to select Japanese system prompts for
Foundation Models while keeping English for cloud backends.

- Add InstructionLanguage enum and LLMBackend.instructionLanguage
- Add SystemPromptProvider with LocalizedPrompt (enforces EN/JA pairs)
- Add language parameter to PasteContext.buildSystemPrompt
- Fix TOCTOU: capture LLMBackend.current once per request
- Extract validateChatMessage to fix function_body_length violation

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@chigichan24 chigichan24 merged commit c552180 into main Apr 6, 2026
2 checks passed
@chigichan24 chigichan24 deleted the improve-usage-of-foundationmodel branch April 6, 2026 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant