yazinsai / srt-ai

Translate SRT files to any language, using AI magic ✨
https://translatesrt.com/
193 stars 50 forks source link

Support for Azure OpenAI Service (AOAI) #24

Open doggy8088 opened 7 months ago

doggy8088 commented 7 months ago

The endpoint between Azure OpenAI Service (AOAI) and OpenAI API has a little bit different, but the API spec are the same.

Just change app/api/route.ts file from:

  const response = await fetch("https://api.openai.com/v1/chat/completions", {
    headers: {
      "Content-Type": "application/json",
      Authorization: `Bearer ${process.env.OPENAI_API_KEY}`,
    },
    method: "POST",
    body: JSON.stringify({
      model: "gpt-3.5-turbo-0125",

to


  const response = await fetch(`https://${YOUR_RESOURCE_NAME}.openai.azure.com/openai/deployments/${YOUR_DEPLOYMENT_NAME}/chat/completions?api-version=2023-05-15`, {
    headers: {
      "Content-Type": "application/json",
      "api-key": `${process.env.OPENAI_API_KEY}`,
    },
    method: "POST",
    body: JSON.stringify({
      model: "gpt-35-turbo",

See also: Azure OpenAI Service REST API reference - Azure OpenAI | Microsoft Learn