Skip to content

wip#123

Draft
kevmoo wants to merge 1 commit intomainfrom
better_chrome_plugin
Draft

wip#123
kevmoo wants to merge 1 commit intomainfrom
better_chrome_plugin

Conversation

@kevmoo
Copy link
Collaborator

@kevmoo kevmoo commented Feb 13, 2026

No description provided.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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 genkit_chrome package by introducing support for defining expected input and output languages for local AI models. This functionality allows for more precise control over how the AI processes and generates content, which is particularly useful for multilingual applications. The changes span across core interop definitions, model configuration, and a demonstration within the sample application's user interface and logic.

Highlights

  • Language Model Options Extension: Extended the LanguageModelOptions with new properties, expectedInputs and expectedOutputs, to allow for specifying expected input and output types and languages for the Chrome local AI.
  • Chrome Model Integration: Integrated the new expectedInputs and expectedOutputs into the ChromeModel's configuration parsing and model creation logic, including new helper functions for parsing these settings from dynamic configurations.
  • Sample Application UI Update: Updated the sample application's user interface (index.html) to include dedicated input fields for users to specify comma-separated expected input and output languages.
  • Sample Application Logic Update: Modified the sample application's main.dart to read the new expected input and output language settings from the UI and pass them correctly to the ChromeModel during AI generation calls.
Changelog
  • packages/genkit_chrome/lib/src/chrome_interop.dart
    • Added expectedInputs and expectedOutputs properties to the LanguageModelOptions factory and external getters.
    • Defined new LanguageModelExpectedInput and LanguageModelExpectedOutput extension types.
    • Updated the initialPrompts getter to be nullable.
  • packages/genkit_chrome/lib/src/chrome_model.dart
    • Modified the ChromeModel to incorporate expectedInputs and expectedOutputs into the model creation process.
    • Introduced _parseExpectedInputs and _parseExpectedOutputs helper functions to handle parsing of these new configuration options.
  • testapps/genkit_chrome_sample/web/index.html
    • Added new HTML input elements for expectedInputLanguages and expectedOutputLanguages to the settings section.
  • testapps/genkit_chrome_sample/web/main.dart
    • Declared new HTMLInputElement references for the expected language fields.
    • Implemented logic to parse comma-separated language inputs from the UI.
    • Updated the _submit function to include expected input and output languages in the ai.generate configuration.
Activity
  • No specific activity (comments, reviews, progress) has been recorded for this pull request yet.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +174 to +214
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;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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,
  );
}

Comment on lines +198 to +207
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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant