Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/genui/lib/src/facade/prompt_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,15 @@ final class _BasicPromptBuilder extends PromptBuilder {
catalog,
).toJson(indent: ' ');

String? activeCatalogId = catalog.catalogId
?.replaceAll('"', '\\"')
.replaceAll('\n', '\\n');

final fragments = <String>[
...systemPromptFragments,
'Use the provided tools to respond to user using rich UI elements.',
if (activeCatalogId != null)
'The active catalog ID is: "$activeCatalogId".',
...technicalPossibilities.systemPromptFragment(),
...catalog.systemPromptFragments,
...allowedOperations.systemPromptFragments,
Expand Down
30 changes: 30 additions & 0 deletions packages/genui/test/facade/prompt_builder_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,34 @@ void main() {
});
}
});

group('Catalog ID', () {
test('is surfaced in system prompt when provided', () {
final catalog = Catalog([
BasicCatalogItems.text,
], catalogId: 'my_custom_catalog');
final builder = PromptBuilder.chat(catalog: catalog);
final String prompt = builder.systemPromptJoined();
expect(prompt, contains('The active catalog ID is: "my_custom_catalog"'));
});

test('is not surfaced in system prompt when not provided', () {
final catalog = Catalog([BasicCatalogItems.text]);
final builder = PromptBuilder.chat(catalog: catalog);
final String prompt = builder.systemPromptJoined();
expect(prompt, isNot(contains('The active catalog ID is:')));
});

test('is sanitized in system prompt', () {
final catalog = Catalog([
BasicCatalogItems.text,
], catalogId: 'my_custom_\ncatalog"');
final builder = PromptBuilder.chat(catalog: catalog);
final String prompt = builder.systemPromptJoined();
expect(
prompt,
contains('The active catalog ID is: "my_custom_\\ncatalog\\"".'),
);
});
});
}
Comment thread
gspencergoog marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ Use the provided tools to respond to user using rich UI elements.

-------------------------------------

The active catalog ID is: "test_catalog".

-------------------------------------

IMPORTANT: You do not have the ability to execute code. If you need to perform calculations, do them yourself.

-------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ Use the provided tools to respond to user using rich UI elements.

-------------------------------------

The active catalog ID is: "test_catalog".

-------------------------------------

IMPORTANT: You do not have the ability to execute code. If you need to perform calculations, do them yourself.

-------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ Use the provided tools to respond to user using rich UI elements.

-------------------------------------

The active catalog ID is: "test_catalog".

-------------------------------------

IMPORTANT: You do not have the ability to execute code. If you need to perform calculations, do them yourself.

-------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ Use the provided tools to respond to user using rich UI elements.

-------------------------------------

The active catalog ID is: "test_catalog".

-------------------------------------

IMPORTANT: You do not have the ability to execute code. If you need to perform calculations, do them yourself.

-------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ Use the provided tools to respond to user using rich UI elements.

-------------------------------------

The active catalog ID is: "test_catalog".

-------------------------------------

IMPORTANT: You do not have the ability to execute code. If you need to perform calculations, do them yourself.

-------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ Use the provided tools to respond to user using rich UI elements.

-------------------------------------

The active catalog ID is: "test_catalog".

-------------------------------------

IMPORTANT: You do not have the ability to execute code. If you need to perform calculations, do them yourself.

-------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ Use the provided tools to respond to user using rich UI elements.

-------------------------------------

The active catalog ID is: "test_catalog".

-------------------------------------

IMPORTANT: You do not have the ability to execute code. If you need to perform calculations, do them yourself.

-------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ Use the provided tools to respond to user using rich UI elements.

-------------------------------------

The active catalog ID is: "test_catalog".

-------------------------------------

IMPORTANT: You do not have the ability to execute code. If you need to perform calculations, do them yourself.

-------------------------------------
Expand Down
1 change: 1 addition & 0 deletions packages/genui/test/functions/format_string_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:genui/src/catalog/basic_catalog.dart';
import 'package:genui/src/functions/format_string.dart';
import 'package:genui/src/model/data_model.dart';

// import 'package:genui/src/primitives/simple_items.dart'; // Unused

void main() {
Expand Down
1 change: 1 addition & 0 deletions packages/genui/test/model/catalog_exception_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:genui/genui.dart';

// import 'package:genui/src/model/catalog.dart'; // Exceptions should be exported by genui.dart, but if not we might need this.
// Assuming CatalogItemNotFoundException is exported or available.

Expand Down
3 changes: 1 addition & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@ workspace:
- examples/composer
- examples/e2e
- examples/simple_chat
- examples/travel_app
- examples/verdure/client

- packages/a2ui_core
- packages/genui
- packages/genui_a2a
- packages/json_schema_builder
- packages/json_schema_builder

- tool/fix_copyright
- tool/release
Expand Down
Loading