Skip to content
Merged
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
8 changes: 8 additions & 0 deletions .github/workflows/python-sample-app-s3-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,11 @@ jobs:
working-directory: lambda-layer/sample-apps
run: aws s3api put-object --bucket ${{ secrets.APP_SIGNALS_E2E_EC2_JAR }}-prod-${{ matrix.aws-region }} --body ./build/function.zip --key pyfunction.zip

- name: Build Gen AI Sample App Zip
working-directory: sample-apps/python/genai_service
run: zip -r python-gen-ai-sample-app.zip .

- name: Upload Gen AI Sample App to S3
working-directory: sample-apps/python/genai_service
run: aws s3api put-object --bucket ${{ secrets.APP_SIGNALS_E2E_EC2_JAR }}-prod-${{ matrix.aws-region }} --body ./python-gen-ai-sample-app.zip --key python-gen-ai-sample-app.zip

11 changes: 10 additions & 1 deletion sample-apps/python/genai_service/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
from langchain_aws import ChatBedrock
from langchain.prompts import ChatPromptTemplate
from langchain.chains import LLMChain
from opentelemetry import trace
from opentelemetry import trace, metrics
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor, ConsoleSpanExporter
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from openinference.instrumentation.langchain import LangChainInstrumentor
import random

# Load environment variables
load_dotenv()
Expand Down Expand Up @@ -92,7 +93,15 @@ async def chat(request: ChatRequest):
"""
Chat endpoint that processes a single user message through AWS Bedrock
"""

try:
# Emit OTel Metrics
meter = metrics.get_meter("genesis-meter", "1.0.0")
request_duration = meter.create_histogram(
name="Genesis_TestMetrics", description="Genesis request duration", unit="s"
)
request_duration.record(0.1 + (0.5 * random.random()), {"method": "GET", "status": "200"})

# Process the input through the chain
result = await chain.ainvoke({"input": request.message})
return ChatResponse(response=result["text"])
Expand Down
Loading