Package io.github.jbastgen.stemma.app.ai
Class CoworkPrompts
java.lang.Object
io.github.jbastgen.stemma.app.ai.CoworkPrompts
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.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordstatic final recordA title and a category for a prompt. -
Field Summary
FieldsModifier and TypeFieldDescriptionThe ready-made prompts that are favourites until the user says otherwise.static final String -
Method Summary
Modifier and TypeMethodDescriptionstatic voidAdds a prompt of one's own to the file (not a favourite).static voidAdds a prompt of the user.static List<CoworkPrompts.Prompt> The ready-made prompts that are not hidden and then the user's own, in the order they are shown.static List<CoworkPrompts.Prompt> builtIn()The ready-made prompts, by category.static StringcanonicalCategory(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.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.static voidRemoves the user's own prompt atindex.static voiddeleteCategory(Path file, String category) Removes a category with its prompts: the user's own are deleted, the ready-made ones hidden.static List<CoworkPrompts.Prompt> The prompts of the library that are favourites, in the order they are shown.The titles of the built-in prompts that the user has hidden or replaced by an edited copy.static voidHides a ready-made prompt.static voidReplaces a ready-made prompt by an edited copy of one's own, in the given category: the original is hidden.static voidoverride(Path file, CoworkPrompts.Prompt builtIn, String category, String title, String text, Boolean favorite) Replaces a built-in prompt by an edited copy: the copy is added and the original hidden.static Optional<CoworkPrompts.Suggestion> parseSuggestion(String answer, List<String> known) Reads the answer of the AI: a lineTITLE: …and a lineCATEGORY: …(in any case, with quotes or bold marks around the words).static voidrenameCategory(Path file, String from, String to) Gives a category another name.static voidShows all ready-made prompts again (the user's own stay).static voidsetFavorite(Path file, CoworkPrompts.Prompt p, boolean favorite) Makes a prompt of the library a favourite or not.static StringsuggestionPrompt(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.static voidChanges the category, the title and the text of the user's own prompt atindex; it stays a favourite or not.static voidAs above, and afavoritethat is not null sets whether it is a favourite.static List<CoworkPrompts.Prompt> The prompts the user wrote.static PathuserFile()prompts/cowork-prompts.tsvin the configuration folder.
-
Field Details
-
YOURS
- See Also:
-
DEFAULT_FAVORITES
The ready-made prompts that are favourites until the user says otherwise.
-
-
Method Details
-
userFile
prompts/cowork-prompts.tsvin the configuration folder. -
builtIn
The ready-made prompts, by category. -
user
The prompts the user wrote. -
add
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 atindex; 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 afavoritethat is not null sets whether it is a favourite.- Throws:
IOException
-
delete
Removes the user's own prompt atindex.- Throws:
IOException
-
hide
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
The prompts of the library that are favourites, in the order they are shown. -
categories
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
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
Removes a category with its prompts: the user's own are deleted, the ready-made ones hidden.- Throws:
IOException
-
restore
Shows all ready-made prompts again (the user's own stay).- Throws:
IOException
-
canonicalCategory
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
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
Reads the answer of the AI: a lineTITLE: …and a lineCATEGORY: …(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 toYOURS. Empty when there is no title. -
all
The ready-made prompts that are not hidden and then the user's own, in the order they are shown.
-