Azure-Samples / azure-search-openai-demo

A sample app for the Retrieval-Augmented Generation pattern running in Azure, using Azure AI Search for retrieval and Azure OpenAI large language models to power ChatGPT-style and Q&A experiences.
https://azure.microsoft.com/products/search
MIT License
5.93k stars 4.07k forks source link

Frontend: http proxy error at /auth_setup, local changes are not reflected on hot reload. #1374

Open Arvoid00 opened 6 months ago

Arvoid00 commented 6 months ago

Please provide us with the following information:

This issue is for a: (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

Follow local development instructions in documentation.

Any log messages given by the failure

Backend

Starting backend

  • Serving Quart app 'app'
    • Debug mode: False
    • Please use an ASGI server (e.g. Hypercorn) directly in production
    • Running on http://localhost:50505 (CTRL + C to quit) INFO:azure.identity.aio._credentials.environment:Incomplete environment configuration for EnvironmentCredential. These variables are set: AZURE_TENANT_ID INFO:azure.identity.aio._credentials.managed_identity:ManagedIdentityCredential will use IMDS

Frontend

frontend@0.0.0 dev vite

VITE v4.5.2 ready in 296 ms

➜ Local: http://localhost:5173/ ➜ Network: use --host to expose ➜ press h to show help 14:49:24 [vite] http proxy error at /auth_setup: Error: connect ECONNREFUSED ::1:50505 at TCPConnectWrap.afterConnect [as oncomplete]

localhost:50505/auth_setup

{
"loginRequest": {
"scopes": [
".default"
]
},
"msalConfig": {
"auth": {
"authority": "https://login.microsoftonline.com/<redacted>",
"clientId": "<redacted>",
"navigateToLoginRequestUrl": false,
"postLogoutRedirectUri": "[/](http://localhost:50505/)",
"redirectUri": "[/redirect](http://localhost:50505/redirect)"
},
"cache": {
"cacheLocation": "localStorage",
"storeAuthStateInCookie": false
}
},
"requireAccessControl": true,
"tokenRequest": {
"scopes": [
"api://<redacted>/access_as_user"
]
},
"useLogin": true
}

Vite config:

server: {
        proxy: {
            "/content/": "http://localhost:50505",
            "/auth_setup": "http://localhost:50505",
            "/.auth/me": "http://localhost:50505",
            "/ask": "http://localhost:50505",
            "/chat": "http://localhost:50505",
            "/config": "http://localhost:50505"
        }
    }

Expected/desired behavior

I want the local changes to be reflected on hot reload, and I am also wondering what the proxy error is about

OS and Version?

Windows 10. Using Powershell 7+

azd version?

azd version 1.6.1 (commit eba2c978b5443fdb002c95add4011d9e63c2e76f)

Versions

Mention any other details that might be useful

Git repo up to date on commit Improvements to load balancer setup script


Thanks! We'll be in touch soon.

pamelafox commented 6 months ago

I saw that today, and it was because my backend server wasn't ready. Did you wait until the backend server was fully up?

Arvoid00 commented 6 months ago

Thank you for the quick reply. I waited for the following message:

[2024-03-06 18:44:02 +0100] [24940] [INFO] Running on http://127.0.0.1:50505 (CTRL + C to quit) INFO:hypercorn.error:Running on http://127.0.0.1:50505 (CTRL + C to quit)

Then started the frontend, but sadly the same error occurs. Inspecting the Chrome Dev Console:

GET http://localhost:5173/auth_setup net::ERR_ABORTED 500 (Internal Server Error) authConfig.ts:56 Uncaught Error: auth setup response was not ok: 500 at fetchAuthSetup (authConfig.ts:56:15) at async authConfig.ts:61:19

EDIT: The localhost:5173 page also stays blank, aside from the error in the console. EDIT2: I can use the :50505 endpoints like normal, and also ask the GPT questions etc, but the hot reloading of the frontend changes do not apply. I can see that the frontend page reloads/recompiles in the logs, but no changes occur on the :50505 endpoints.

Do you perhaps have any other suggestions or information I could provide? Also, could it be cookies/sessions conflicting in some way?

Thanks in advance!

pamelafox commented 6 months ago

Okay, and you dont see any error logs when you switch back over to the Python logs? And you dont accidentally have two servers running on 50505? (Which shouldnt be possible.. but just trying to figure out whats happening.)

Arvoid00 commented 6 months ago

Hi, I just tried again. I am sure only one server instance is running. (nothing to route to when server is off) There are no Python logs when navigating to localhost:5173 and receiving the 500 in Chrome Dev tools.

See below:

Initial startup logs:

Starting backend

  • Serving Quart app 'app'
  • Debug mode: False
  • Please use an ASGI server (e.g. Hypercorn) directly in production
  • Running on http://localhost:50505 (CTRL + C to quit) INFO:azure.identity.aio._credentials.environment:Incomplete environment configuration for EnvironmentCredential. These variables are set: AZURE_TENANT_ID INFO:azure.identity.aio._credentials.managed_identity:ManagedIdentityCredential will use IMDS 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.12.2 (Windows-11-10.0.22631-SP0)' No body was attached to the request INFO:azure.identity.aio._credentials.chained:DefaultAzureCredential acquired a token from AzureCliCredential INFO:azure.core.pipeline.policies.http_logging_policy:Request URL: 'https://gptkb-qt36li4qprbtw.search.windows.net/indexes('gptkbindex')?api-version=REDACTED' Request method: 'GET' Request headers: 'Accept': 'application/json' 'x-ms-client-request-id': '0c6d87bf-dbef-11ee-abc7-7404f1de83e4' 'User-Agent': 'azsdk-python-search-documents/11.6.0b1 Python/3.12.2 (Windows-11-10.0.22631-SP0)' 'Authorization': 'REDACTED' No body was attached to the request INFO:azure.core.pipeline.policies.http_logging_policy:Response status: 200 Response headers: 'Transfer-Encoding': 'chunked' 'Content-Type': 'application/json; odata.metadata=minimal; odata.streaming=true; charset=utf-8' 'Content-Encoding': 'REDACTED' 'Etag': '"0x8DC3DC0DBC736FB"' 'Vary': 'REDACTED' 'Server': 'Microsoft-IIS/10.0' 'Strict-Transport-Security': 'REDACTED' 'Preference-Applied': 'REDACTED' 'OData-Version': 'REDACTED' 'request-id': '0c6d87bf-dbef-11ee-abc7-7404f1de83e4' 'elapsed-time': 'REDACTED' 'Strict-Transport-Security': 'REDACTED' 'Date': 'Wed, 06 Mar 2024 19:23:46 GMT' ERROR:asyncio:Unclosed client session client_session: <aiohttp.client.ClientSession object at 0x0000018D816FBAD0> ERROR:asyncio:Unclosed connector connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0x0000018D816FE930>, 463979.859)]'] connector: <aiohttp.connector.TCPConnector object at 0x0000018D816FB200> [2024-03-06 20:23:47 +0100] [5756] [INFO] Running on http://127.0.0.1:50505 (CTRL + C to quit) INFO:hypercorn.error:Running on http://127.0.0.1:50505 (CTRL + C to quit)

Then after doing a chat request once:

Startup

[2024-03-06 20:23:47 +0100] [5756] [INFO] Running on http://127.0.0.1:50505 (CTRL + C to quit) INFO:hypercorn.error:Running on http://127.0.0.1:50505 (CTRL + C to quit)

First request to localhost:50505

[2024-03-06 20:26:21 +0100] [5756] [INFO] 127.0.0.1:59674 GET /auth_setup 1.1 200 492 0 [2024-03-06 20:26:21 +0100] [5756] [INFO] 127.0.0.1:59674 GET /auth_setup 1.1 - - 0 [2024-03-06 20:26:21 +0100] [5756] [INFO] 127.0.0.1:59674 GET /.auth/refresh 1.1 404 207 0 [2024-03-06 20:26:21 +0100] [5756] [INFO] 127.0.0.1:59674 GET /.auth/refresh 1.1 - - 0 [2024-03-06 20:26:21 +0100] [5756] [INFO] 127.0.0.1:59674 GET /config 1.1 200 84 0 [2024-03-06 20:26:21 +0100] [5756] [INFO] 127.0.0.1:59674 GET /config 1.1 - - 8172

Send chat request

INFO:httpx:HTTP Request: POST https://api.openai.com/v1/chat/completions "HTTP/1.1 200 OK" INFO:httpx:HTTP Request: POST https://api.openai.com/v1/embeddings "HTTP/1.1 200 OK" INFO:azure.identity.aio._internal.decorators:AzureCliCredential.get_token succeeded INFO:azure.core.pipeline.policies.http_logging_policy:Request URL: 'https://gptkb-qt36li4qprbtw.search.windows.net/indexes('gptkbindex')/docs/search.post.search?api-version=REDACTED' Request method: 'POST' Request headers: 'Content-Type': 'application/json' 'Content-Length': '34778' 'Accept': 'application/json' 'x-ms-client-request-id': '81712552-dbef-11ee-a3d8-7404f1de83e4' 'User-Agent': 'azsdk-python-search-documents/11.6.0b1 Python/3.12.2 (Windows-11-10.0.22631-SP0)' 'Authorization': 'REDACTED' A body is sent with the request INFO:azure.core.pipeline.policies.http_logging_policy:Response status: 200 Response headers: 'Transfer-Encoding': 'chunked' 'Content-Type': 'application/json; odata.metadata=minimal; odata.streaming=true; charset=utf-8' 'Content-Encoding': 'REDACTED' 'Vary': 'REDACTED' 'Server': 'Microsoft-IIS/10.0' 'Strict-Transport-Security': 'REDACTED' 'Preference-Applied': 'REDACTED' 'OData-Version': 'REDACTED' 'request-id': '81712552-dbef-11ee-a3d8-7404f1de83e4' 'elapsed-time': 'REDACTED' 'Strict-Transport-Security': 'REDACTED' 'Date': 'Wed, 06 Mar 2024 19:27:03 GMT' INFO:httpx:HTTP Request: POST https://api.openai.com/v1/chat/completions "HTTP/1.1 200 OK" [2024-03-06 20:27:06 +0100] [5756] [INFO] 127.0.0.1:59708 POST /chat 1.1 200 - 8711932 [2024-03-06 20:27:06 +0100] [5756] [INFO] 127.0.0.1:59708 POST /chat 1.1 - - 8711932

Could it be related to Azure Client App Registration not allowing http://127.0.0.1:50505/redirect as a valid parameter, but only http://localhost:50505/redirect? I had a similar auth redirect error in the chat application on chat response earlier (eg the gpt answer returned an error stating an URL mismatch. Replacing the IP with localhost resolved that issue).

image

Arvoid00 commented 6 months ago

In the startup logs for the backend I do see the following:

ERROR:asyncio:Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x0000018D816FBAD0>
ERROR:asyncio:Unclosed connector
connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0x0000018D816FE930>, 463979.859)]']
connector: <aiohttp.connector.TCPConnector object at 0x0000018D816FB200>

