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

Aperta
#9,702 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
25/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
java

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
Java
Stelle
1.6k
Fork
499
Merge medio
1g 5h
PR unite (30g)
316

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di apache/hop

Tutte le issue di apache/hop

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.