From 0ec616ea3f1973aa92144d2311b55c52645c20f0 Mon Sep 17 00:00:00 2001 From: nex Date: Wed, 22 Nov 2023 15:50:15 +0000 Subject: [PATCH] Fix ollama server selector [pt 1] --- cogs/other.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/cogs/other.py b/cogs/other.py index 763a714..93e7b57 100644 --- a/cogs/other.py +++ b/cogs/other.py @@ -1904,7 +1904,7 @@ class OtherCog(commands.Cog): except ValueError: model = model + ":latest" - servers = { + servers: dict[str, dict[str, str, list[str] | int]] = { "100.106.34.86:11434": { "name": "NexTop", "allow": [ @@ -1926,7 +1926,7 @@ class OtherCog(commands.Cog): }, "100.66.187.46:11434": { "name": "NexBox", - "restrict-to": [ + "allow": [ "orca-mini:latest", "orca-mini:3b", "orca-mini:7b", @@ -1935,6 +1935,12 @@ class OtherCog(commands.Cog): }, } + def model_is_allowed(model_name: str, srv: dict[str, str | list[str] | int]) -> bool: + for pat in srv.get("allow", ['*']): + if not fnmatch.fnmatch(model_name.casefold(), pat.casefold()): + return False + return True + class ServerSelector(discord.ui.View): def __init__(self): super().__init__( @@ -1951,7 +1957,7 @@ class OtherCog(commands.Cog): value=x ) for x, y in servers.items() - if fnmatch.fnmatch(model, y.get("restrict-to", ['*'])) + if model_is_allowed(model, y) ] + [ discord.SelectOption( label="Custom",