Skip to content

Commit

Permalink
ollama: Support multiple ollama-connector instances
Browse files Browse the repository at this point in the history
  • Loading branch information
gbenson committed Feb 2, 2025
1 parent e92372e commit 303ebbe
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
3 changes: 3 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ include:
- $HOME/.config/hive/vane-webui.env

- path: services/ollama/docker-compose.yml
env_file:
- $HOME/.config/hive/ollama.env

- path: services/service-monitor/docker-compose.yml
- path: services/vane-webui-api/docker-compose.yml

Expand Down
2 changes: 2 additions & 0 deletions services/ollama/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ services:
- ollama
secrets:
- rabbitmq.env
command:
- --request-queue-prefix=${OLLAMA_REQUEST_QUEUE_PREFIX}

ollama:
image: ollama/ollama
Expand Down
41 changes: 39 additions & 2 deletions services/ollama/hive/ollama/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import requests

from hive.common import ArgumentParser
from hive.messaging import Channel, Message
from hive.service import HiveService

Expand All @@ -18,8 +19,44 @@

@dataclass
class Service(HiveService):
ollama_api_url: str = "http://ollama:11434"
request_queue: str = "ollama.api.requests"
DEFAULT_API_URL: ClassVar[str] = "http://ollama:11434"
ollama_api_url: Optional[str] = None

DEFAULT_QUEUE: ClassVar[str] = "ollama.api.requests"
request_queue: Optional[str] = None

def make_argument_parser(self) -> ArgumentParser:
parser = super().make_argument_parser()
parser.add_argument(
"--ollama-api-url",
metavar="URL",
default=self.DEFAULT_API_URL,
help=(f"URL to proxy requests to"
f" [default: {self.DEFAULT_API_URL}]"),
)
parser.add_argument(
"--request-queue",
metavar="QUEUE",
default=self.DEFAULT_QUEUE,
help=(f"Queue to consume requests from"
f" [default: {self.DEFAULT_QUEUE}]"),
)
parser.add_argument(
"--request-queue-prefix",
metavar="PREFIX",
help=("Prefix to prepend to request queue name"
" [default: no prefix]"),
)
return parser

def __post_init__(self):
super().__post_init__()
if not self.ollama_api_url:
self.ollama_api_url = self.args.ollama_api_url
if not self.request_queue:
self.request_queue = self.args.request_queue
if (prefix := self.args.request_queue_prefix):
self.request_queue = f"{prefix}{self.request_queue}"

def run(self):
with self.blocking_connection() as conn:
Expand Down
1 change: 1 addition & 0 deletions services/ollama/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ authors = [{ name = "Gary Benson", email = "gary@gbenson.net" }]
description = "Ollama connector service for Hive"
requires-python = ">=3.10" # match..case
dependencies = [
"hive-common",
"hive-messaging",
"hive-service",
"requests",
Expand Down

0 comments on commit 303ebbe

Please sign in to comment.