supplier+deploy/mainnet: LLM_BACKEND=openai via ChatMock proxy

Adds a Codex/ChatGPT backend path for the supplier alongside the
existing Ollama one. The mainnet supplier is repointed at a localhost
ChatMock proxy (RayBytes/ChatMock, pinned :v1.35) that authenticates
against a ChatGPT Pro subscription via OAuth.

- supplier/src/openai.ts: HTTP client for OpenAI-compatible
  /v1/chat/completions. Same return shape as ollama.callOllama so
  jobRunner can branch cleanly.
- supplier/src/jobRunner.ts: branch on config.llmBackend.
- supplier/src/config.ts: LLM_BACKEND ("ollama" default | "openai"),
  OPENAI_BASE_URL, OPENAI_TIMEOUT_MS (default 180_000 — GPT first-token
  latency).
- supplier/src/cli/gen-keypair.ts: standalone Ed25519 keypair generator
  + bech32 address derivation. Used to bootstrap a fresh supplier
  wallet without round-tripping through tx:post-advert --dry-run.
- deploy/mainnet/docker-compose.chatmock.yml: long-running chatmock
  serve + one-shot --profile login flow.
- deploy/mainnet/docker-compose.supplier.yml: rewritten for openai
  backend; Traefik routes at mp-suppliers-gpt.vector.apexfusion.org so
  the unsuffixed slot stays free for a future supplier with a
  different backend.
- tests/unit/supplier-openai.test.ts: unit coverage for callOpenAi.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
david
2026-05-19 13:47:44 +02:00
parent 96d9d1d354
commit 965fabd3f0
8 changed files with 731 additions and 27 deletions

View File

@@ -0,0 +1,93 @@
# deploy/mainnet/docker-compose.chatmock.yml — ChatMock — MAINNET
#
# ChatMock (RayBytes/ChatMock, MIT) is a localhost OpenAI-compatible proxy
# that authenticates against a ChatGPT subscription via Codex OAuth. Used as
# the upstream for the mainnet supplier when LLM_BACKEND=openai.
#
# Two services:
# - chatmock long-running serve mode (port 8000), joins
# marketplace-mainnet-net so the supplier can reach it
# via http://marketplace-mainnet-chatmock:8000
# - chatmock-login ONE-SHOT interactive OAuth flow, profile=login, binds
# :1455 on the host. Run once on first deploy and again
# whenever the refresh token is invalidated.
#
# Shared `chatmock_data` named volume persists OAuth tokens at /data inside
# the container (CHATGPT_LOCAL_HOME=/data tells ChatMock to use that path).
#
# Pre-flight networks (must already exist):
# docker network create marketplace-mainnet-net # one-shot
#
# First-run sequence (one-time, then never again unless tokens are revoked):
# docker compose -f docker-compose.chatmock.yml up -d chatmock
# docker compose -f docker-compose.chatmock.yml --profile login \
# run --rm --service-ports chatmock-login login
# # ChatMock prints an OAuth URL. Open it in your laptop browser, sign in
# # with the ChatGPT Pro account. When the browser hits the localhost:1455
# # callback (which it can't reach on a remote VPS), copy the full URL
# # from the browser address bar and paste it back into the SSH terminal.
# # ChatMock writes refresh tokens to chatmock_data:/data and exits.
#
# Smoke test after login:
# docker exec marketplace-mainnet-chatmock wget -qO- \
# --header='content-type: application/json' \
# --post-data='{"model":"gpt-5.4","messages":[{"role":"user","content":"hi"}]}' \
# http://localhost:8000/v1/chat/completions
#
# Image is pinned to a specific version — do NOT use :latest. A `docker
# compose pull` against :latest could land a breaking upstream change while
# you're not watching, and the supplier would start emitting openai_failure
# on every claim (each one forfeits a 1 APEX supplier bond).
name: marketplace-mainnet-chatmock
services:
chatmock:
image: storagetime/chatmock:v1.35
container_name: marketplace-mainnet-chatmock
command: ["serve"]
restart: unless-stopped
environment:
CHATGPT_LOCAL_HOME: /data
PORT: "8000"
volumes:
- chatmock_data:/data
healthcheck:
test: ["CMD-SHELL", "wget -qO- http://localhost:8000/health >/dev/null || exit 1"]
interval: 20s
timeout: 5s
retries: 3
start_period: 15s
networks:
- marketplace-mainnet-net
logging:
driver: json-file
options:
max-size: "10m"
max-file: "3"
chatmock-login:
image: storagetime/chatmock:v1.35
container_name: marketplace-mainnet-chatmock-login
profiles: ["login"]
command: ["login"]
environment:
CHATGPT_LOCAL_HOME: /data
CHATGPT_LOCAL_LOGIN_BIND: 0.0.0.0
volumes:
- chatmock_data:/data
ports:
- "1455:1455"
networks:
- marketplace-mainnet-net
stdin_open: true
tty: true
volumes:
chatmock_data:
name: marketplace-mainnet-chatmock-data
networks:
marketplace-mainnet-net:
external: true
name: marketplace-mainnet-net

