Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions samples/python/azureai-streaming/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
5 changes: 3 additions & 2 deletions samples/python/azureai-streaming/src/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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.
Expand Down
10 changes: 9 additions & 1 deletion samples/python/azureai-streaming/src/start_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
36 changes: 36 additions & 0 deletions samples/python/quickstart/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
10 changes: 9 additions & 1 deletion samples/python/quickstart/src/start_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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