Updated Ollama text generation (markdown)

Azgaar 2025-06-14 15:12:57 +02:00
parent 3d2874344a
commit ea99f38d5c

@ -1,4 +1,4 @@
An integration with [Ollama](https://ollama.com/) allows users to leverage local large language models to generate text data for the Map Genrator.
An integration with [Ollama](https://ollama.com/) allows users to leverage local large language models to generate text data for the Map Generator.
## Setup and Configuration
@ -13,7 +13,7 @@ To use Ollama with Fantasy Map Generator, you need to ensure Ollama is correctly
By default, Ollama might only listen for connections from the same machine (`localhost` or `127.0.0.1`). For Fantasy Map Generator to access Ollama, especially from other devices on your local network, you must configure Ollama to listen on all network interfaces and allow cross-origin requests.
* **Set `OLLAMA_HOST` Environment Variable:**
* Set `OLLAMA_HOST` Environment Variable:
* This variable tells Ollama which network interfaces to listen on.
* **Action:** Set `OLLAMA_HOST` to `0.0.0.0`.
* **How to set (Windows Permanent):**
@ -28,7 +28,7 @@ By default, Ollama might only listen for connections from the same machine (`loc
1. **Per session:** In your terminal, before running `ollama serve`: `export OLLAMA_HOST="0.0.0.0"`
2. **Persistent:** Add `export OLLAMA_HOST="0.0.0.0"` to your shell profile file (e.g., `~/.bashrc`, `~/.zshrc`), then `source` the file or restart your terminal.
* **Set `OLLAMA_ORIGINS` Environment Variable (CORS Configuration):**
* Set `OLLAMA_ORIGINS` Environment Variable (CORS Configuration):
* This variable is essential for browsers to allow JavaScript code from one origin (Fantasy Map Generator's port 8000) to communicate with Ollama on a different port (11434).
* **Action:** Set `OLLAMA_ORIGINS` to allow your Fantasy Map Generator's origin.
* **How to set (Windows Permanent):** Follow the same steps as for `OLLAMA_HOST`, but use:
@ -44,21 +44,8 @@ By default, Ollama might only listen for connections from the same machine (`loc
* Ensure your PC's firewall (e.g., Windows Defender Firewall) is not blocking incoming connections to Ollama's default port, `11434`.
* **Action:** Create an inbound rule to allow TCP traffic on port `11434`.
**3. Configure Fantasy Map Generator's `ai-generator.js`:**
**3. Configure Fantasy Map Generator**
The `ai-generator.js` file needs to point to the correct Ollama endpoint.
Select `ollama` from the list of models and provide desired model name to the `key` field. You don't need a key, so use this field to define the model name.
* **Scenario A: Using only on the same machine (`localhost`):**
* Ensure the `fetch` call in the `generateWithOllama` function (inside `modules/ui/ai-generator.js`) points to `http://localhost:11434/api/generate`. This is usually the default.
* **Scenario B: Using from other machines on the local network:**
* You **must** change the `fetch` call in the `generateWithOllama` function (inside `modules/ui/ai-generator.js`) to use the actual local IP address of your machine where Ollama is running.
* **Example:**
```javascript
// Inside modules/ui/ai-generator.js, within generateWithOllama function:
const response = await fetch("http://192.168.178.46:11434/api/generate" // Replace with your actual PC's IP
```
* **How to find your PC's IP:**
* **Windows:** Open Command Prompt (`cmd`) and type `ipconfig`. Look for "IPv4 Address" under your active network adapter.
* **Linux/macOS:** Open Terminal and type `ip addr show` or `ifconfig`.
The FMG points `http://localhost:11434/api/generate` for Ollama generation. In you need a different endpoint, change it in the `ai-generator.js` file.