Class AiService

java.lang.Object
io.github.jbastgen.stemma.app.ai.AiService

public final class AiService extends Object
The one door to AI services. Every AI feature of Stemma asks here; this class enforces the settings (switched off, local only), cleans and cuts the prompt (PromptGuard), picks the provider, repeats a failed try, and runs the request on a virtual thread so the user interface never waits.
  • Constructor Details

    • AiService

      public AiService(Supplier<AiConfig> config, AiService.ApiKeys keys, PromptTemplates templates)
      Parameters:
      config - the current AI settings; asked for every request, so changes apply at once
      keys - where the API key of the configured account comes from
      templates - the prompt templates
  • Method Details

    • withConfig

      public AiService withConfig(Supplier<AiConfig> other)
      The same connection with other settings, for trying out settings that are not saved yet.
    • config

      public AiConfig config()
      The settings in effect now.
    • enabled

      public boolean enabled()
      Whether AI is switched on.
    • templates

      public PromptTemplates templates()
      The prompt templates.
    • test

      public AiCall test()
      A short request that shows whether the connection works. It sends no repository data.
    • ask

      public AiCall ask(String prompt)
      Sends prompt (cleaned and cut as configured) and returns at once; the answer comes with the call.
    • ask

      public AiCall ask(String prompt, Path repository)
      Like ask(String) for a request about the repository in repository: a tool on this computer runs in that folder unless the settings name another working folder.