nikdanilov / whisper-obsidian-plugin

Speech-to-text in Obsidian using OpenAI Whisper
MIT License
227 stars 31 forks source link

No 'Access-Control-Allow-Origin' header is present on the requested resource. #49

Open FilJed opened 9 months ago

FilJed commented 9 months ago

Hi!

I have my own openai compatible endpoint that works fine in all my programs i.e. in python:

import openai
client = openai.OpenAI(
    api_key="my-key",
    base_url="http://***.111:80/v1"
)
with open("./tracks/test.ogg", "rb") as audio_file:
    transcript = client.audio.transcriptions.create(
        file = audio_file,
        model = "whisper-1",
        response_format="srt",
    )
print(transcript)

So endpoint works fine.

But when I try to put it as API_URL I keep getting network error message in logs

Access to XMLHttpRequest at 'http://***111/v1/audio/transcriptions' from origin 'app://obsidian.md' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Thing that confuses me is the error message contain no port info. Is it normal?

I've tried putting all cersions:

I saw in other issues (i.e. https://github.com/nikdanilov/whisper-obsidian-plugin/issues/2) that changing endpoint works well. What I'm doing wrong?

JungeWerther commented 1 month ago

Yeah thanks, this solved my issue. If your custom openai compatible endpoint is in nodeJS, for example, add CORS to your response headers like:

new Response(
    JSON.stringify(data),
    { headers: { 
      "Content-Type": "application/json",
      "Access-Control-Allow-Origin": "*", // or specify a particular origin
     } })

might make a difference.