obsidianmd / obsidian-clipper

Highlight and capture the web in your favorite browser. The official Web Clipper extension for Obsidian.
https://obsidian.md/clipper
MIT License
1.1k stars 62 forks source link

BUG: The Interpreter does not allow the use of Azure OpenAI models when add a new model. #214

Open gilbertoolimpio opened 3 days ago

gilbertoolimpio commented 3 days ago

Version (please complete the following information):

Describe the bug

When I go to the Interpreter and try to insert a new model, I provide all the details of my model hosted on Azure OpenAI. However, when running the extension, the following error occurs even though all the information is correct (as verified via request in Postman).

{   
    "Azure error":  
    { 
        "statusCode": 401, 
        "message": "Unauthorized. Access token is missing, invalid, audience is incorrect (https://cognitiveservices.azure.com), or have expired." 
    }
}

Expected behavior

The request is executed successfully.

URLs where the bug occurs

All URL.

To reproduce

Steps to reproduce the behavior:

  1. Go to Interpreter in the extension options.
  2. Click on Add Model.
  3. Add the model information hosted on Azure OpenAI.
  4. Execute on any page.
  5. Error:
    {   
    "Azure error":  
    { 
        "statusCode": 401, 
        "message": "Unauthorized. Access token is missing, invalid, audience is incorrect (https://cognitiveservices.azure.com), or have expired." 
    }
    }

Your template file N/A

Additional Information As can be seen in the Azure OpenAI API documentation, there are two types of authentication, as follows:

  1. API Key authentication: For this type of authentication, all API requests must include the API Key in the api-key HTTP header.

  2. Microsoft Entra ID authentication: You can authenticate an API call using a Microsoft Entra token. Authentication tokens are included in a request as the Authorization header. The token provided must be preceded by Bearer, for example, Bearer YOUR_AUTH_TOKEN.

For the case 1 (mostly common?), the extension fails, causing the previously mentioned error due to a request problem that only uses Authorization: Bearer ... and don't validade if needs use api-key instead of Authorization

A proposed solution (implemented locally and validated functionality) would be to identify through a regex to validate the URL in the pattern openai.azure.com.

If you are interested, I can open a PR for this solution.

elzik commented 2 days ago

I am seeing the same problem with my Azure OpenAI model.