Open PandaWhoCodes opened 2 months ago
Have you tried importing,
from azurefunctions.extensions.http.fastapi import Request, StreamingResponse
source code is here at Azure/azurefunctions-extensions-http-fastapi
and it is relying on wrapper in the azurefunctions.extensions.base
module, instead of just reusing fastapi
natives classes like you did.
I am also interested in the answer to the original question, as I had trouble running the samples for the beta extension, see https://github.com/Azure/azure-functions-python-worker/discussions/1349#discussioncomment-10084283
StreamingResponse in fastapi is not working
This issue is for a: (mark with an
x
)Minimal steps to reproduce
@app.post("/api/stream") async def chat_completion_stream(request): try: return StreamingResponse( generate_sensor_data(), media_type="text/event-stream" ) except Exception as e: logger.error(f"Error in chat_completion: {str(e)}", exc_info=True) raise HTTPException(status_code=500, detail=str(e)) from e
[2024-06-24T18:18:55.183Z] Worker failed to index functions [2024-06-24T18:18:55.185Z] Result: Failure Exception: FunctionLoadError: cannot load the http_app_func function: 'req' binding type "httpTrigger" and dataType "None" in function.json do not match the corresponding function parameter's Python type annotation "HttpRequest" Stack: File "C:\Users\ashis\AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin\workers\python\3.11\WINDOWS\X64\azure_functions_worker\dispatcher.py", line 413, in _handle__functions_metadata_request self.load_function_metadata( File "C:\Users\ashis\AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin\workers\python\3.11\WINDOWS\X64\azure_functions_worker\dispatcher.py", line 393, in load_function_metadata
self.index_functions(function_path, function_app_directory)) \ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ashis\AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin\workers\python\3.11\WINDOWS\X64\azure_functions_worker\dispatcher.py", line 773, in index_functions loader.process_indexed_function( File "C:\Users\ashis\AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin\workers\python\3.11\WINDOWS\X64\azure_functions_worker\loader.py", line 139, in process_indexed_function function_info = functions_registry.add_indexed_function( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ashis\AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin\workers\python\3.11\WINDOWS\X64\azure_functions_worker\functions.py", line 450, in add_indexed_function deferred_bindings_enabled) = self.validate_function_params( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ashis\AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin\workers\python\3.11\WINDOWS\X64\azure_functions_worker\functions.py", line 243, in validate_function_params
raise FunctionLoadError(