Skip to content

draft for entrypoint #3169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
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
8 changes: 8 additions & 0 deletions pkgs/dart_services/lib/server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ Future<void> main(List<String> args) async {
'The name of the Cloud Storage bucket for compilation artifacts.',
defaultsTo: 'nnbd_artifacts',
)
..addOption(
'genui-key',
valueHelp: 'key',
help:
'Genui key to be passed with request. '
'Is not needed for hosted one plat service, as it will use service account.',
defaultsTo: null,
)
..addFlag(
'help',
abbr: 'h',
Expand Down
15 changes: 15 additions & 0 deletions pkgs/dart_services/lib/src/common_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import 'package:shelf_router/shelf_router.dart';
import 'analysis.dart';
import 'caching.dart';
import 'compiling.dart';
import 'flutter_genui.dart';
import 'generative_ai.dart';
import 'project_templates.dart';
import 'pub.dart';
Expand Down Expand Up @@ -311,6 +312,7 @@ class CommonServerApi {

@Route.post('$apiPrefix/generateCode')
Future<Response> generateCode(Request request, String apiVersion) async {
print('!!!! generate code');
if (apiVersion != api3) return unhandledVersion(apiVersion);

final generateCodeRequest = api.GenerateCodeRequest.fromJson(
Expand All @@ -327,6 +329,19 @@ class CommonServerApi {
);
}

@Route.post('$apiPrefix/generateUi')
Future<Response> handleGenui(Request request, String apiVersion) async {
print('!!!! generate ui');
if (apiVersion != api3) return unhandledVersion(apiVersion);

await invokeFlutterGenUi();

return _streamResponse(
'generateUi',
Stream.fromIterable(['hello', ' from', ' genui']),
);
}

@Route.post('$apiPrefix/updateCode')
Future<Response> updateCode(Request request, String apiVersion) async {
if (apiVersion != api3) return unhandledVersion(apiVersion);
Expand Down
29 changes: 29 additions & 0 deletions pkgs/dart_services/lib/src/flutter_genui.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import 'dart:convert';

import 'package:http/http.dart' as http;

Future<void> invokeFlutterGenUi() async {
print('Invoking flutter_gen_ui');

final response = await _requestGenui();
if (response.statusCode == 201) {
print('Success: ${response.body}');
} else {
print('Failed: ${response.statusCode}');
}
}

Future<http.Response> _requestGenui() {
return http.post(
Uri.parse(
'https://autopush-devgenui.sandbox.googleapis.com/v1beta1/firstparty/generateidecode\?key\=AIzaSyA5oU44eMuipFel1jxoYEh',
),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
body: jsonEncode(<String, String>{
'userPrompt': 'hello, genui',
'modelUrl': 'genuigemini://models/gemini-2.0-flash',
}),
);
}
10 changes: 5 additions & 5 deletions pkgs/dart_services/lib/src/generative_ai.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final _logger = Logger('gen-ai');
class GenerativeAI {
static const _apiKeyVarName = 'PK_GEMINI_API_KEY';
static const _geminiModel = 'gemini-2.0-flash';
late final String? _geminiApiKey;
String? _geminiApiKey;

GenerativeAI() {
final geminiApiKey = Platform.environment[_apiKeyVarName];
Expand Down Expand Up @@ -459,24 +459,24 @@ Make sure to take into account any attachments as part of the user's prompt.
''',
AppType.dart: '''
You're an expert Dart developer specializing in writing efficient, idiomatic,
and production-ready Dart programs.
and production-ready Dart programs.
You will produce professional, release-ready Dart applications. All of the
instructions below are required to be rigorously followed.

Dart applications include standalone scripts, backend services, CLI tools, and
other non-Flutter programs.
other non-Flutter programs.
They shall prioritize clarity, maintainability, and correctness. Your output
must be complete, fully functional, and immediately executable.

You're using the following process to systematically construct the Dart program
(each numbered step is a distinct part of the process):
(each numbered step is a distinct part of the process):

1. **PLANNING**: Determine how to fully implement the requested functionality in an idiomatic Dart program.
2. **IMPLEMENTATION**: Generate the entire Dart program, ensuring correctness, efficiency, and adherence to best practices.
3. **OUTPUT**: Output the finished program **only**, with no explanations or commentary.

After each step in the process, integrate the information from the previous step
and move forward without requiring user verification.
and move forward without requiring user verification.
The **only output** shall be the final, complete Dart program.


Expand Down
3 changes: 3 additions & 0 deletions pkgs/dartpad_shared/lib/services.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ class ServicesClient {
Stream<String> generateCode(GenerateCodeRequest request) =>
_requestPostStream('generateCode', request.toJson());

Stream<String> generateUi(GenerateCodeRequest request) =>
_requestPostStream('generateUi', request.toJson());

Stream<String> updateCode(UpdateCodeRequest request) =>
_requestPostStream('updateCode', request.toJson());

Expand Down
2 changes: 1 addition & 1 deletion pkgs/dartpad_ui/lib/enable_gen_ai.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
// BSD-style license that can be found in the LICENSE file.

// Turn on or off gen-ai features in the client.
const bool genAiEnabled = false;
const bool genAiEnabled = true;
2 changes: 1 addition & 1 deletion pkgs/dartpad_ui/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ class DartPadAppBar extends StatelessWidget implements PreferredSizeWidget {
LocalStorage.instance.saveLastCreateCodePrompt(promptResponse.prompt);

try {
final stream = appServices.generateCode(
final stream = appServices.generateUi(
GenerateCodeRequest(
appType: promptResponse.appType,
prompt: promptResponse.prompt,
Expand Down
4 changes: 4 additions & 0 deletions pkgs/dartpad_ui/lib/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,10 @@ class AppServices {
return services.generateCode(request);
}

Stream<String> generateUi(GenerateCodeRequest request) {
return services.generateUi(request);
}

Stream<String> updateCode(UpdateCodeRequest request) {
return services.updateCode(request);
}
Expand Down
Loading