[Feature Request]: Hop GUI API for plugins to ask the default AI provider

オープン
#9,702 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
25/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
活発
技術スタック
java

調査の方向性

Start with the existing HopGui.openAiAdvisorSession route in hop-ui and the extension-point lookup it uses, then read HopAiConfigSingleton, AiProviderLoader and AiChatFactory in hop-tech-ai. The work spans hop-ui (HopAi, AiPrompt, AiAnswer), hop-core (IHopAiService) and hop-tech-ai (HopAiServiceImpl, HopGuiAiServiceLookup); first settle the lookup contract and how isAvailable stays cheap. Done when a plugin can call HopAi.askAsync against the default provider with masking and full-XML rules enforced, and Hop Web's UI-thread callback path is checked.

索引モデルが issue の本文から書いたものです。

説明

AI awaiting triage P3
What would you like to happen?
Why

A plugin that wants to ask the configured AI provider a simple question has to use too much Java reflection.

This came up while prototyping a button in the Git commit perspective that generates the commit message from the changes. The feature only concerns the Git plugin, but hop-tech-ai is optional and has its own class loader, so the Git plugin cannot compile against it. To send one prompt, it has to find the AI plugin in the registry, get its class loader, and call these by name:

  • HopAiLegacyConfigMigrator.migrate
  • HopAiConfigSingleton.getConfig, then isAiEnabled, getDefaultProviderName and isAllowSendFullXml
  • AiTextUtil.redactSecrets
  • AiProviderLoader.load
  • AiChatFactory.generate

This has several drawbacks:

  • A rename in hop-tech-ai only fails at runtime.
  • Each plugin has to apply the AI privacy rules itself (enabled switch, secret masking, "Allow sending full XML"), and can forget one.
  • Each plugin repeats the same work: thread context class loader, background thread, return to the UI thread, clean-up of the answer.
Proposal

A small API in Hop GUI to know whether AI can be used and to ask it something, with no reflection in the calling plugin.

if (HopAi.isAvailable(hopGui)) {
  AiPrompt prompt =
      AiPrompt.builder()
          .system(SYSTEM_PROMPT)
          .data("changed_files", files)              // secrets masked, block tags neutralized
          .data("diff", textDiff, 60_000)            // with a maximum size
          .hopXml("pipeline_diff", xmlDiff, summary) // summary when full XML is not allowed
          .build();

  HopAi.askAsync(
      hopGui,
      prompt,
      answer -> wMessage.setText(answer.text()), // called on the UI thread
      error -> showStatus(error.getMessage()));
}

hop-ui: the entry point for plugins

public final class HopAi {
  /** True when the AI plugin is installed and enabled, with a valid default provider. */
  public static boolean isAvailable(HopGui hopGui);

  /** Call outside the UI thread. */
  public static AiAnswer ask(HopGui hopGui, AiPrompt prompt) throws HopException;

  /** Runs in the background, and calls back on the UI thread. */
  public static void askAsync(
      HopGui hopGui,
      AiPrompt prompt,
      Consumer<AiAnswer> onAnswer,
      Consumer<HopException> onError);
}

hop-core: the contract, without any model library type

public interface IHopAiService {
  boolean isAvailable(IHopMetadataProvider metadata);

  AiAnswer ask(AiPrompt prompt, IVariables variables, IHopMetadataProvider metadata)
      throws HopException;
}

public record AiAnswer(
    String text, Integer inputTokens, Integer outputTokens, long durationMs) {}

AiPrompt is a plain builder: system, data, hopXml, and the optional provider(name) and jsonOnly().

hop-tech-ai: the implementation

HopAiServiceImpl reads the configuration, loads the provider, applies the privacy rules and calls the model. HopAi gets it through a new extension point, HopGuiAiServiceLookup, the same way HopGui.openAiAdvisorSession reaches the plugin today. After that lookup, calls are normal Java calls, checked at compile time.

Behavior
  • isAvailable returns false without the AI plugin. It makes no network call and stays cheap, so a plugin can call it when it refreshes its toolbar. Availability can change during a session (option, default provider, project).
  • ask throws a HopException with a message for the user when AI cannot be used, for example if the provider was removed in the meantime.
  • The privacy rules are in the implementation, so a plugin cannot bypass them: data is always masked, and hopXml only sends its content with "Allow sending full XML".
  • Model reasoning (<think>) and a surrounding code block are removed from the answer.
  • The default AI provider is used unless provider(name) is set.
Out of scope for a first version
  • Streaming and conversation history.
  • Cancellation: AiChatFactory cannot interrupt a request today.
  • LanguageModelChatAiProviderSupport, which merges a provider configuration and does not ask the model anything.
To check

Hop Web: calling back on the UI thread from a background thread may need RAP server push.

Issue Priority

Priority: 3

Issue Component

Component: AI

主要言語
Java
スター
1.6k
フォーク
499
平均マージ
1日 5時間
マージ済み PR(30日)
316

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

apache/hop のほかの issue

apache/hop の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。