azure-search-openai-demo
azure-search-openai-demo copied to clipboard
Docker build not working
I was trying to run the backend in docker container by supplying configuration vie ENVs. I used following dockerfile
# backend build
FROM python:3.11 AS backend-build
COPY backend /app/backend
WORKDIR /app/backend
RUN pip install -r requirements.txt
EXPOSE 5000
CMD ["python", "-m", "quart", "--app", "main:app", "run", "--host", "0.0.0.0", "--reload"]
### This issue is for a: (mark with an `x`)
I was able to run the container locally & access the UI at http://localhost:5000/ , But when I try to ask question, it failed to respond with following error
Error: The app encountered an error processing your request.
If you are an administrator of the app, view the full error in the logs. See aka.ms/appservice-logs for more information.
Error type: <class 'azure.core.exceptions.ClientAuthenticationError'>
Noticed following error in container
[2024-02-16 14:11:03 +0000] [1] [INFO] 192.168.65.1:22545 GET /config 1.1 - - 2237
INFO:azure.core.pipeline.policies.http_logging_policy:Request URL: 'http://169.254.169.254/metadata/identity/oauth2/token?api-version=REDACTED&resource=REDACTED'
Request method: 'GET'
Request headers:
'User-Agent': 'azsdk-python-identity/1.15.0 Python/3.11.8 (Linux-6.6.12-linuxkit-aarch64-with-glibc2.36)'
No body was attached to the request
ERROR:root:Exception while generating response stream: DefaultAzureCredential failed to retrieve a token from the included credentials.
Attempted credentials:
EnvironmentCredential: EnvironmentCredential authentication unavailable. Environment variables are not fully configured.
Visit https://aka.ms/azsdk/python/identity/environmentcredential/troubleshoot to troubleshoot this issue.
ManagedIdentityCredential: ManagedIdentityCredential authentication unavailable, no response from the IMDS endpoint.
AzureCliCredential: Azure CLI not found on path
AzurePowerShellCredential: PowerShell is not installed
AzureDeveloperCliCredential: Azure Developer CLI could not be found. Please visit https://aka.ms/azure-dev for installation instructions and then,once installed, authenticate to your Azure account using 'azd auth login'.
To mitigate this issue, please refer to the troubleshooting guidelines here at https://aka.ms/azsdk/python/identity/defaultazurecredential/troubleshoot.
Traceback (most recent call last):
File "/app/backend/app.py", line 150, in format_as_ndjson
async for event in r:
File "/app/backend/approaches/chatapproach.py", line 149, in run_with_streaming
extra_info, chat_coroutine = await self.run_until_final_call(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/backend/approaches/chatreadretrieveread.py", line 132, in run_until_final_call
chat_completion: ChatCompletion = await self.openai_client.chat.completions.create(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/openai/resources/chat/completions.py", line 1322, in create
return await self._post(
^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/openai/_base_client.py", line 1705, in post
return await self.request(cast_to, opts, stream=stream, stream_cls=stream_cls)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/openai/_base_client.py", line 1408, in request
return await self._request(
^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/openai/_base_client.py", line 1426, in _request
await self._prepare_options(options)
File "/usr/local/lib/python3.11/site-packages/openai/lib/azure.py", line 518, in _prepare_options
azure_ad_token = await self._get_azure_ad_token()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/openai/lib/azure.py", line 504, in _get_azure_ad_token
token = await token
^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/azure/identity/aio/_bearer_token_provider.py", line 44, in wrapper
await policy.on_request(request)
File "/usr/local/lib/python3.11/site-packages/azure/core/pipeline/policies/_authentication_async.py", line 70, in on_request
self._token = await await_result(self._credential.get_token, *self._scopes)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/azure/core/pipeline/_tools_async.py", line 58, in await_result
return await result
^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/azure/identity/aio/_credentials/default.py", line 201, in get_token
token = await super().get_token(*scopes, claims=claims, tenant_id=tenant_id, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/azure/identity/aio/_credentials/chained.py", line 107, in get_token
raise ClientAuthenticationError(message=message)
azure.core.exceptions.ClientAuthenticationError: DefaultAzureCredential failed to retrieve a token from the included credentials.
Attempted credentials:
EnvironmentCredential: EnvironmentCredential authentication unavailable. Environment variables are not fully configured.
Visit https://aka.ms/azsdk/python/identity/environmentcredential/troubleshoot to troubleshoot this issue.
ManagedIdentityCredential: ManagedIdentityCredential authentication unavailable, no response from the IMDS endpoint.
AzureCliCredential: Azure CLI not found on path
AzurePowerShellCredential: PowerShell is not installed
AzureDeveloperCliCredential: Azure Developer CLI could not be found. Please visit https://aka.ms/azure-dev for installation instructions and then,once installed, authenticate to your Azure account using 'azd auth login'.
To mitigate this issue, please refer to the troubleshooting guidelines here at https://aka.ms/azsdk/python/identity/defaultazurecredential/troubleshoot.
[2024-02-16 14:11:07 +0000] [1] [INFO] 192.168.65.1:22545 POST /chat 1.1 200 - 2141509
[2024-02-16 14:11:07 +0000] [1] [INFO] 192.168.65.1:22545 POST /chat 1.1 - - 2141983
Any help on this ?
Unfortunately, it is very difficult to use Azure credentials inside a Docker container. See the long discussion here: https://github.com/Azure/azure-sdk-for-net/issues/19167 (That's about .NET SDK, but the same holds true for the Python SDK)
I typically have to resort to key-based authentication in that situation. You would need to modify the code in app.py that constructs AzureOpenAI and SearchClient to pass in a key credential instead.
I want to deploy Chatbot App using Terraform, If I supply all ENVs would that work ?
You would need to convert our Bicep to Terraform to create all the appropriate resources. That would presumably work, I haven't had the time to try it myself. Check infra/ to find all the Bicep files.