function main() {
    let content = payload.get().body?.toObject()
    if (!content || !content.prompt) {
        return errMsg(413, '参数错误');
    }
    let data = {
        "bitoUserId": 2906,
        "ideName": "X",
        "topN": 100,
        "topNThreshold": 0.7,
        "folderPath": "",
    }
    data.prompt = content.prompt
    if (content.context) {
        // console.log(content.context)
        // "context":[{"question":"你是谁","answer":"我是一个人工智能助手"}]
        data.context = content.context
    }

    let req = {
        url: "https://staging.bito.ai/ai/v2/chat/?processSilently=true",
        method: 'POST',
        headers: {
            'Content-Type': 'application/json'
        },
    }

    switch (content.model) {
        // default:
        case 'gpt':
        case 'basic':
            req.headers.Authorization = "1536224657982906"
            data.aiModelType = 'BASIC'
            data.modelId = 0 // 0 是BASIC基础模型
            break;
        case 'claude':
        case 'claude-haiku':
            req.headers.Authorization = "1536224657982906"
            data.aiModelType = 'BASIC'
            data.modelId = 25
            break;
        case 'gpt-4o-mini':
            req.headers.Authorization = "1536224657982906"
            data.aiModelType = 'BASIC'
            data.modelId = 28
            break;
        case 'advanced':
            req.headers.Authorization = "1536224657982906"
            data.aiModelType = 'ADVANCED'
            data.modelId = 1
            break;
        case 'gpt-4o':
            req.headers.Authorization = "1536224657982906"
            data.aiModelType = 'ADVANCED'
            data.modelId = 29
            break;
        case 'claude-sonnet':
            req.headers.Authorization = "1536224657982906"
            data.aiModelType = 'ADVANCED'
            data.modelId = 33
            break;
        case 'o3-mini-medium':
            req.headers.Authorization = "1536224657982906"
            data.aiModelType = 'ADVANCED'
            data.modelId = 35
            break;
        case 'o3-mini-low':
            req.headers.Authorization = "1536224657982906"
            data.aiModelType = 'ADVANCED'
            data.modelId = 36
            break;
        case 'o3-mini-high':
            req.headers.Authorization = "1536224657982906"
            data.aiModelType = 'ADVANCED'
            data.modelId = 37
            break;
        case 'deepseek-v3':
            req.headers.Authorization = "1536224657982906"
            data.aiModelType = 'ADVANCED'
            data.modelId = 44
            break;
        case 'claude-sonnet-3-7':
            req.headers.Authorization = "1536224657982906"
            data.aiModelType = 'ADVANCED'
            data.modelId = 45
            break;
        case 'claude-sonnet-3-7-v1':
            req.headers.Authorization = "1536224657982906"
            data.aiModelType = 'ADVANCED'
            data.modelId = 46
            break;
        default:
        case 'deepseek-r1':
            content.model = 'deepseek-r1'
            data = {
                "content": content.prompt,
                "platform": "MINI_PROGRAM",
            }
            req.url = 'https://zqs.test.d-bigdata.com:49998/api/v1.0/chats/stream'
            break;
        case 'deepseek':
            data = {
                "query": content.prompt,
                "online": true
            }
            if (content.context) {
                // "context":[["你是谁","我是一个人工智能助手"]]
                data.history = content.context
            }

            req.url = 'http://498764.proxy.nscc-gz.cn:34049/llmstream/v5/chat'
            break;
        case 'hunyuan-chat':
        case 'deepseek-r1-tencent':
            req.headers.Authorization = "Bearer eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJteWZFenA3ODNLaV9KQ3g4Vm5jM1hfaXg2alpyYjZDZjVPTWtHWk1QSTNzIn0.eyJleHAiOjE3NzIwODY1OTksImlhdCI6MTc0MDU1MDYwMCwiYXV0aF90aW1lIjoxNzQwNTUwNTk5LCJqdGkiOiIwODhlODRkMi1iNjBjLTQ3MTItODZjOS0xZmMxNzU1YjgxNjMiLCJpc3MiOiJodHRwczovL2NvcGlsb3QudGVuY2VudC5jb20vYXV0aC9yZWFsbXMvY29waWxvdCIsImF1ZCI6ImFjY291bnQiLCJzdWIiOiIyYTZhNDhlMC0yN2U1LTRmYjUtODY1OS05MDQ2OWRjMjJhMTgiLCJ0eXAiOiJCZWFyZXIiLCJhenAiOiJjb25zb2xlIiwic2lkIjoiZjFkYjAzNzEtYWE5ZC00ZTExLWE4MGMtN2FiNmU2ZjhmMzMzIiwiYWNyIjoiMCIsImFsbG93ZWQtb3JpZ2lucyI6WyIqIl0sInJlYWxtX2FjY2VzcyI6eyJyb2xlcyI6WyJkZWZhdWx0LXJvbGVzIiwib2ZmbGluZV9hY2Nlc3MiLCJ1bWFfYXV0aG9yaXphdGlvbiJdfSwicmVzb3VyY2VfYWNjZXNzIjp7ImFjY291bnQiOnsicm9sZXMiOlsibWFuYWdlLWFjY291bnQiLCJtYW5hZ2UtYWNjb3VudC1saW5rcyIsInZpZXctcHJvZmlsZSJdfX0sInNjb3BlIjoib3BlbmlkIHByb2ZpbGUgb2ZmbGluZV9hY2Nlc3MgZW1haWwiLCJlbWFpbF92ZXJpZmllZCI6ZmFsc2UsIm5pY2tuYW1lIjoi5bim5bmF5bqm55qE6ZSlIiwicHJlZmVycmVkX3VzZXJuYW1lIjoiM2Q4NjdmNjMtMzVmMS00MTcxLWFkYWUtNDcxODk5YTUyOGU4LeW4puW5heW6pueahOmUpSJ9.RUolaqSO-qEKBA44X3JrccgP-wSQ1yvLPEda4r-JiNmnf9Th-DbjyP6pJ4cb38RkHi2XqMPlLJwuGJIoagOa4rBXOYqMvKHDSeIo5OxEZwEggQvu4o6PhDT_yzIOa_s1vAPGjtyOnecAq6LBg5J5Dg48wVGzL9AQ2lZDKuZ4g7jVACiFSUzS7-nRnJj3rFdsLdQ0iP9adapwcODJfXWBh0K9mWY75oo3HT2dOfy3FXHaVSMH6WA2R77PS41BLyORacBjh3MgH6U2jhVk1XWKqx8-DvVcdYoRtZ7NtcAOYeU-nJfz6bNKLAKxZ2B3mrWf0RkvSTG8yJw4xp6qATaY9w"
            req.url = "https://copilot.tencent.com/v2/chat/completions"
            data = {
                // "max_tokens": 4096,
                "messages": [
                    // {
                    //     "role": "system",
                    //     "content":""
                    // },
                    // {
                    //     "content": "你是谁",
                    //     "deletable": true,
                    //     "role": "user"
                    // },
                    // {
                    //     "content": "我是腾讯云AI代码助手，专门帮助你解决编程相关的问题。",
                    //     "deletable": true,
                    //     "role": "assistant"
                    // },
                    // {
                    //     "content": "你能做什么",
                    //     "role": "user"
                    // }
                ],
                // "msgs": [
                //     {
                //         "role": "config",
                //         "content": "",
                //         "extra": {
                //             "comment_lang": "en",
                //             "response_lang": "中文"
                //         }
                //     },
                //     {
                //         "role": "user",
                //         "content": "你是谁",
                //         "extra": {
                //             "agent": "default",
                //             "cmd": "default",
                //             "related_file": {},
                //             "context": {}
                //         },
                //         "deletable": true
                //     },
                //     {
                //         "role": "assistant",
                //         "content": "我是腾讯云AI代码助手，专门帮助你解决编程相关的问题。",
                //         "extra": {},
                //         "deletable": true
                //     },
                //     {
                //         "role": "user",
                //         "content": "你能做什么",
                //         "extra": {
                //             "agent": "default",
                //             "cmd": "default",
                //             "related_file": {},
                //             "context": {}
                //         }
                //     }
                // ],
                "stream": true,
                "model": content.model.replaceAll('-tencent', '')
            }
            if (content.context) {
                content.context.forEach((item) => {
                    data.messages.push({
                        "content": item.question,
                        "role": "user"
                    })
                    data.messages.push({
                        "content": item.answer,
                        "role": "assistant"
                    })
                })
            }
            data.messages.push({
                "content": content.prompt,
                "role": "user"
            })
            break;
        case 'grok-3':
        case 'deepseek-r1-max':
        case 'claude-3-7-sonnet':
        case 'deepseek:online':
        case 'deepseek-r1:online':
        case 'doubao-1-5-pro:online':

        case 'hunyuan-chat':
        case 'deepseek-r1-tencent':
            req.headers.Authorization = "Bearer a"
            req.headers["User-Agent"] = "Mozilla/5.0 (Windows NT 10.0; aardio; rv:37) like Gecko"
            req.url = 'https://ai.aardio.com/api/v1/chat/completions'
            data = {
                // "max_tokens": 1024000,
                "messages": [
                    // {
                    //     "content": "",
                    //     "role": "system"
                    // },
                    // {
                    //     "content": "你是谁",
                    //     "role": "user"
                    // },
                ],
                "model": content.model.replaceAll('-max', ''),
                "stream": true,
                "temperature": 0.7
            }

            // "context": [
            //     {
            //         "question": "毛泽东选集共有几卷",
            //         "answer": "毛泽东选集共有五卷。"
            //     },
            //     {
            //         "question": "第二卷的主要内容是什么",
            //         "answer": "《毛泽东选集》第二卷主要收录了毛泽东在抗日战争和解放战争时期的重要著作，集中体现了他关于中国革命的战略思想和理论。"
            //     }
            // ],
            // foreach 上下文，如果是answer则以助手身份添加，否则以用户身份添加
            if (content.context) {
                content.context.forEach((item) => {
                    data.messages.push({
                        "content": item.question,
                        "role": "user"
                    })
                    data.messages.push({
                        "content": item.answer,
                        "role": "assistant"
                    })
                })
            }
            data.messages.push({
                "content": content.prompt,
                "role": "user"
            })
            break;
    }

    response.headers.set("Cache-Control", "no-cache")
    req.data = JSON.stringify(data)

    if (content.stream) {
        response.headers.set("Content-Type", "text/event-stream; charset=utf-8;");
        response.headers.set("Connection", "keep-alive")

        switch (content.model) {
            case 'deepseek-r1':
                req.stream_call = `
                response.push('ai-reply',JSON.parse(args[0].replaceAll('data:','')).answer.content.replaceAll('\\n','<br>'))
                response.flush()
                `
                break;
            case 'deepseek':
                req.stream_call = `
                // console.log(JSON.parse(args[0].replaceAll('data:','')).data)
                response.push('ai-reply',JSON.parse(args[0].replaceAll('data:','')).data.replaceAll('\\n','<br>'))
                response.flush()
                `
                break;
            case 'grok-3':
            case 'deepseek-r1-max':
            case 'claude-3-7-sonnet':
            case 'deepseek:online':
            case 'deepseek-r1:online':
            case 'doubao-1-5-pro:online':

            case 'hunyuan-chat':
            case 'deepseek-r1-tencent':
                req.stream_call = `
                // console.log(JSON.parse(args[0].replaceAll('data:','')).choices[0].delta.content)
                let data = JSON.parse(args[0].replaceAll('data:','')).choices[0].delta
                if (data.reasoning_content) {
                response.push('ai-illation',data.reasoning_content.replaceAll('\\n','<br>'))
                }else{
                response.push('ai-reply',data.content.replaceAll('\\n','<br>'))
                }
                response.flush()
                `
                break;
            default:
                req.stream_call = `
                // console.log(JSON.parse(args[0].replaceAll('data:','')).choices[0].text)
                response.push('ai-reply',JSON.parse(args[0].replaceAll('data:','')).choices[0].text.replaceAll('\\n','<br>'))
                response.flush()
                `
        }
    } else {
        switch (content.model) {
            case 'deepseek-r1':
                req.stream_call = `
                response.write(JSON.parse(args[0].replaceAll('data:','')).answer.content)
                `
                break;
            case 'deepseek':
                req.stream_call = `
                let data = JSON.parse(args[0].replaceAll('data:','')).choices[0].delta
                if (data.reasoning_content) {
                response.write(data.reasoning_content.replaceAll('\\n','<br>'))
                }else{
                response.write(data.content.replaceAll('\\n','<br>'))
                }
                `
                break;
            case 'grok-3':
            case 'deepseek-r1-max':
            case 'claude-3-7-sonnet':
            case 'deepseek:online':
            case 'deepseek-r1:online':
            case 'doubao-1-5-pro:online':

            case 'hunyuan-chat':
            case 'deepseek-r1-tencent':
                req.stream_call = `
                let data = JSON.parse(args[0].replaceAll('data:','')).choices[0].delta
                if (data.reasoning_content) {
                response.write(data.reasoning_content.replaceAll('\\n','<br>'))
                }else{
                response.write(data.content.replaceAll('\\n','<br>'))
                }
                `
                break;
            default:
                req.stream_call = `
                response.write(JSON.parse(args[0].replaceAll('data:','')).choices[0].text)
                `
        }
    }

    // console.log(request.toCURL(req))
    request.parse(req)
    // console.log(JSON.stringify(data))

    return ''
}