Closed DuboisABB closed 2 months ago
The last time that I saw this error pop up, it was in the azure-search-openai-demo: https://github.com/Azure-Samples/azure-search-openai-demo/issues/1215
The cause there was a "key" that was actually an Entra token that was incredibly long for some reason.
In this repo, this is the relevant code, in service_setup.py, that generates the token:
api_key = azure_credential.get_token("https://cognitiveservices.azure.com/.default").token
openai_config = {
"api_type": "azure",
"api_base": f"https://{os.environ['AZURE_OPENAI_SERVICE']}.openai.azure.com",
"api_key": api_key,
"api_version": "2024-02-15-preview",
"deployment": os.environ["AZURE_OPENAI_EVAL_DEPLOYMENT"],
"model": os.environ["OPENAI_GPT_MODEL"],
}
You could print the length of api_key value there and see if it is very long. Could you report back what length you see?
Thanks for the pointer. I added a log of the length, looks like it's 9719, which indeed looks excessively long.
(evalenv) PS C:\Programming\ai-rag-chat-evaluator> python -m scripts generate --output=example_input/qa.jsonl --numquestions=10 --persource=5
[08:46:28] INFO Using Azure OpenAI Service with Azure Developer CLI Credential service_setup.py:54
[08:46:29] INFO API Key Len: 9719 service_setup.py:57
INFO Using Azure Search Service with Azure Developer CLI Credential service_setup.py:84
INFO Generating 10 questions total, 5 per source, based on search results generate.py:23
However, thanks to your hint, I added AZURE_OPENAI_KEY and AZURE_SEARCH_KEY to my .env file. Look like I somehow need to enable key based access however, I'll look into it.
File "C:\Programming\ai-rag-chat-evaluator\evalenv\Lib\site-packages\openai\_base_client.py", line 1041, in _request
raise self._make_status_error_from_response(err.response) from None
openai.PermissionDeniedError: Error code: 403 - {'error': {'code': 'AuthenticationTypeDisabled', 'message': 'Key based authentication is disabled for this resource.'}}
Yes, we disable key-based access by default in the azure-search-openai-demo infra, here: https://github.com/Azure-Samples/azure-search-openai-demo/blob/7b55ad2b4cb4911141a69963a230ee79fd2f2b41/infra/main.bicep#L403 You can set to false and re-run "azd provision".
But I'll investigate why your token might be so long and ask the Generative SDK to use the token provider route.
I've filed this issue for QADataGenerator: https://github.com/Azure/azure-sdk-for-python/issues/37050
Thanks again. I set all 3 instances of disableLocalAuth to false: openAi, documentIntelligence (probably not needed) and searchService. I also upgraded azure-search-openai-demo to the latest version and set AZURE_DISABLE_APP_SERVICES_AUTHENTICATION to false. No more openAI error but then I got an unauthorized error for search.
I remembered that I had went into the portal to the search instance to change API Access Control from RBAC only to Both (API keys + RBAC) but running azd up had reset that. I changed it again to both and it finally works.
I then asked copilot for the required change to search-services.bicep to make that change permanent and it came up with this change:
param authOptions object = {
aadOrApiKey: {
aadAuthFailureMode: 'http401WithBearerChallenge' // or 'http403'
}
}
It seem to work. After azd up the API access control setting is still set to Both.
Thanks Pamela for your support. Next time will be to make evaluate work but the authentication is more tricky. I'll update in #97
This issue is for a: (mark with an
x
)Minimal steps to reproduce
Follow the setup instructions azd auth login python -m scripts generate --output=example_input/qa.jsonl --numquestions=10 --persource=5
Any log messages given by the failure
Expected/desired behavior
No error.