我現在想將Workers AI的api在第三方web ui上使用，我想部屬可以將Workers AI的api接口轉化為Openai api格式的base url，之後我只要在類似lobehub這樣的web ui上，填入base url和api和模型名字就能使用，我應該怎麼寫這個網站代碼呢？
註解：網站我會部屬在Cloudflare Workers上。
註解：這是Workers AI相容於Openai的文件說明

Use AI Gateway for analytics, caching, and security on requests to Workers AI.
REST API

To interact with a REST API, update the URL used for your request:

    Previous: https://api.cloudflare.com/client/v4/accounts/{account_id}/ai/run/{model_id}
    New: https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/workers-ai/{model_id}

For these parameters:

    {account_id} is your Cloudflare account ID.
    {gateway_id} refers to the name of your existing AI Gateway.
    {model_id} refers to the model ID of the Workers AI model.

Examples

First, generate an API token with Workers AI Read access and use it in your request.
Request to Workers AI llama model

curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/workers-ai/@cf/meta/llama-3.1-8b-instruct \
 --header 'Authorization: Bearer {cf_api_token}' \
 --header 'Content-Type: application/json' \
 --data '{"prompt": "What is Cloudflare?"}'

Request to Workers AI text classification model

curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/workers-ai/@cf/huggingface/distilbert-sst-2-int8 \
  --header 'Authorization: Bearer {cf_api_token}' \
  --header 'Content-Type: application/json' \
  --data '{ "text": "Cloudflare docs are amazing!" }'

OpenAI compatible endpoints

Workers AI supports OpenAI compatible endpoints for text generation (/v1/chat/completions) and text embedding models (/v1/embeddings). This allows you to use the same code as you would for your OpenAI commands, but swap in Workers AI easily.

Request to OpenAI compatible endpoint

curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/workers-ai/v1/chat/completions \
 --header 'Authorization: Bearer {cf_api_token}' \
 --header 'Content-Type: application/json' \
 --data '{
      "model": "@cf/meta/llama-3.1-8b-instruct",
      "messages": [
        {
          "role": "user",
          "content": "What is Cloudflare?"
        }
      ]
    }
'

Worker

To include an AI Gateway within your Worker, add the gateway as an object in your Workers AI request.

export interface Env {
  AI: Ai;
}

export default {
  async fetch(request: Request, env: Env): Promise<Response> {
    const response = await env.AI.run(
      "@cf/meta/llama-3.1-8b-instruct",
      {
        prompt: "Why should you use Cloudflare for your AI inference?",
      },
      {
        gateway: {
          id: "{gateway_id}",
          skipCache: false,
          cacheTtl: 3360,
        },
      },
    );
    return new Response(JSON.stringify(response));
  },
} satisfies ExportedHandler<Env>;

Workers AI supports the following parameters for AI gateways:

    id string
        Name of your existing AI Gateway. Must be in the same account as your Worker.
    skipCache boolean(default: false)
        Controls whether the request should skip the cache.
    cacheTtl number
        Controls the Cache TTL.

*******************************************************

以下這是我部屬在cloudflare Workers的代碼，但是他顯示"error": "AI Gateway responded with 400: {\"success\":false,\"result\":[],\"messages\":[],\"error\":[{\"code\":2008,\"message\":\"Invalid provider\"}]}",
請問要怎麼修改，請將完整代碼一次列出，因為我是新手，我不會局部修改


// 配置部分：請替換為您的實際值
const ACCOUNT_ID = 'your_account_id' // 請替換為您的實際賬戶 ID
const API_TOKEN = 'your_api_token' // 請替換為您的實際 API 令牌
const AI_GATEWAY_ID = 'your_ai_gateway_id' // 請替換為您的 AI Gateway ID

// 構建 AI Gateway URL
const AI_GATEWAY_URL = `https://gateway.ai.cloudflare.com/v1/${ACCOUNT_ID}/${AI_GATEWAY_ID}`

addEventListener('fetch', event => {
  event.respondWith(handleRequest(event.request))
})

async function handleRequest(request) {
  console.log('Received request:', request.url)

  // 處理 CORS 預檢請求
  if (request.method === "OPTIONS") {
    return handleCORS(request)
  }

  // 獲取請求的路徑和方法
  const url = new URL(request.url)
  const path = url.pathname
  const method = request.method

  // 處理所有 POST 請求
  if (method === 'POST') {
    try {
      const body = await request.json()

      // 確保模型名稱格式正確
      if (body.model && !body.model.startsWith('@cf/')) {
        body.model = '@cf/' + body.model
      }

      console.log('Sending request to AI Gateway:', JSON.stringify(body))

      // 發送請求到 AI Gateway，保持原始路徑
      const gatewayResponse = await fetch(`${AI_GATEWAY_URL}${path}`, {
        method: 'POST',
        headers: {
          'Authorization': `Bearer ${API_TOKEN}`,
          'Content-Type': 'application/json',
        },
        body: JSON.stringify(body)
      })

      if (!gatewayResponse.ok) {
        const errorText = await gatewayResponse.text()
        console.error('AI Gateway Error:', errorText)
        throw new Error(`AI Gateway responded with ${gatewayResponse.status}: ${errorText}`)
      }

      // 獲取 AI Gateway 的響應
      const gatewayResult = await gatewayResponse.json()

      console.log('Received response from AI Gateway:', JSON.stringify(gatewayResult))

      // 直接返回 AI Gateway 的響應
      return new Response(JSON.stringify(gatewayResult), {
        headers: { 
          'Content-Type': 'application/json',
          'Access-Control-Allow-Origin': '*',
          'Access-Control-Allow-Methods': 'POST, OPTIONS',
          'Access-Control-Allow-Headers': 'Content-Type, Authorization',
        }
      })

    } catch (error) {
      console.error('Error:', error)
      return new Response(JSON.stringify({ error: error.message }), {
        status: 500,
        headers: { 
          'Content-Type': 'application/json',
          'Access-Control-Allow-Origin': '*',
        }
      })
    }
  }

  // 對於其他請求，返回 404
  return new Response('Not Found', { status: 404 })
}

// 處理 CORS 預檢請求的函數
function handleCORS(request) {
  return new Response(null, {
    headers: {
      'Access-Control-Allow-Origin': '*',
      'Access-Control-Allow-Methods': 'POST, OPTIONS',
      'Access-Control-Allow-Headers': 'Content-Type, Authorization',
    }
  })
}