package comm import ( "os" "strconv" "strings" ) // 测试服锁:AI 能力只许走科大讯飞 SparkChain 这一套,不许再去调微软、阿里、字节、谷歌、灵犀。 // // 开关只认环境变量 AI_ONLY_IFLYTEK=1。正式服不设这个变量,解析和调用都跟原来一样。 // 存储、短信、实名、支付、MCP、应用参数不在这把锁里。 // // 允许的服务 id 只有 SparkChain 这一族。同是讯飞的 AIUI、老的 ntrans 听写不在里面。 const ( svcCatSTT int32 = 1 svcCatTTS int32 = 2 svcCatLLM int32 = 5 svcCatSTS int32 = 7 svcCatASRFile int32 = 8 svcCatLLMVision int32 = 9 ) var aiVendorCats = map[int32]bool{ svcCatSTT: true, svcCatTTS: true, SvcCatMT: true, SvcCatAST: true, svcCatLLM: true, svcCatSTS: true, svcCatASRFile: true, svcCatLLMVision: true, } var iflytekAiSvcIDs = map[string]bool{ "sparkchain": true, "mt_iflytek": true, "asrfile_iflytek": true, "llm_iflytek": true, } // AiOnlyIflytek 当前进程是不是「AI 只许讯飞」的测试服。 func AiOnlyIflytek() bool { switch strings.ToLower(strings.TrimSpace(os.Getenv("AI_ONLY_IFLYTEK"))) { case "1", "true", "yes", "on": return true default: return false } } // IflytekAiSvc 是不是这次允许的科大讯飞服务。 func IflytekAiSvc(id, provider string) bool { if strings.ToLower(strings.TrimSpace(provider)) != "iflytek" { return false } return iflytekAiSvcIDs[strings.TrimSpace(id)] } // AiVendorBlocked 锁开着、而且这是一家别的 AI 服务时返回 true。调用方应整条跳过,不要发请求。 func AiVendorBlocked(id, provider, categories string) bool { if !AiOnlyIflytek() || !categoriesHaveAI(categories) { return false } return !IflytekAiSvc(id, provider) } func categoriesHaveAI(categories string) bool { for _, p := range strings.Split(categories, ",") { v, err := strconv.Atoi(strings.TrimSpace(p)) if err != nil { continue } if aiVendorCats[int32(v)] { return true } } return false }