hack-house/examples/echo_provider.py
leetcrypt 65df12de9e feat(ai): model profiles, capability discovery, and agentless /ai list|models
Make connecting any model a config step, not a code change:
- models.toml named profiles (api_key_env names an env var, never the key)
- providers gain available_models(); add preflight + --list-models/--check
- /ai list and /ai models in-room; client probes local Ollama for
  /ai models when no agent is running, and /ai list hints to summon one
- docs/providers.md provider guide + examples/echo_provider.py
- README: command table, AI section, layout updated

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-06-01 15:25:07 -07:00

35 lines
1.0 KiB
Python

"""Minimal bring-your-own Provider example.
A Provider just turns (system prompt + messages) into one reply string. Anything
with ``name``, ``model`` and a ``complete()`` method qualifies — no base class,
no SDK. Point the agent at it with the ``module:Class`` spec:
python -m cmd_chat.agent 127.0.0.1 3000 --no-tls --password hunter2 \
--provider examples.echo_provider:EchoProvider
or via models.toml:
[echo]
provider = "examples.echo_provider:EchoProvider"
model = "echo-1"
Implementing ``available_models()`` is optional; it powers ``--list-models``,
``--check`` preflight, and the in-room ``/ai models`` command.
"""
from __future__ import annotations
class EchoProvider:
name = "echo"
def __init__(self, model: str = "echo-1"):
self.model = model
def complete(self, system: str, messages: list) -> str:
last = messages[-1].content if messages else ""
return f"echo: {last}"
def available_models(self) -> list[str]: # optional
return ["echo-1"]