Closed lao8n closed 11 months ago
not sure what is going on above i echod allowed origins on api and it included when i sh into api container i can see that $API_ALLOW_ORIGINS is set to https://ca-web-4a73yskoiju2e.whiteground-d98c7a61.eastus.azurecontainerapps.io which matches https://ca-web-4a73yskoiju2e.whiteground-d98c7a61.eastus.azurecontainerapps.io
so it seems like console.log("onQueryCreated called" + query) const queryResponseList = await actions.queryResponseList.getQueryResponseList(query); console.log("query response returned" + queryResponseList); so i guess that queryresponselist is hanging...
and it doesn't get to this next console log
async (dispatch: Dispatch
yeah tracing through the code from infrastructure i can see what API_ALLOW_ORIGINS is there and i confirm it on sh and the url looks correct
but there in azure portal it looks like it isn't set...
now i can't even connect to the container INFO: Connecting to the container 'main'... ERROR: {"Error":{"Code":"ClusterExecEndpointWebSocketConnectionError","Message":"Failed to establish WebSocket connection with the container, error is Failed to establish WebSocket connection with Kubsernetes cluster exec endpoint, error: The server returned status code \u0027500\u0027 when status code \u0027101\u0027 was expected..","Details":null,"Target":null,"AdditionalInfo":null}}
problem seems to be that the getQueryResponseList function does not return anything... console.log("query", query.userTxt) const queryResponses = await queryService.getQueryResponseList(query);
i can see that
@app.get("/queryAi", response_model=List[QueryAiResponseBlock], response_model_by_alias=False) async def query_ai(query: Query) -> List[QueryAiResponseBlock]: print("allow origins" + app.allow_origins) print is not printing - although maybe i need to check the console logs for the api - let's check taht
so progress where now getting this error s.azurecontainerapps.io . To change or disable, go to /code/todo/app.py 2023-07-27T17:09:44.849367250Z INFO: 100.100.0.58:56644 - "OPTIONS /queryAi HTTP/1.1" 200 OK 2023-07-27T17:09:44.943170926Z INFO: 100.100.0.58:56644 - "GET /queryAi HTTP/1.1" 422 Unprocessable Entity so clearly the backend is beign called but somethign isn't quite right
o {message: 'Request failed with status code 422', name: 'AxiosError', code: 'ERR_BAD_REQUEST', config: {…}, request: XMLHttpRequest, …} code : "ERR_BAD_REQUEST" config : {transitional: {…}, transformRequest: Array(1), transformResponse: Array(1), timeout: 0, adapter: ƒ, …} message : "Request failed with status code 422" name : "AxiosError" request : XMLHttpRequest {ajaxData: null, _aiDataEvents_2_8_142_bAJ90M: {…}, onreadystatechange: null, readyState: 4, timeout: 0, …} response : {data: {…}, status: 422, statusText: '', headers: {…}, config: {…}, …}
memory sized has reduced to 0.5 cpu cores and memory size of 1Gi (from 2) although i thought i set it to 0.5
so the problem was it was being overrided somewhere else
error might be that i have set up get method which doesn't take an argument rather than a post
@app.post("/queryAi", response_model=List[QueryAiResponseBlock], response_model_by_alias=False)
async def query_ai(query: Query) -> List[QueryAiResponseBlock]:
new code to try
new error
confirmed that
API_ALLOW_ORIGINS
is set
echo $API_ALLOW_ORIGINS
https://ca-web-4a73yskoiju2e.whiteground-d98c7a61.eastus.azurecontainerapps.io
when ssh into api
which does match
so i think i might have solved that problem
error in the api backend is fastapi has no attribute allow origins - line 19..
seems like import was wrong - it is really annoying that suggested imports are now ai generated rather than based off what is actually in the code - in a language like python it becomes really unworkable
new error is didn't provide an api key openai.error.AuthenticationError: You didn't provide an API key. You need to provide your API key in an Authorization header using Bearer auth (i.e. Authorization: Bearer YOUR_KEY), or as the password field (with blank username) if you're accessing the API from your browser and are prompted for a username and password. You can obtain an API key from https://platform.openai.com/account/api-keys.
but i tried to set it here openai.api_key = settings.OPENAI_API_KEY
i can see in settings there is some code to load OPENAI_API_KEY class Settings(BaseSettings): def init(self, *args, *kwargs): super().init(args, **kwargs)
# Load secrets from keyvault
if self.AZURE_KEY_VAULT_ENDPOINT:
credential = DefaultAzureCredential()
keyvault_client = SecretClient(self.AZURE_KEY_VAULT_ENDPOINT, credential)
for secret in keyvault_client.list_properties_of_secrets():
setattr(
self,
keyvault_name_as_attr(secret.name),
keyvault_client.get_secret(secret.name).value,
)
AZURE_COSMOS_CONNECTION_STRING: str = ""
AZURE_COSMOS_DATABASE_NAME: str = "Todo"
AZURE_KEY_VAULT_ENDPOINT: Optional[str] = None
APPLICATIONINSIGHTS_CONNECTION_STRING: Optional[str] = None
APPLICATIONINSIGHTS_ROLENAME: Optional[str] = "API"
OPENAI_API_KEY: str = ""
however when i go onto key value store i can see that the open ai key is there but the value is an empty string
module keyVaultOpenAiApiKey './core/security/keyvault-secret.bicep' = { name: 'openai-api-key' scope: rg params: { keyVaultName: keyVault.outputs.name name: 'openai-api-key' secretValue: openAiApiKey } } "openAiApiKey": { "value": "${OPENAI_API_KEY}" }
so i thought i had solved the corsAcaUrl issue by passing it into allowedOrigins in app for api but have the same error as before
although admittedly this is only for the pre-flight request, where i'm getting a post request error
for the actual post request where we now have this info
2023-08-09T12:57:19.663570460Z Allowing requests from https://ca-web-4a73yskoiju2e.whiteground-d98c7a61.eastus.azurecontainerapps.io . To change or disable, go to /code/todo/app.py
so actually i think this is working okay, it is because i was using hte cnstlltn.ai website url not the azure one - i guess i need to add cnstlln.ai as a link as well
so incredibly we are now printing a response from open ai locally it isn't showing up on the web page but progress!!
i feel completley exhausted though omg hmm going to pop out to the shops but big moment nonetheless
and we actually do get something back in query responses now
thus we are getting to here in the code
appContext.dispatch({ type: ActionTypes.POST_QUERY_RESPONSE_LIST, payload: queryResponseList });
seems like we are dispatching twice so removed the dispatch above in the onQueryCreated function and instead kept the one in queryActions
in the template code the only reason they return anything is to navigate to a new page - but actually i don't need that information so there is no reason to need to return actually the dispatch should be sufficient... anyway chatgpt couldn't see anything majorily wrong so i'm adding a console log in the app reducer to see if i can debut it there
holy shit - it is being displayed just not umm in the correct font colour.. lol
seems to be only if that is the only thing being shown on the page.. not quite sure that is goning on there - so okay it is just because it takes 10s roughly for the response to be returned which is fine for now i think