Class CoworkPrompts

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

public final class CoworkPrompts extends Object
The library of prompts of the Cowork view: the ready-made ones, and the user's own, which are kept in the file prompts/cowork-prompts.tsv of the configuration folder (one prompt per line: category, title and text, separated by tabs; a line break in the text is written as \n). The prompts are written in English; the answer is asked for in the language of the interface. Places that start with {…} are replaced by data of the repository when the prompt is sent, see CoworkContext.
  • Field Details

    • YOURS

      public static final String YOURS
      See Also:
    • DEFAULT_FAVORITES

      public static final Set<String> DEFAULT_FAVORITES
      The ready-made prompts that are favourites until the user says otherwise.
  • Method Details

    • userFile

      public static Path userFile()
      prompts/cowork-prompts.tsv in the configuration folder.
    • builtIn

      public static List<CoworkPrompts.Prompt> builtIn()
      The ready-made prompts, by category.
    • user

      public static List<CoworkPrompts.Prompt> user(Path file)
      The prompts the user wrote.
    • hidden

      public static Set<String> hidden(Path file)
      The titles of the built-in prompts that the user has hidden or replaced by an edited copy.
    • add

      public static void add(Path file, String category, String title, String text) throws IOException
      Adds a prompt of one's own to the file (not a favourite).
      Throws:
      IOException
    • add

      public static void add(Path file, String category, String title, String text, boolean favorite) throws IOException
      Adds a prompt of the user.
      Throws:
      IOException
    • update

      public static void update(Path file, int index, String category, String title, String text) throws IOException
      Changes the category, the title and the text of the user's own prompt at index; it stays a favourite or not.
      Throws:
      IOException
    • update

      public static void update(Path file, int index, String category, String title, String text, Boolean favorite) throws IOException
      As above, and a favorite that is not null sets whether it is a favourite.
      Throws:
      IOException
    • delete

      public static void delete(Path file, int index) throws IOException
      Removes the user's own prompt at index.
      Throws:
      IOException
    • hide

      public static void hide(Path file, String title) throws IOException
      Hides a ready-made prompt.
      Throws:
      IOException
    • override

      public static void override(Path file, CoworkPrompts.Prompt builtIn, String category, String title, String text) throws IOException
      Replaces a ready-made prompt by an edited copy of one's own, in the given category: the original is hidden. The copy is a favourite like the original.
      Throws:
      IOException
    • override

      public static void override(Path file, CoworkPrompts.Prompt builtIn, String category, String title, String text, Boolean favorite) throws IOException
      Replaces a built-in prompt by an edited copy: the copy is added and the original hidden.
      Throws:
      IOException
    • setFavorite

      public static void setFavorite(Path file, CoworkPrompts.Prompt p, boolean favorite) throws IOException
      Makes a prompt of the library a favourite or not.
      Throws:
      IOException
    • favorites

      public static List<CoworkPrompts.Prompt> favorites(Path file)
      The prompts of the library that are favourites, in the order they are shown.
    • categories

      public static List<String> categories(Path file)
      The categories of the library as they are shown (the ready-made ones that are not hidden and the user's own), each once, in order.
    • renameCategory

      public static void renameCategory(Path file, String from, String to) throws IOException
      Gives a category another name. Prompts of one's own in it move over; the ready-made ones in it become prompts of one's own in the new category (with their favourite state) and the originals are hidden. An existing category of that name takes the prompts in (the two merge).
      Throws:
      IOException
    • deleteCategory

      public static void deleteCategory(Path file, String category) throws IOException
      Removes a category with its prompts: the user's own are deleted, the ready-made ones hidden.
      Throws:
      IOException
    • restore

      public static void restore(Path file) throws IOException
      Shows all ready-made prompts again (the user's own stay).
      Throws:
      IOException
    • canonicalCategory

      public static String canonicalCategory(String typed, List<String> known)
      The name of a category that the user typed, as the library knows it: a typed name that is a known category (or its translation, in any case) is that category, so "Schreiben" and "Write" do not become two columns.
    • suggestionPrompt

      public static String suggestionPrompt(String text, List<String> categories)
      The question to the AI: a title and a category for the prompt, the categories of the library to choose from. Only the text of the prompt is sent.
    • parseSuggestion

      public static Optional<CoworkPrompts.Suggestion> parseSuggestion(String answer, List<String> known)
      Reads the answer of the AI: a line TITLE: … and a line CATEGORY: … (in any case, with quotes or bold marks around the words). The category is a known one of the library when it matches one; without a category the prompt goes to YOURS. Empty when there is no title.
    • all

      public static List<CoworkPrompts.Prompt> all(Path userFile)
      The ready-made prompts that are not hidden and then the user's own, in the order they are shown.