Is that an error that is expected?

pamelafox commented 6 months ago

No, I saw that as well and wondered if that might be contributing to the issue. Is your code changed at all from what's in main?

Here's what I see:

 * Serving Quart app 'app'
 * Debug mode: False
 * Please use an ASGI server (e.g. Hypercorn) directly in production
 * Running on http://127.0.0.1:50505 (CTRL + C to quit)
INFO:azure.identity.aio._credentials.environment:Incomplete environment configuration for EnvironmentCredential. These variables are set: AZURE_TENANT_ID
INFO:azure.identity.aio._credentials.managed_identity:ManagedIdentityCredential will use IMDS
[2024-03-06 19:52:18 +0000] [51511] [INFO] Running on http://127.0.0.1:50505 (CTRL + C to quit)
INFO:hypercorn.error:Running on http://127.0.0.1:50505 (CTRL + C to quit)
Arvoid00 commented 6 months ago

I would have to check what the diffs are between upstream and my fork. I think most edits are related to text translations, data and prepdocs. EDIT: Just checked, no diffs related to routing, auth or anything related.

However, I just tested that changing the vite.config.ts to 127.0.0.1 instead of localhost does in fact render the page and does reload the page on save with the new changes. It also returns some error in the console:

image

And now I have no problem with vite refusing the /auth_config route

