mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 09:41:24 +01:00
AI generation for notes (#1112)
* feat: ai generation for notes * feat - ai generation -default to gpt-4o-mini * feat - ai generation - change update text * feat - ai generation - improve prompt --------- Co-authored-by: Azgaar <azgaar.fmg@yandex.com>
This commit is contained in:
parent
1f280133be
commit
6df54d1ef6
5 changed files with 139 additions and 4 deletions
|
|
@ -55,6 +55,7 @@ function editNotes(id, name) {
|
|||
byId("notesLegend").addEventListener("blur", updateLegend);
|
||||
byId("notesPin").addEventListener("click", toggleNotesPin);
|
||||
byId("notesFocus").addEventListener("click", validateHighlightElement);
|
||||
byId("notesGenerateWithAi").addEventListener("click", openAiGenerator);
|
||||
byId("notesDownload").addEventListener("click", downloadLegends);
|
||||
byId("notesUpload").addEventListener("click", () => legendsToLoad.click());
|
||||
byId("legendsToLoad").addEventListener("change", function () {
|
||||
|
|
@ -143,6 +144,25 @@ function editNotes(id, name) {
|
|||
});
|
||||
}
|
||||
|
||||
function openAiGenerator() {
|
||||
const note = notes.find(note => note.id === notesSelect.value);
|
||||
|
||||
let prompt = `Respond with description. Use simple dry language. Invent facts, names and details. Split to paragraphs and format to HTML. Remove h tags, remove markdown.`;
|
||||
if (note?.name) prompt += ` Name: ${note.name}.`;
|
||||
if (note?.legend) prompt += ` Data: ${note.legend}`;
|
||||
|
||||
const onApply = result => {
|
||||
notesLegend.innerHTML = result;
|
||||
if (note) {
|
||||
note.legend = result;
|
||||
updateNotesBox(note);
|
||||
if (window.tinymce) tinymce.activeEditor.setContent(note.legend);
|
||||
}
|
||||
};
|
||||
|
||||
geneateWithAi(prompt, onApply);
|
||||
}
|
||||
|
||||
function downloadLegends() {
|
||||
const notesData = JSON.stringify(notes);
|
||||
const name = getFileName("Notes") + ".txt";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue