From cbb3410ec91d677b1e1cdbcd12be23afb9dbd524 Mon Sep 17 00:00:00 2001 From: jz8132543 Date: Wed, 25 Sep 2024 01:23:49 +0800 Subject: [PATCH] add: perplexica, ollama, open-webui --- lib/data/data.json | 8 +++ nixos/hosts/fra1/default.nix | 1 + .../isk/_steam/dst/Caves/worldgenoverride.lua | 8 +-- .../_steam/dst/Master/worldgenoverride.lua | 4 +- nixos/hosts/isk/_steam/dst/modoverrides.lua | 36 +++++------ nixos/modules/base/module/misc/ports.nix | 2 + nixos/modules/services/ollama.nix | 62 +++++++++++++++++++ nixos/modules/services/perplexica.nix | 15 +++-- nixos/modules/services/searx.nix | 4 ++ terraform/cloudflare.tf | 2 + 10 files changed, 112 insertions(+), 30 deletions(-) create mode 100644 nixos/modules/services/ollama.nix diff --git a/lib/data/data.json b/lib/data/data.json index c3e6e578..26c7d7e0 100644 --- a/lib/data/data.json +++ b/lib/data/data.json @@ -138,6 +138,14 @@ "on": "fra1", "proxy": false }, + "ollama": { + "on": "fra1", + "proxy": false + }, + "ollama-ui": { + "on": "fra1", + "proxy": false + }, "p": { "on": "hkg4", "proxy": false diff --git a/nixos/hosts/fra1/default.nix b/nixos/hosts/fra1/default.nix index 68cbb6c9..b3b1717d 100644 --- a/nixos/hosts/fra1/default.nix +++ b/nixos/hosts/fra1/default.nix @@ -14,6 +14,7 @@ nixosModules.services.ntfy nixosModules.services.sogo nixosModules.services.pastebin + nixosModules.services.ollama (import nixosModules.services.matrix { }) (import nixosModules.services.keycloak { }) (import nixosModules.services.vaultwarden { }) diff --git a/nixos/hosts/isk/_steam/dst/Caves/worldgenoverride.lua b/nixos/hosts/isk/_steam/dst/Caves/worldgenoverride.lua index 0020699d..040b4311 100644 --- a/nixos/hosts/isk/_steam/dst/Caves/worldgenoverride.lua +++ b/nixos/hosts/isk/_steam/dst/Caves/worldgenoverride.lua @@ -1,6 +1,6 @@ return { - override_enabled = true, - worldgen_preset = "DST_CAVE", - settings_preset = "DST_CAVE", - overrides = {}, + override_enabled = true, + worldgen_preset = "DST_CAVE", + settings_preset = "DST_CAVE", + overrides = {}, } diff --git a/nixos/hosts/isk/_steam/dst/Master/worldgenoverride.lua b/nixos/hosts/isk/_steam/dst/Master/worldgenoverride.lua index e4ef3b00..42012250 100644 --- a/nixos/hosts/isk/_steam/dst/Master/worldgenoverride.lua +++ b/nixos/hosts/isk/_steam/dst/Master/worldgenoverride.lua @@ -1,4 +1,4 @@ return { - override_enabled = true, - overrides = {}, + override_enabled = true, + overrides = {}, } diff --git a/nixos/hosts/isk/_steam/dst/modoverrides.lua b/nixos/hosts/isk/_steam/dst/modoverrides.lua index 718e1185..40c6e9ad 100644 --- a/nixos/hosts/isk/_steam/dst/modoverrides.lua +++ b/nixos/hosts/isk/_steam/dst/modoverrides.lua @@ -1,20 +1,20 @@ return { - --# Health Info - ["workshop-375859599"] = { enabled = true }, - --# Show Me - ["workshop-2287303119"] = { enabled = true }, - --# No Thermal Stone Durability - ["workshop-466732225"] = { enabled = true }, - --# Extra Equip Slots - ["workshop-375850593"] = { enabled = true }, - --# Display Attack Range - ["workshop-2078243581"] = { enabled = true }, - --# Increased Stack size - ["workshop-374550642"] = { enabled = true }, - --# Combined Status - ["workshop-376333686"] = { enabled = true }, - --# Global Positions - ["workshop-378160973"] = { enabled = true }, - --# Demon sword Muramasa - ["workshop-1842087172"] = { enabled = true }, + --# Health Info + ["workshop-375859599"] = { enabled = true }, + --# Show Me + ["workshop-2287303119"] = { enabled = true }, + --# No Thermal Stone Durability + ["workshop-466732225"] = { enabled = true }, + --# Extra Equip Slots + ["workshop-375850593"] = { enabled = true }, + --# Display Attack Range + ["workshop-2078243581"] = { enabled = true }, + --# Increased Stack size + ["workshop-374550642"] = { enabled = true }, + --# Combined Status + ["workshop-376333686"] = { enabled = true }, + --# Global Positions + ["workshop-378160973"] = { enabled = true }, + --# Demon sword Muramasa + ["workshop-1842087172"] = { enabled = true }, } diff --git a/nixos/modules/base/module/misc/ports.nix b/nixos/modules/base/module/misc/ports.nix index 0ecb4f6a..1f3cc920 100644 --- a/nixos/modules/base/module/misc/ports.nix +++ b/nixos/modules/base/module/misc/ports.nix @@ -115,6 +115,8 @@ ntfy = 1161; perplexica-frontend = 3002; perplexica-backend = 3003; + ollama-api = 11434; + ollama-ui = 11435; }; }; } diff --git a/nixos/modules/services/ollama.nix b/nixos/modules/services/ollama.nix new file mode 100644 index 00000000..d8d62a9c --- /dev/null +++ b/nixos/modules/services/ollama.nix @@ -0,0 +1,62 @@ +{ config, ... }: +{ + services.ollama = { + enable = true; + host = "0.0.0.0"; + port = config.ports.ollama-api; + }; + services.open-webui = { + enable = true; + host = "0.0.0.0"; + port = config.ports.ollama-ui; + environment = { + ANONYMIZED_TELEMETRY = "False"; + DO_NOT_TRACK = "True"; + SCARF_NO_ANALYTICS = "True"; + OLLAMA_API_BASE_URL = "https://ollama.${config.networking.domain}/api"; + OLLAMA_BASE_URL = "https://ollama.${config.networking.domain}"; + # Disable authentication + WEBUI_AUTH = "False"; + ENABLE_SIGNUP = "False"; + WEBUI_URL = "http://localhost:${toString config.ports.ollama-ui}"; + # Search + ENABLE_RAG_WEB_SEARCH = "True"; + RAG_WEB_SEARCH_ENGINE = "searxng"; + SEARXNG_QUERY_URL = "https://searx.${config.networking.domain}/search?q="; + # fix crush on web search + # RAG_EMBEDDING_ENGINE = "ollama"; + # RAG_EMBEDDING_MODEL = "mxbai-embed-large:latest"; + PYDANTIC_SKIP_VALIDATING_CORE_SCHEMAS = "True"; + }; + }; + # services.nextjs-ollama-llm-ui = { + # enable = true; + # hostname = "127.0.0.1"; + # ollamaUrl = "https://ollama.${config.networking.domain}"; + # port = 11435; + # }; + services.traefik.dynamicConfigOptions.http = { + routers = { + ollama-api = { + rule = "Host(`ollama.${config.networking.domain}`)"; + entryPoints = [ "https" ]; + service = "ollama-api"; + }; + ollama-ui = { + rule = "Host(`ollama-ui.${config.networking.domain}`)"; + entryPoints = [ "https" ]; + service = "ollama-ui"; + }; + }; + services = { + ollama-api.loadBalancer = { + passHostHeader = true; + servers = [ { url = "http://localhost:${toString config.ports.ollama-api}"; } ]; + }; + ollama-ui.loadBalancer = { + passHostHeader = true; + servers = [ { url = "http://localhost:${toString config.ports.ollama-ui}"; } ]; + }; + }; + }; +} diff --git a/nixos/modules/services/perplexica.nix b/nixos/modules/services/perplexica.nix index 8e6053d4..f37ea245 100644 --- a/nixos/modules/services/perplexica.nix +++ b/nixos/modules/services/perplexica.nix @@ -10,7 +10,7 @@ virtualisation.oci-containers.containers = { perplexica-backend = { hostname = "perplexica-backend"; - image = "elestio4test/perplexica-backend"; + image = "hajowieland/perplexica-backend"; autoStart = true; volumes = [ "${config.sops.templates.perplexica.path}:/home/perplexica/config.toml" @@ -19,14 +19,17 @@ }; perplexica-frontend = { hostname = "perplexica-backend"; - image = "elestio4test/perplexica-frontend"; + image = "hajowieland/perplexica-frontend"; autoStart = true; - labels = { - # NEXT_PUBLIC_API_URL = "http://127.0.0.1:${toString config.ports.perplexica-backend}/api"; - # NEXT_PUBLIC_WS_URL = "ws://127.0.0.1:${toString config.ports.perplexica-backend}"; + environment = { NEXT_PUBLIC_API_URL = "https://perplexica-backend.${config.networking.domain}/api"; NEXT_PUBLIC_WS_URL = "wss://perplexica-backend.${config.networking.domain}"; }; + cmd = [ + "/bin/sh" + "-c" + "yarn build; yarn start" + ]; ports = [ "127.0.0.1:${toString config.ports.perplexica-frontend}:3000" ]; }; }; @@ -44,7 +47,7 @@ [API_ENDPOINTS] SEARXNG = "${config.services.searx.settings.server.base_url}" # SearxNG API URL - OLLAMA = "" # Ollama API URL - http://host.docker.internal:11434 + OLLAMA = "https://ollama.${config.networking.domain}" # Ollama API URL - http://host.docker.internal:11434 ''; }; services.traefik.dynamicConfigOptions.http = { diff --git a/nixos/modules/services/searx.nix b/nixos/modules/services/searx.nix index f2e0ef06..cb70d368 100644 --- a/nixos/modules/services/searx.nix +++ b/nixos/modules/services/searx.nix @@ -37,6 +37,10 @@ in safe_search = 0; autocomplete = "google"; # Existing autocomplete backends: "dbpedia", "duckduckgo", "google", "startpage", "swisscows", "qwant", "wikipedia" - leave blank to turn it off by default default_lang = "zh-CN"; + formats = [ + "html" + "json" + ]; }; server = { base_url = "https://${url}"; diff --git a/terraform/cloudflare.tf b/terraform/cloudflare.tf index b0b764a1..21c29ab3 100644 --- a/terraform/cloudflare.tf +++ b/terraform/cloudflare.tf @@ -82,6 +82,8 @@ locals { ntfy = { on = "fra1", proxy = false } mail = { on = "fra1", proxy = false } pb = { on = "fra1", proxy = false } + ollama = { on = "fra1", proxy = false } + ollama-ui = { on = "fra1", proxy = false } "admin.m" = { on = "fra1", proxy = false } searx = { on = "hkg4", proxy = false } morty = { on = "hkg4", proxy = false }