[Developer] #215 AI frame-suggest vertical slice (mock LlmService)
설계서대로 구현. flutter_gemma 실제 통합은 OQ-1 (모델 URL+SHA) 확정 후.
v1은 LlmService 추상 + ModelLifecycle (다운로드/SHA/purge) + Riverpod
providers + 다이얼로그 + Settings 화면까지. main.dart 가 MockLlmService 를
override 해 모든 경로가 graceful (suggest 결과는 빈 리스트).
추가:
- lib/data/ai/{llm_service,gemma_llm_service,model_lifecycle}.dart
- lib/domain/ai/{frame_candidate,few_shot_builder,parse_response,suggest_frame}.dart
- lib/state/ai_providers.dart (aiSettings + modelAvailability + frameSuggestions)
- lib/ui/screens/settings_screen.dart (opt-in 토글 + 모델 상태 표시)
- lib/ui/widgets/frame_suggestion_dialog.dart (후보 3개 카드 + 다시 시도)
- HabitCreateScreen: "AI 제안" 버튼 (opt-in + ready 일 때만 노출)
- MetaDao.remove(key) 추가 (purge 용)
테스트 31개 신규 추가 (총 62개 통과):
- test/domain/ai/{suggest_frame, few_shot_builder, parse_response}_test.dart
- test/data/ai/model_lifecycle_test.dart (download/SHA/purge/availability)
flutter analyze 0 issue, flutter build apk --debug 통과.
Refs #215
This commit is contained in:
102
app/lib/ui/widgets/frame_suggestion_dialog.dart
Normal file
102
app/lib/ui/widgets/frame_suggestion_dialog.dart
Normal file
@@ -0,0 +1,102 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../domain/ai/frame_candidate.dart';
|
||||
import '../../domain/models/habit.dart';
|
||||
import '../../state/ai_providers.dart';
|
||||
|
||||
/// Shows L2/L3 suggestion cards from suggestFrame. Returns the selected
|
||||
/// framed_text via `Navigator.pop(context, candidate.framedText)`.
|
||||
class FrameSuggestionDialog extends ConsumerWidget {
|
||||
final SuggestFrameInput input;
|
||||
const FrameSuggestionDialog({super.key, required this.input});
|
||||
|
||||
static Future<String?> show(
|
||||
BuildContext context, {
|
||||
required SuggestFrameInput input,
|
||||
}) {
|
||||
return showDialog<String>(
|
||||
context: context,
|
||||
builder: (_) => FrameSuggestionDialog(input: input),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final async = ref.watch(frameSuggestionsProvider(input));
|
||||
return AlertDialog(
|
||||
title: const Text('AI 제안'),
|
||||
content: SizedBox(
|
||||
width: 320,
|
||||
child: async.when(
|
||||
loading: () => const SizedBox(
|
||||
height: 120,
|
||||
child: Center(child: CircularProgressIndicator()),
|
||||
),
|
||||
error: (e, _) => Padding(
|
||||
padding: const EdgeInsets.all(8),
|
||||
child: Text('AI 제안을 받지 못했습니다. 직접 입력해주세요.\n($e)'),
|
||||
),
|
||||
data: (candidates) {
|
||||
if (candidates.isEmpty) {
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
const Padding(
|
||||
padding: EdgeInsets.all(8),
|
||||
child: Text(
|
||||
'더 구체적으로 입력해주시면 더 좋은 제안을 드릴 수 있어요.',
|
||||
),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
ref.invalidate(frameSuggestionsProvider(input));
|
||||
},
|
||||
child: const Text('다시 시도'),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
for (final c in candidates)
|
||||
_CandidateCard(
|
||||
candidate: c,
|
||||
onTap: () => Navigator.of(context).pop(c.framedText),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: const Text('취소'),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _CandidateCard extends StatelessWidget {
|
||||
final FrameCandidate candidate;
|
||||
final VoidCallback onTap;
|
||||
const _CandidateCard({required this.candidate, required this.onTap});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Card(
|
||||
child: ListTile(
|
||||
title: Text(candidate.framedText),
|
||||
subtitle: Text(
|
||||
'${candidate.level == FrameLevel.l3 ? "L3 · 정체성" : "L2 · 조건부 긍정"} '
|
||||
'· 신뢰도 ${(candidate.confidence * 100).toInt()}%',
|
||||
),
|
||||
onTap: onTap,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user