Compare commits

...

1 Commits
0.1.5 ... 0.1.6

Author SHA1 Message Date
d72676c7e0 Improve chat (#2)
Co-authored-by: Myx <info@azaaxin.com>
2024-08-11 01:18:29 +02:00
7 changed files with 54 additions and 20 deletions

View File

@@ -12,9 +12,11 @@ namespace Lunaris2.Handler.ChatCommand
{ {
private readonly OllamaApiClient _ollama; private readonly OllamaApiClient _ollama;
private readonly Dictionary<ulong, Chat?> _chatContexts = new(); private readonly Dictionary<ulong, Chat?> _chatContexts = new();
private readonly ChatSettings _chatSettings;
public ChatHandler(IOptions<ChatSettings> chatSettings) public ChatHandler(IOptions<ChatSettings> chatSettings)
{ {
_chatSettings = chatSettings.Value;
var uri = new Uri(chatSettings.Value.Url); var uri = new Uri(chatSettings.Value.Url);
_ollama = new OllamaApiClient(uri) _ollama = new OllamaApiClient(uri)
@@ -30,6 +32,10 @@ namespace Lunaris2.Handler.ChatCommand
var userMessage = command.FilteredMessage; 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(); using var setTyping = command.Message.Channel.EnterTypingState();
if (string.IsNullOrWhiteSpace(userMessage)) if (string.IsNullOrWhiteSpace(userMessage))

View File

@@ -4,4 +4,11 @@ public class ChatSettings
{ {
public string Url { get; set; } public string Url { get; set; }
public string Model { get; set; } public string Model { get; set; }
public List<Personality> Personalities { get; set; }
}
public class Personality
{
public string Name { get; set; }
public string Instruction { get; set; }
} }

View File

@@ -16,6 +16,7 @@
<PackageReference Include="Discord.Net.Rest" Version="3.13.1" /> <PackageReference Include="Discord.Net.Rest" Version="3.13.1" />
<PackageReference Include="MediatR" Version="12.2.0" /> <PackageReference Include="MediatR" Version="12.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" /> <PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" /> <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" /> <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" /> <PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />

View File

@@ -42,7 +42,8 @@ public class Program
.AddJsonFile("appsettings.json") .AddJsonFile("appsettings.json")
.Build(); .Build();
services.AddSingleton(client) services
.AddSingleton(client)
.AddSingleton(commands) .AddSingleton(commands)
.AddMediatR(configuration => configuration.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly())) .AddMediatR(configuration => configuration.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly()))
.AddSingleton<DiscordEventListener>() .AddSingleton<DiscordEventListener>()

View File

@@ -11,7 +11,13 @@
"LavaLinkHostname": "127.0.0.1", "LavaLinkHostname": "127.0.0.1",
"LavaLinkPort": 2333, "LavaLinkPort": 2333,
"LLM": { "LLM": {
"Url": "http://192.168.50.54:11434", "Url": "http://localhost:7869",
"Model": "gemma" "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:"
}
]
} }
} }

View File

@@ -26,34 +26,43 @@ services:
- "2333:2333" - "2333:2333"
ollama: ollama:
volumes: image: ollama/ollama:latest
- ollama:/root/.ollama
# comment below to not expose Ollama API outside the container stack
ports: ports:
- 11434:11434 - 7869:11434
volumes:
- .:/code
- ./ollama/ollama:/root/.ollama
container_name: ollama container_name: ollama
pull_policy: always pull_policy: always
tty: true tty: true
restart: unless-stopped restart: always
image: ollama/ollama:latest environment:
- OLLAMA_KEEP_ALIVE=24h
- OLLAMA_HOST=0.0.0.0
networks:
- ollama-docker
ollama-webui: ollama-webui:
build: image: ghcr.io/open-webui/open-webui:main
context: .
args:
OLLAMA_API_BASE_URL: '/ollama/api'
dockerfile: Dockerfile
image: ollama-webui:latest
container_name: ollama-webui container_name: ollama-webui
volumes:
- ./ollama/ollama-webui:/app/backend/data
depends_on: depends_on:
- ollama - ollama
ports: ports:
- 3000:8080 - 8080:8080
environment: environment: # https://docs.openwebui.com/getting-started/env-configuration#default_models
- "OLLAMA_API_BASE_URL=http://ollama:11434/api" - 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: extra_hosts:
- host.docker.internal:host-gateway - host.docker.internal:host-gateway
restart: unless-stopped restart: unless-stopped
networks:
- ollama-docker
volumes: volumes:
ollama: {} ollama: {}
@@ -62,3 +71,5 @@ networks:
# create a lavalink network you can add other containers to, to give them access to Lavalink # create a lavalink network you can add other containers to, to give them access to Lavalink
lavalink: lavalink:
name: lavalink name: lavalink
ollama-docker:
external: false

View File

@@ -1 +1,3 @@
docker compose up -d docker compose up -d
read -p "Press enter to continue"