diff --git a/samples/python/azureai-streaming/Dockerfile b/samples/python/azureai-streaming/Dockerfile new file mode 100644 index 00000000..3b79eb1b --- /dev/null +++ b/samples/python/azureai-streaming/Dockerfile @@ -0,0 +1,36 @@ +# Use Python 3.11 slim image as base (compatible with the requirement for Python 3.9+) +FROM python:3.11-slim + +# Set working directory +WORKDIR /app + +# Set environment variables +ENV PYTHONPATH=/app +ENV PYTHONUNBUFFERED=1 + +# Install system dependencies if needed +RUN apt-get update && apt-get install -y \ + gcc \ + && rm -rf /var/lib/apt/lists/* + +# Copy requirements file +COPY requirements.txt . + +# Install Python dependencies +RUN pip install --no-cache-dir -r requirements.txt + +# Copy source code +COPY src/ ./src/ + +# Copy environment file +COPY .env . + +# Create a non-root user for security +RUN useradd -m -u 1000 appuser && chown -R appuser:appuser /app +USER appuser + +# Expose the port the app runs on +EXPOSE 8088 + +# Run the application +CMD ["python", "-m", "src.main"] \ No newline at end of file diff --git a/samples/python/azureai-streaming/src/agent.py b/samples/python/azureai-streaming/src/agent.py index 474adb92..36b30171 100644 --- a/samples/python/azureai-streaming/src/agent.py +++ b/samples/python/azureai-streaming/src/agent.py @@ -43,7 +43,8 @@ CLIENT = AsyncAzureOpenAI( api_version=environ["AZURE_OPENAI_API_VERSION"], azure_endpoint=environ["AZURE_OPENAI_ENDPOINT"], - azure_ad_token_provider=token_provider + api_key=environ["AZURE_OPENAI_API_KEY"] if "AZURE_OPENAI_API_KEY" in environ else None, + # azure_ad_token_provider=token_provider ) @AGENT_APP.conversation_update("membersAdded") @@ -75,7 +76,7 @@ async def on_poem_message(context: TurnContext, _state: TurnState): context.streaming_response.queue_informative_update("Starting a poem...\n") streamed_response = await CLIENT.chat.completions.create( - model="gpt-4o", + model=environ["AZURE_OPENAI_CHAT_DEPLOYMENT_NAME"] if "AZURE_OPENAI_CHAT_DEPLOYMENT_NAME" in environ else "gpt-4o-mini", messages=[ {"role": "system", "content": """You are a creative assistant who has deeply studied Greek and Roman Gods, You also know all of the Percy Jackson Series You write poems about the Greek Gods as they are depicted in the Percy Jackson books. diff --git a/samples/python/azureai-streaming/src/start_server.py b/samples/python/azureai-streaming/src/start_server.py index 3cf731d3..103d7c9a 100644 --- a/samples/python/azureai-streaming/src/start_server.py +++ b/samples/python/azureai-streaming/src/start_server.py @@ -19,13 +19,21 @@ async def entry_point(req: Request) -> Response: adapter, ) + async def liveness_check(req: Request) -> Response: + return Response(text="OK", status=200) + + async def readiness_check(req: Request) -> Response: + return Response(text="OK", status=200) + APP = Application(middlewares=[jwt_authorization_middleware]) APP.router.add_post("/api/messages", entry_point) + APP.router.add_get("/liveness", liveness_check) + APP.router.add_get("/readiness", readiness_check) APP["agent_configuration"] = auth_configuration APP["agent_app"] = agent_application APP["adapter"] = agent_application.adapter try: - run_app(APP, host="localhost", port=environ.get("PORT", 3978)) + run_app(APP, host="0.0.0.0", port=environ.get("PORT", 8088)) except Exception as error: raise error diff --git a/samples/python/quickstart/Dockerfile b/samples/python/quickstart/Dockerfile new file mode 100644 index 00000000..3b79eb1b --- /dev/null +++ b/samples/python/quickstart/Dockerfile @@ -0,0 +1,36 @@ +# Use Python 3.11 slim image as base (compatible with the requirement for Python 3.9+) +FROM python:3.11-slim + +# Set working directory +WORKDIR /app + +# Set environment variables +ENV PYTHONPATH=/app +ENV PYTHONUNBUFFERED=1 + +# Install system dependencies if needed +RUN apt-get update && apt-get install -y \ + gcc \ + && rm -rf /var/lib/apt/lists/* + +# Copy requirements file +COPY requirements.txt . + +# Install Python dependencies +RUN pip install --no-cache-dir -r requirements.txt + +# Copy source code +COPY src/ ./src/ + +# Copy environment file +COPY .env . + +# Create a non-root user for security +RUN useradd -m -u 1000 appuser && chown -R appuser:appuser /app +USER appuser + +# Expose the port the app runs on +EXPOSE 8088 + +# Run the application +CMD ["python", "-m", "src.main"] \ No newline at end of file diff --git a/samples/python/quickstart/src/start_server.py b/samples/python/quickstart/src/start_server.py index d76b619e..c8dd33ca 100644 --- a/samples/python/quickstart/src/start_server.py +++ b/samples/python/quickstart/src/start_server.py @@ -20,13 +20,21 @@ async def entry_point(req: Request) -> Response: adapter, ) + async def liveness_check(req: Request) -> Response: + return Response(text="OK", status=200) + + async def readiness_check(req: Request) -> Response: + return Response(text="OK", status=200) + APP = Application(middlewares=[jwt_authorization_middleware]) APP.router.add_post("/api/messages", entry_point) + APP.router.add_get("/liveness", liveness_check) + APP.router.add_get("/readiness", readiness_check) APP["agent_configuration"] = auth_configuration APP["agent_app"] = agent_application APP["adapter"] = agent_application.adapter try: - run_app(APP, host="localhost", port=environ.get("PORT", 3978)) + run_app(APP, host="0.0.0.0", port=environ.get("PORT", 8088)) except Exception as error: raise error