From 169a407e026a9e390de451779df72d877220388f Mon Sep 17 00:00:00 2001 From: kroryan Date: Sun, 18 May 2025 16:11:46 +0200 Subject: [PATCH] ollama implementation --- README.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/README.md b/README.md index 3ab245b2..69e6bd2e 100644 --- a/README.md +++ b/README.md @@ -27,3 +27,34 @@ _Inspiration:_ - Amit Patel's [_Polygonal Map Generation for Games_](http://www-cs-students.stanford.edu/~amitp/game-programming/polygon-map-generation) - Scott Turner's [_Here Dragons Abound_](https://heredragonsabound.blogspot.com) + +## Recent Changes (May 18, 2025) + +### Ollama Integration for AI Text Generation + +An integration with [Ollama](https://ollama.com/) has been added as a new provider for the AI text generator feature, allowing users to leverage local large language models. + +**Key Changes:** + +* **New Provider:** "Ollama" is now available in the AI generator's model/provider selection. +* **Model Name as Key:** When Ollama is selected, the "API Key" input field is repurposed to accept the Ollama model name (e.g., `llama3`, `mistral`, etc.) instead of a traditional API key. +* **Local Endpoint:** The integration communicates with a local Ollama instance via the `http://localhost:11434/api/generate` endpoint. +* **Streaming Support:** Responses from Ollama are streamed into the text area. + +**Files Modified:** + +1. `modules/ui/ai-generator.js`: + * Added `ollama` to the `PROVIDERS` and `MODELS` constants. + * Implemented the `generateWithOllama` function to handle API requests to the Ollama endpoint. + * Modified `handleStream` to correctly parse the JSON streaming response from Ollama. + * Updated UI logic in `generateWithAi` and its helper `updateDialogElements` to: + * Change the "API Key" field's placeholder text to "Enter Ollama model name (e.g., llama3)" when Ollama is selected. + * Store and retrieve the Ollama model name from local storage similarly to how API keys are handled for other providers. + * Ensured the dialog initialization and element updates occur at the correct time (during the dialog's `open` event) to prevent errors with elements not being found in the DOM. +2. `modules/ui/notes-editor.js`: + * The `openAiGenerator` function, which is called when clicking the "generate text for notes" button, was verified to correctly invoke the `generateWithAi` function. + * The prompt sent to the AI was updated to be more explicit about requiring HTML formatting (using `

` tags, no heading tags, no markdown) to ensure consistent output. *(Self-correction: The user undid the latest prompt change, so this part of the description might not be accurate if the user intends to keep the previous prompt. The README will reflect the general functionality implemented).* The prompt engineering aims to guide the AI to produce HTML-formatted descriptions suitable for the notes section. + +**Goal:** + +The primary goal of this integration was to provide a simple and functional way to use local Ollama models within the Fantasy Map Generator's AI text generation feature, ensuring that existing functionalities, especially the "generate text for notes" button, remain operational. Initial issues with the dialog not opening were resolved by refining how and when the dialog and its internal event listeners are initialized.