image

I encountered this issue on SO, talking about node17 and vite favouring ipv4 and ipv6 over localhost. Also see this note in the vite docs

DeepAsmani commented 6 months ago

[2024-03-06 20:26:21 +0100] [5756] [INFO] 127.0.0.1:59674 GET /auth_setup 1.1 200 492 0 [2024-03-06 20:26:21 +0100] [5756] [INFO] 127.0.0.1:59674 GET /auth_setup 1.1 - - 0 [2024-03-06 20:26:21 +0100] [5756] [INFO] 127.0.0.1:59674 GET /.auth/refresh 1.1 404 207 0 [2024-03-06 20:26:21 +0100] [5756] [INFO] 127.0.0.1:59674 GET /.auth/refresh 1.1 - - 0 [2024-03-06 20:26:21 +0100] [5756] [INFO] 127.0.0.1:59674 GET /config 1.1 200 84 0 [2024-03-06 20:26:21 +0100] [5756] [INFO] 127.0.0.1:59674 GET /config 1.1 - - 8172

in i got error in 404 for .auth/refresh

pamelafox commented 6 months ago

A 404 for .auth/refresh is fine and expected in local development with auth disabled.

pamelafox commented 6 months ago

@Arvoid00 So you're using Node 17? I'm still in 16 so that might explain discrepancies.

Arvoid00 commented 6 months ago

@pamelafox I am using Node version 18.19.1 (latest stable v18 I think?), so that would indeed differ. I just tested v16 and both 127.0.01 and localhost in vite config work correctly with the node version 16.20.2. Also double checked by reverting back to v18 and localhost. This returns the error again. The error is resolved once the config is set to 127.0.0.1. It seems like error is introduced in v17 or v18 by node "reordering the result of DNS-resolved addresses by default" as stated in the vite docs.

In any case, 127.0.0.1 works fine on both versions.