Skip to content

Commit e194a8b

Browse files
committed
-
1 parent 79fcef9 commit e194a8b

4 files changed

Lines changed: 65 additions & 48 deletions

File tree

examples/eval/pubspec.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ dependencies:
1616
flutter:
1717
sdk: flutter
1818
genui: ^0.7.0
19+
simple_chat:
20+
path: ../simple_chat
1921

2022
dev_dependencies:
2123
flutter_test:

examples/eval/test/infra_test.dart

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2025 The Flutter Authors.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
// ignore_for_file: avoid_print
6+
7+
import 'package:flutter_test/flutter_test.dart';
8+
9+
import 'test_infra/ai_client.dart';
10+
import 'test_infra/api_key.dart';
11+
12+
void main() {
13+
test('test can read api key "$geminiApiKeyName"', () {
14+
final String key = apiKeyForEval();
15+
expect(key, isNotEmpty);
16+
print('API Key: ${key.substring(0, 1)}...${key.substring(key.length - 1)}');
17+
});
18+
19+
test('test can talk with AI', () async {
20+
final aiClient = DartanticAiClient();
21+
addTearDown(aiClient.dispose);
22+
23+
final String result =
24+
(await aiClient
25+
.sendStream('Please, tell me a joke.', history: [])
26+
.toList())
27+
.join(' ');
28+
expect(result, isNotEmpty);
29+
print('Result: $result');
30+
});
31+
}

examples/eval/test/smoke_test.dart

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,12 @@
55
// ignore_for_file: avoid_print
66

77
import 'package:flutter_test/flutter_test.dart';
8-
9-
import 'test_infra/ai_client.dart';
10-
import 'test_infra/api_key.dart';
8+
import 'package:genui/genui.dart';
9+
import 'package:simple_chat/chat_session.dart';
1110

1211
void main() {
13-
test('test can read api key "$geminiApiKeyName"', () {
14-
final String key = apiKeyForEval();
15-
expect(key, isNotEmpty);
16-
print('API Key: ${key.substring(0, 1)}...${key.substring(key.length - 1)}');
17-
});
18-
19-
test('test can talk with AI', () async {
20-
final aiClient = DartanticAiClient();
21-
addTearDown(aiClient.dispose);
22-
23-
final String result = await aiClient
24-
.sendStream('Please, tell me a joke.', history: [])
25-
.first;
26-
expect(result, isNotEmpty);
27-
print('Result: $result');
12+
test('Model respects configuration of prompt builder.', () async {
13+
// final Catalog catalog = simpleChatCatalog;
14+
// final promptBuilder = simpleChatPromptBuilder;
2815
});
2916
}

examples/simple_chat/lib/chat_session.dart

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,41 @@ import 'ai_client.dart';
1212
import 'ai_client_transport.dart';
1313
import '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+
'''
2518
When you need additional information from the user, try to use the component '${BasicCatalogItems.choicePicker.name}' to ask for it.
2619
''',
27-
'''
20+
'''
2821
If 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

Comments
 (0)