Skip to content

Commit 5a194d1

Browse files
committed
Step 7
1 parent 1da6b5f commit 5a194d1

File tree

4 files changed

+78
-1
lines changed

4 files changed

+78
-1
lines changed

colorist/codelab_rebuild.yaml

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,67 @@ steps:
881881
steps:
882882
- name: Remove generated code
883883
rmdir: step_07
884-
884+
- name: Patch lib/services/gemini_chat_service.dart
885+
path: colorist/lib/services/gemini_chat_service.dart
886+
patch-u: |
887+
--- b/colorist/step_07/lib/services/gemini_chat_service.dart
888+
+++ a/colorist/step_07/lib/services/gemini_chat_service.dart
889+
@@ -3,7 +3,9 @@
890+
// found in the LICENSE file.
891+
892+
import 'dart:async';
893+
+import 'dart:convert';
894+
895+
+import 'package:colorist_ui/models/color_data.dart';
896+
import 'package:colorist_ui/models/conversation_state.dart';
897+
import 'package:colorist_ui/providers/chat_state_notifier.dart';
898+
import 'package:colorist_ui/providers/log_state_notifier.dart';
899+
@@ -24,6 +26,10 @@ class GeminiChatService {
900+
GeminiChatService(this.ref);
901+
final Ref ref;
902+
903+
+ Future<void> notifyColorSelection(ColorData color) => sendMessage(
904+
+ 'User selected color from history: ${json.encode(color.toLLMContextMap())}',
905+
+ );
906+
+
907+
Future<void> sendMessage(String message) async {
908+
final chatSession = await ref.read(chatSessionProvider.future);
909+
final conversationState = ref.read(conversationStateProvider);
910+
- name: Patch lib/main.dart
911+
path: colorist/lib/main.dart
912+
patch-u: |
913+
--- b/colorist/step_07/lib/main.dart
914+
+++ a/colorist/step_07/lib/main.dart
915+
@@ -43,6 +43,9 @@ class MainApp extends ConsumerWidget {
916+
data:
917+
(data) => MainScreen(
918+
conversationState: conversationState,
919+
+ notifyColorSelection: (color) {
920+
+ ref.read(geminiChatServiceProvider).notifyColorSelection(color);
921+
+ },
922+
sendMessage: (text) {
923+
ref.read(geminiChatServiceProvider).sendMessage(text);
924+
},
925+
- name: Patch assets/prompts/system_prompt.md
926+
path: colorist/assets/prompts/system_prompt.md
927+
patch-u: |
928+
--- b/colorist/step_07/assets/prompts/system_prompt.md
929+
+++ a/colorist/step_07/assets/prompts/system_prompt.md
930+
@@ -29,6 +29,14 @@ After the tool call: "I've set a warm orange with strong red, moderate green, an
931+
932+
If a color description is ambiguous or unclear, please ask the user clarifying questions, one at a time.
933+
934+
+## When Users Select Historical Colors
935+
+
936+
+Sometimes, the user will manually select a color from the history panel. When this happens, you'll receive a notification about this selection that includes details about the color. Acknowledge this selection with a brief response that recognizes what they've done and comments on the selected color.
937+
+
938+
+Example notification:
939+
+User: "User selected color from history: {red: 0.2, green: 0.5, blue: 0.8, hexCode: #3380CC}"
940+
+You: "I see you've selected an ocean blue from your history. This tranquil blue with a moderate intensity has a calming, professional quality to it. Would you like to explore similar shades or create a contrasting color?"
941+
+
942+
## Important Guidelines
943+
944+
- Always keep RGB values between 0.0 and 1.0
885945
- name: Run build_runner
886946
path: colorist
887947
dart: run build_runner build --delete-conflicting-outputs

colorist/step_07/assets/prompts/system_prompt.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ After the tool call: "I've set a warm orange with strong red, moderate green, an
2929

3030
If a color description is ambiguous or unclear, please ask the user clarifying questions, one at a time.
3131

32+
## When Users Select Historical Colors
33+
34+
Sometimes, the user will manually select a color from the history panel. When this happens, you'll receive a notification about this selection that includes details about the color. Acknowledge this selection with a brief response that recognizes what they've done and comments on the selected color.
35+
36+
Example notification:
37+
User: "User selected color from history: {red: 0.2, green: 0.5, blue: 0.8, hexCode: #3380CC}"
38+
You: "I see you've selected an ocean blue from your history. This tranquil blue with a moderate intensity has a calming, professional quality to it. Would you like to explore similar shades or create a contrasting color?"
39+
3240
## Important Guidelines
3341

3442
- Always keep RGB values between 0.0 and 1.0

colorist/step_07/lib/main.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ class MainApp extends ConsumerWidget {
4343
data:
4444
(data) => MainScreen(
4545
conversationState: conversationState,
46+
notifyColorSelection: (color) {
47+
ref.read(geminiChatServiceProvider).notifyColorSelection(color);
48+
},
4649
sendMessage: (text) {
4750
ref.read(geminiChatServiceProvider).sendMessage(text);
4851
},

colorist/step_07/lib/services/gemini_chat_service.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
// found in the LICENSE file.
44

55
import 'dart:async';
6+
import 'dart:convert';
67

8+
import 'package:colorist_ui/models/color_data.dart';
79
import 'package:colorist_ui/models/conversation_state.dart';
810
import 'package:colorist_ui/providers/chat_state_notifier.dart';
911
import 'package:colorist_ui/providers/log_state_notifier.dart';
@@ -24,6 +26,10 @@ class GeminiChatService {
2426
GeminiChatService(this.ref);
2527
final Ref ref;
2628

29+
Future<void> notifyColorSelection(ColorData color) => sendMessage(
30+
'User selected color from history: ${json.encode(color.toLLMContextMap())}',
31+
);
32+
2733
Future<void> sendMessage(String message) async {
2834
final chatSession = await ref.read(chatSessionProvider.future);
2935
final conversationState = ref.read(conversationStateProvider);

0 commit comments

Comments
 (0)