Log when find_server tries servers
This commit is contained in:
parent
1be3c51160
commit
8ae75afb64
1 changed files with 6 additions and 0 deletions
|
@ -23,20 +23,26 @@ async def ollama_client(url: str) -> AsyncClient:
|
|||
|
||||
class AIModule(niobot.Module):
|
||||
bot: "TortoiseIntegratedBot"
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
async def find_server(self, gpu_only: bool = True) -> dict[str, str | bool] | None:
|
||||
for name, cfg in self.bot.cfg["ollama"].items():
|
||||
url = cfg["url"]
|
||||
gpu = cfg["gpu"]
|
||||
if gpu_only and not gpu:
|
||||
self.log.info("Skipping %r, need GPU.", name)
|
||||
continue
|
||||
async with ollama_client(url) as client:
|
||||
try:
|
||||
self.log.info("Trying %r", name)
|
||||
await client.ps()
|
||||
except (httpx.HTTPError, ConnectionError):
|
||||
self.log.warning("%r is offline, trying next.", name)
|
||||
continue
|
||||
else:
|
||||
self.log.info("%r is online.")
|
||||
return {"name": name, **cfg}
|
||||
self.log.warning("No suitable ollama server is online.")
|
||||
|
||||
@staticmethod
|
||||
def read_users():
|
||||
|
|
Loading…
Reference in a new issue