Conversation
Summary of ChangesHello @kevmoo, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request adds support for expectedInputs and expectedOutputs to the Chrome AI model, which is a valuable enhancement. The changes include updates to the interop layer, the model implementation, and the sample application UI. The implementation is solid, and the identified areas for reducing code duplication by introducing helper functions remain valid suggestions for improving maintainability.
| List<LanguageModelExpectedInput>? _parseExpectedInputs( | ||
| Map<String, dynamic> config, | ||
| ) { | ||
| final inputs = config['expectedInputs']; | ||
| if (inputs is List) { | ||
| return inputs.map((e) { | ||
| if (e is Map) { | ||
| return LanguageModelExpectedInput( | ||
| type: e['type'] as String? ?? 'text', | ||
| languages: (e['languages'] as List?) | ||
| ?.map((l) => (l as String).toJS) | ||
| .toList() | ||
| .toJS, | ||
| ); | ||
| } | ||
| throw ArgumentError('Invalid expectedInput: $e'); | ||
| }).toList(); | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| List<LanguageModelExpectedOutput>? _parseExpectedOutputs( | ||
| Map<String, dynamic> config, | ||
| ) { | ||
| final outputs = config['expectedOutputs']; | ||
| if (outputs is List) { | ||
| return outputs.map((e) { | ||
| if (e is Map) { | ||
| return LanguageModelExpectedOutput( | ||
| type: e['type'] as String? ?? 'text', | ||
| languages: (e['languages'] as List?) | ||
| ?.map((l) => (l as String).toJS) | ||
| .toList() | ||
| .toJS, | ||
| ); | ||
| } | ||
| throw ArgumentError('Invalid expectedOutput: $e'); | ||
| }).toList(); | ||
| } | ||
| return null; | ||
| } |
There was a problem hiding this comment.
The functions _parseExpectedInputs and _parseExpectedOutputs are nearly identical. To improve maintainability and reduce code duplication, you can refactor them into a single generic helper function that handles the parsing logic for both.
List<T>? _parseExpected<T>({
required Map<String, dynamic> config,
required String key,
required T Function({String type, JSArray<JSString>? languages}) constructor,
}) {
final items = config[key];
if (items is List) {
return items.map((e) {
if (e is Map) {
return constructor(
type: e['type'] as String? ?? 'text',
languages: (e['languages'] as List?)
?.map((l) => (l as String).toJS)
.toList()
.toJS,
);
}
throw ArgumentError('Invalid item in $key: $e');
}).toList();
}
return null;
}
List<LanguageModelExpectedInput>? _parseExpectedInputs(
Map<String, dynamic> config,
) {
return _parseExpected(
config: config,
key: 'expectedInputs',
constructor: LanguageModelExpectedInput.new,
);
}
List<LanguageModelExpectedOutput>? _parseExpectedOutputs(
Map<String, dynamic> config,
) {
return _parseExpected(
config: config,
key: 'expectedOutputs',
constructor: LanguageModelExpectedOutput.new,
);
}| final inputLangs = _expectedInputLanguages.value | ||
| .split(',') | ||
| .map((e) => e.trim()) | ||
| .where((e) => e.isNotEmpty) | ||
| .toList(); | ||
| final outputLangs = _expectedOutputLanguages.value | ||
| .split(',') | ||
| .map((e) => e.trim()) | ||
| .where((e) => e.isNotEmpty) | ||
| .toList(); |
There was a problem hiding this comment.
There's duplicated logic for parsing the comma-separated language strings from the input fields. You can extract this into a local helper function to avoid repetition and make the code cleaner.
| final inputLangs = _expectedInputLanguages.value | |
| .split(',') | |
| .map((e) => e.trim()) | |
| .where((e) => e.isNotEmpty) | |
| .toList(); | |
| final outputLangs = _expectedOutputLanguages.value | |
| .split(',') | |
| .map((e) => e.trim()) | |
| .where((e) => e.isNotEmpty) | |
| .toList(); | |
| List<String> parseLangs(String value) => value | |
| .split(',') | |
| .map((e) => e.trim()) | |
| .where((e) => e.isNotEmpty) | |
| .toList(); | |
| final inputLangs = parseLangs(_expectedInputLanguages.value); | |
| final outputLangs = parseLangs(_expectedOutputLanguages.value); |
No description provided.