How jun-howie/erniebot-openai-api works
Project Type and Purpose
• Type: A lightweight Python microservice that exposes an OpenAI-compatible HTTP API and proxies requests to the Baidu ERNIE Bot platform.
• Purpose:
– Accept incoming POST requests on /v1/chat/completions.
– Translate them into ERNIE Bot SDK calls (streaming or non-streaming).
– Return ERNIE Bot responses in OpenAI-style JSON.
– Run standalone (via python erniebot-openai-api.py) or as a Docker container.
File Structure
• Dockerfile – builds a containerized version of the Python service.
• erniebot-openai-api.py – main script: loads env vars, spins up HTTP server (Flask/FastAPI/uvicorn), defines endpoint logic.
• requirements.txt – lists runtime dependencies (web framework, ERNIE Bot agent SDK, etc.).
• README.md – usage instructions, environment variables (EB_AGENT_ACCESS_TOKEN, EB_AGENT_LOGGING_LEVEL), curl examples, Docker run commands.
Key Components
a. Client(s)
– Examples: curl, front-end app, or any OpenAI-compatible client library.
b. API Proxy Service
– Container/Host running erniebot-openai-api.py.
• HTTP Server (FastAPI/Flask + Uvicorn/Gunicorn)
• Request Handler (endpoint logic)
• ERNIE Bot Agent SDK client module
• Configuration loader (reads EB_AGENT_ACCESS_TOKEN, logging level, port)
c. External Service
– Baidu ERNIE Bot endpoint (e.g., https://api.ernie-bot.baidu.com).
– Show as an external “AI Inference” service.
d. Docker / Deployment
– Illustrate the Docker container as the deployment unit around the API Proxy Service.
– Indicate port mapping (8000:8000).
Relationships & Data Flows
– HTTP POST /v1/chat/completions (JSON payload).
– Function call / HTTP request to ERNIE Bot (with streaming or not).
– Response stream or JSON.
– HTTP response (OpenAI-style JSON or streaming chunks).
Architectural Patterns & Principles
• Single‐responsibility microservice: only handles HTTP translation and proxying.
• Configuration via environment variables for 12-factor compliance.
• Containerization for consistent deployment.
• Optional streaming data flow: highlight chunked response path.
Technologies & Frameworks
• Python 3.10
• FastAPI or Flask (whichever erniebot-openai-api.py uses)
• ERNIE Bot Agent SDK (from requirements.txt)
• Uvicorn/Gunicorn (WSGI/ASGI server)
• Docker