Restore cmd/server/, cmd/openai-worker/, cmd/grok-worker/ that were accidentally excluded during initial copy.
43 lines
1.1 KiB
Go
43 lines
1.1 KiB
Go
package main
|
||
|
||
import (
|
||
"os"
|
||
|
||
"github.com/gin-gonic/gin"
|
||
"github.com/xiaolajiaoyyds/regplatformm/internal/worker"
|
||
)
|
||
|
||
func main() {
|
||
port := os.Getenv("PORT")
|
||
if port == "" {
|
||
port = "7860" // HuggingFace 默认端口
|
||
}
|
||
|
||
gin.SetMode(gin.ReleaseMode)
|
||
r := gin.Default()
|
||
|
||
// 处理端点 — 带并发限流(超限返回 503,CF Worker 自动转发下一节点)
|
||
handler := []gin.HandlerFunc{worker.ConcurrencyLimiter(), worker.OpenAIProtocolRegisterHandler}
|
||
r.POST("/api/v1/process", handler...)
|
||
// 兼容 VPS 直连隧道域名(不经过 CF Worker 路由重写时路径为 /openai/process)
|
||
r.POST("/openai/process", handler...)
|
||
|
||
// 健康检查(精简响应,仅暴露 CF Worker 需要的最小字段)
|
||
r.GET("/health", func(c *gin.Context) {
|
||
c.JSON(200, gin.H{"status": "ok", "concurrency": worker.ConcurrencyStats()})
|
||
})
|
||
|
||
// 根路径
|
||
r.GET("/", func(c *gin.Context) {
|
||
c.JSON(200, gin.H{
|
||
"model": "distilbert-base-uncased",
|
||
"task": "text-classification",
|
||
"framework": "onnxruntime",
|
||
"version": "1.2.0",
|
||
"status": "ready",
|
||
})
|
||
})
|
||
|
||
r.Run(":" + port)
|
||
}
|