View File

@@ -1,15 +1,19 @@
# deploy/mainnet/docker-compose.supplier.yml — Supplier — MAINNET
# deploy/mainnet/docker-compose.supplier.yml — Supplier — MAINNET (ChatGPT/Codex backend)
#
# Mirrors the testnet supplier compose, with these differences:
# - container_name + project name use the marketplace-mainnet- prefix
# - No apex-net join: the mainnet host reaches ogmios via the public HTTPS
# endpoint (https://ogmios.vector.mainnet.apexfusion.org) supplied by
# supplier/.env — same pattern as the mainnet buyer + indexer.
# - Traefik router name + Host rule drop the `testnet.` infix
# This compose runs the mainnet supplier with LLM_BACKEND=openai pointed at
# the ChatMock localhost proxy (see docker-compose.chatmock.yml). Traefik
# routes at mp-suppliers-gpt.vector.apexfusion.org so the unsuffixed
# mp-suppliers.* slot remains free for a future supplier with a different
# backend.
#
# Pre-flight networks (must already exist):
# docker network create marketplace-mainnet-net # one-shot
# # traefik-net is created by the Traefik project
#
# Pre-flight services:
# docker compose -f docker-compose.chatmock.yml up -d chatmock
# # then run the --profile login flow once to seed OAuth tokens in
# # the chatmock_data volume — see chatmock compose header for details
name: marketplace-mainnet-supplier
@@ -24,7 +28,9 @@ services:
- path: ../../supplier/.env
required: false
environment:
OLLAMA_URL: http://marketplace-mainnet-ollama:11434
LLM_BACKEND: openai
OPENAI_BASE_URL: http://marketplace-mainnet-chatmock:8000
OPENAI_TIMEOUT_MS: "180000"
PORT: "8080"
# Enable LiveOgmiosProvider so submitTx/awaitTx actually broadcast.
# Mirrors the testnet supplier compose; without this the supplier
@@ -47,9 +53,9 @@ services:
labels:
- "traefik.enable=true"
- "traefik.docker.network=traefik-net"
- "traefik.http.routers.mp-suppliers-mainnet.entrypoints=web"
- "traefik.http.routers.mp-suppliers-mainnet.rule=Host(`mp-suppliers.vector.apexfusion.org`)"
- "traefik.http.services.mp-suppliers-mainnet.loadbalancer.server.port=8080"
- "traefik.http.routers.mp-suppliers-gpt-mainnet.entrypoints=web"
- "traefik.http.routers.mp-suppliers-gpt-mainnet.rule=Host(`mp-suppliers-gpt.vector.apexfusion.org`)"
- "traefik.http.services.mp-suppliers-gpt-mainnet.loadbalancer.server.port=8080"
logging:
driver: json-file
options: