openai-python icon indicating copy to clipboard operation
openai-python copied to clipboard

Add https:// prefix to azure_endpoint when missing

Open daravi opened this issue 9 months ago • 2 comments

Add https:// prefix to azure_endpoint when missing to avoid faulty URL construction where azure_endpoint is repeated twice

  • [x] I understand that this repository is auto-generated and my pull request may not be merged

Changes being requested

Please either apply this change to add https:// prefix to azure_endpoint or throw exception when it is missing. Otherwise the https client will create a weird URL like

<azure-ai-service-name>.cognitiveservices.azure.com/openai/<azure-ai-service-name>.cognitiveservices.azure.com/openai/deployments/<deployment-name>/chat/completions

Since host is not correctly parsed and set on the base URL.

Additional context & links

daravi avatar Mar 06 '25 11:03 daravi

@daravi can you share the scenario where an endpoint wouldn't already have https://? I think all places I've seen where you can copy the endpoint value e.g. from the Azure portal, CLI, etc. will always include it.

kristapratico avatar Mar 12 '25 17:03 kristapratico

@kristapratico I mistakenly did not include https when running and was surprised that such URL was constructed:

https://<azure-ai-service-name>.cognitiveservices.azure.com/openai/<azure-ai-service-name>.cognitiveservices.azure.com/openai/deployments/<deployment-name>/chat/completions

If we don't want to add it we can also throw an exception if endpoint format is not correctly having https.

Just a suggestion. Since it happened to me I figured it may happen to others as well.

daravi avatar Mar 18 '25 18:03 daravi

@daravi Your situation makes sense! I think a loud warning would be more suitable than a hard-coded https requirement. Locally run services might not be https -- I don't want to be attempting to predict what the user might need. My recommendation would be to print a warning and continue code execution.

Since you were in this situation recently - what was the outcome behavior? Was there an exception thrown down the line, or did things hang indefinitely?

mikhail avatar May 06 '25 19:05 mikhail