From f08d89f3229eac7e40fa9a9c350c178fb3e0c786 Mon Sep 17 00:00:00 2001 From: Myx Date: Sun, 11 Aug 2024 01:17:16 +0200 Subject: [PATCH] Improve chat --- Bot/Handler/ChatCommand/ChatHandler.cs | 6 ++++ Bot/Handler/ChatCommand/ChatSettings.cs | 7 ++++ Bot/Lunaris2.csproj | 1 + Bot/Program.cs | 3 +- Bot/appsettings.json | 10 ++++-- docker-compose.yml | 43 ++++++++++++++++--------- start-services.sh | 4 ++- 7 files changed, 54 insertions(+), 20 deletions(-) diff --git a/Bot/Handler/ChatCommand/ChatHandler.cs b/Bot/Handler/ChatCommand/ChatHandler.cs index d9c6c1f..a016936 100644 --- a/Bot/Handler/ChatCommand/ChatHandler.cs +++ b/Bot/Handler/ChatCommand/ChatHandler.cs @@ -12,9 +12,11 @@ namespace Lunaris2.Handler.ChatCommand { private readonly OllamaApiClient _ollama; private readonly Dictionary _chatContexts = new(); + private readonly ChatSettings _chatSettings; public ChatHandler(IOptions chatSettings) { + _chatSettings = chatSettings.Value; var uri = new Uri(chatSettings.Value.Url); _ollama = new OllamaApiClient(uri) @@ -29,6 +31,10 @@ namespace Lunaris2.Handler.ChatCommand _chatContexts.TryAdd(channelId, null); var userMessage = command.FilteredMessage; + + var randomPersonality = _chatSettings.Personalities[new Random().Next(_chatSettings.Personalities.Count)]; + + userMessage = $"{randomPersonality.Instruction} {userMessage}"; using var setTyping = command.Message.Channel.EnterTypingState(); diff --git a/Bot/Handler/ChatCommand/ChatSettings.cs b/Bot/Handler/ChatCommand/ChatSettings.cs index 48697fc..ddfc031 100644 --- a/Bot/Handler/ChatCommand/ChatSettings.cs +++ b/Bot/Handler/ChatCommand/ChatSettings.cs @@ -4,4 +4,11 @@ public class ChatSettings { public string Url { get; set; } public string Model { get; set; } + public List Personalities { get; set; } +} + +public class Personality +{ + public string Name { get; set; } + public string Instruction { get; set; } } \ No newline at end of file diff --git a/Bot/Lunaris2.csproj b/Bot/Lunaris2.csproj index 3e2682d..11724e0 100644 --- a/Bot/Lunaris2.csproj +++ b/Bot/Lunaris2.csproj @@ -16,6 +16,7 @@ + diff --git a/Bot/Program.cs b/Bot/Program.cs index 5f68df1..df2e13e 100644 --- a/Bot/Program.cs +++ b/Bot/Program.cs @@ -42,7 +42,8 @@ public class Program .AddJsonFile("appsettings.json") .Build(); - services.AddSingleton(client) + services + .AddSingleton(client) .AddSingleton(commands) .AddMediatR(configuration => configuration.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly())) .AddSingleton() diff --git a/Bot/appsettings.json b/Bot/appsettings.json index b671103..3f0d860 100644 --- a/Bot/appsettings.json +++ b/Bot/appsettings.json @@ -11,7 +11,13 @@ "LavaLinkHostname": "127.0.0.1", "LavaLinkPort": 2333, "LLM": { - "Url": "http://192.168.50.54:11434", - "Model": "gemma" + "Url": "http://localhost:7869", + "Model": "gemma", + "personalities": [ + { + "name": "Lunaris", + "instruction": "Let's role play. Your name is Lunaris and can be quite rude. You are supposed to answer on following question with a maximum of 2 sentences:" + } + ] } } diff --git a/docker-compose.yml b/docker-compose.yml index 0293448..73a84f2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -26,34 +26,43 @@ services: - "2333:2333" ollama: - volumes: - - ollama:/root/.ollama - # comment below to not expose Ollama API outside the container stack + image: ollama/ollama:latest ports: - - 11434:11434 + - 7869:11434 + volumes: + - .:/code + - ./ollama/ollama:/root/.ollama container_name: ollama pull_policy: always tty: true - restart: unless-stopped - image: ollama/ollama:latest + restart: always + environment: + - OLLAMA_KEEP_ALIVE=24h + - OLLAMA_HOST=0.0.0.0 + networks: + - ollama-docker ollama-webui: - build: - context: . - args: - OLLAMA_API_BASE_URL: '/ollama/api' - dockerfile: Dockerfile - image: ollama-webui:latest + image: ghcr.io/open-webui/open-webui:main container_name: ollama-webui + volumes: + - ./ollama/ollama-webui:/app/backend/data depends_on: - ollama ports: - - 3000:8080 - environment: - - "OLLAMA_API_BASE_URL=http://ollama:11434/api" + - 8080:8080 + environment: # https://docs.openwebui.com/getting-started/env-configuration#default_models + - OLLAMA_BASE_URLS=http://host.docker.internal:7869 #comma separated ollama hosts + - ENV=dev + - WEBUI_AUTH=False + - WEBUI_NAME=valiantlynx AI + - WEBUI_URL=http://localhost:8080 + - WEBUI_SECRET_KEY=t0p-s3cr3t extra_hosts: - host.docker.internal:host-gateway restart: unless-stopped + networks: + - ollama-docker volumes: ollama: {} @@ -61,4 +70,6 @@ volumes: networks: # create a lavalink network you can add other containers to, to give them access to Lavalink lavalink: - name: lavalink \ No newline at end of file + name: lavalink + ollama-docker: + external: false \ No newline at end of file diff --git a/start-services.sh b/start-services.sh index e92332e..956fe58 100644 --- a/start-services.sh +++ b/start-services.sh @@ -1 +1,3 @@ -docker compose up -d \ No newline at end of file +docker compose up -d + +read -p "Press enter to continue"