Skip to content

Latest commit

 

History

History
134 lines (105 loc) · 4.5 KB

File metadata and controls

134 lines (105 loc) · 4.5 KB

MiroFish — OpenRouter Setup (Our Working Config)

How to run MiroFish with OpenRouter instead of Alibaba Bailian.

Why OpenRouter?

  • No Chinese cloud account needed
  • Access to 200+ models (Qwen, GPT, Claude, Gemini, Llama)
  • Pay-per-token, no subscription
  • Same OpenAI-compatible API format

Required Patches

MiroFish needs 4 patches to work with OpenRouter because:

  1. Qwen3 models output <think> reasoning tags — need stripping
  2. response_format: json_object — not supported on OpenRouter for all models
  3. OpenRouter requires extra headers (HTTP-Referer, X-Title)
  4. Python integer conversion limit — Qwen3 can return very large numbers

Patched Files

All patches are in the patches/ subfolder:

File What Changed
llm_client.py Strips think tags, skips response_format for OpenRouter, adds headers
oasis_profile_generator.py Removes response_format, adds think-tag stripping
simulation_config_generator.py Same as above
run.py Sets sys.set_int_max_str_digits(100000)
frontend/src/api/index.js Changes baseURL from localhost:5001 to empty (uses Vite proxy)

.env Configuration

# LLM — OpenRouter with Qwen
LLM_API_KEY=sk-or-v1-your-openrouter-key
LLM_BASE_URL=https://openrouter.ai/api/v1
LLM_MODEL_NAME=qwen/qwen3-30b-a3b

# Zep Cloud (same as original)
ZEP_API_KEY=z_your-zep-key

# Optional boost model (even faster)
LLM_BOOST_API_KEY=sk-or-v1-your-openrouter-key
LLM_BOOST_BASE_URL=https://openrouter.ai/api/v1
LLM_BOOST_MODEL_NAME=qwen/qwen3-30b-a3b

Recommended Models (OpenRouter)

Model ID Speed Quality Cost/1M tokens
qwen/qwen3-30b-a3b Fast Good $0.30
qwen/qwen3-235b-a22b Slow Best $1.50
qwen/qwen2.5-72b-instruct Medium Great $0.50
google/gemini-2.5-flash Very fast Great $0.10
google/gemini-2.0-flash-001 Very fast Good $0.05

Recommendation: qwen/qwen3-30b-a3b for best speed/quality/cost ratio.

Docker Deployment with Patches

# docker-compose.yml
services:
  mirofish:
    image: ghcr.io/666ghj/mirofish:latest
    container_name: mirofish
    env_file:
      - .env
    ports:
      - "3000:3000"
      - "5001:5001"
    restart: unless-stopped
    volumes:
      - ./backend/uploads:/app/backend/uploads
      - ./backend/app/utils/llm_client.py:/app/backend/app/utils/llm_client.py
      - ./backend/app/services/oasis_profile_generator.py:/app/backend/app/services/oasis_profile_generator.py
      - ./backend/app/services/simulation_config_generator.py:/app/backend/app/services/simulation_config_generator.py
      - ./backend/run.py:/app/backend/run.py
      - ./frontend/src/api/index.js:/app/frontend/src/api/index.js

Remote Access Fix

When accessing the UI remotely (not localhost), the frontend API calls fail because they go to localhost:5001 which is YOUR machine, not the server.

The index.js patch changes baseURL to empty string, making all API calls go through the Vite proxy on port 3000, which forwards /api/* to localhost:5001 inside the container.

Full Setup (Server)

# 1. Clone MiroFish
git clone https://github.com/666ghj/MiroFish.git
cd MiroFish

# 2. Create .env
cat > .env << 'EOF'
LLM_API_KEY=sk-or-v1-YOUR_KEY
LLM_BASE_URL=https://openrouter.ai/api/v1
LLM_MODEL_NAME=qwen/qwen3-30b-a3b
ZEP_API_KEY=z_YOUR_ZEP_KEY
EOF

# 3. Copy patches
cp setup-guide/patches/llm_client.py backend/app/utils/llm_client.py
cp setup-guide/patches/oasis_profile_generator.py backend/app/services/oasis_profile_generator.py
cp setup-guide/patches/simulation_config_generator.py backend/app/services/simulation_config_generator.py
cp setup-guide/patches/run.py backend/run.py
mkdir -p frontend/src/api/
cp setup-guide/patches/index.js frontend/src/api/index.js
cp setup-guide/patches/docker-compose.yml docker-compose.yml

# 4. Start
docker compose pull
docker compose up -d

# 5. Verify
curl http://localhost:3000  # Frontend
curl http://localhost:5001/healthz  # Backend (should return ".")

Costs Per Simulation (OpenRouter)

Phase Calls Cost (30B) Cost (235B)
Ontology Generation 1 $0.01 $0.05
Graph Building (Zep) 0 $0 $0
Profile Generation (93 agents) ~93 $0.10 $0.80
Config Generation (7 batches) ~10 $0.05 $0.30
Simulation (72 rounds x 93 agents) ~6,600 $0.50 $3.00
Report Generation ~10 $0.05 $0.30
Total ~$0.70 ~$4.45