@@ -12,31 +12,41 @@ import 'ai_client.dart';
1212import 'ai_client_transport.dart' ;
1313import 'message.dart' ;
1414
15- /// A class that manages the chat session state and logic.
16- class ChatSession extends ChangeNotifier {
17- ChatSession ({required AiClient aiClient}) {
18- // 1. Create Transport
19- _transport = AiClientTransport (aiClient: aiClient);
20-
21- // 2. Initialize Catalog & Controller
22- final Catalog catalog = BasicCatalogItems .asCatalog (
23- systemPromptFragments: [
24- '''
15+ final Catalog _catalog = BasicCatalogItems .asCatalog (
16+ systemPromptFragments: [
17+ '''
2518When you need additional information from the user, try to use the component '${BasicCatalogItems .choicePicker .name }' to ask for it.
2619''' ,
27- '''
20+ '''
2821If there is no way to itemize all the options, either use the component '${BasicCatalogItems .textField .name }' or add option 'Other' to the '${BasicCatalogItems .choicePicker .name }'.
2922''' ,
30- ],
31- );
32- _surfaceController = SurfaceController (catalogs: [catalog]);
23+ ],
24+ );
25+
26+ final PromptBuilder _promptBuilder = PromptBuilder .chat (
27+ catalog: _catalog,
28+ systemPromptFragments: [
29+ 'You are a helpful assistant who chats with a user.' ,
30+ PromptFragments .acknowledgeUser (),
31+ PromptFragments .requireAtLeastOneSubmitElement (
32+ prefix: PromptBuilder .defaultImportancePrefix,
33+ ),
34+ PromptFragments .uiGenerationRestriction (
35+ prefix: PromptBuilder .defaultImportancePrefix,
36+ ),
37+ ],
38+ );
3339
34- // 3. Initialize Conversation
40+ /// A class that manages the chat session state and logic.
41+ class ChatSession extends ChangeNotifier {
42+ ChatSession ({required AiClient aiClient}) {
43+ _transport = AiClientTransport (aiClient: aiClient);
44+ _surfaceController = SurfaceController (catalogs: [_catalog]);
3545 _conversation = Conversation (
3646 controller: _surfaceController,
3747 transport: _transport,
3848 );
39- _init (catalog );
49+ _init (_catalog );
4050 }
4151
4252 late final AiClientTransport _transport;
@@ -75,20 +85,7 @@ If there is no way to itemize all the options, either use the component '${Basic
7585 }
7686 });
7787
78- final promptBuilder = PromptBuilder .chat (
79- catalog: catalog,
80- systemPromptFragments: [
81- 'You are a helpful assistant who chats with a user.' ,
82- PromptFragments .acknowledgeUser (),
83- PromptFragments .requireAtLeastOneSubmitElement (
84- prefix: PromptBuilder .defaultImportancePrefix,
85- ),
86- PromptFragments .uiGenerationRestriction (
87- prefix: PromptBuilder .defaultImportancePrefix,
88- ),
89- ],
90- );
91- _transport.addSystemMessage (promptBuilder.systemPromptJoined ());
88+ _transport.addSystemMessage (_promptBuilder.systemPromptJoined ());
9289 }
9390
9491 void _addSurfaceMessage (String surfaceId) {
0 commit comments