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
8 changes: 8 additions & 0 deletions samples-v2/openai_agents/azure.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: durable-functions-openai-agents
metadata:
template: [email protected]
services:
api:
project: .
language: python
host: function
21 changes: 20 additions & 1 deletion samples-v2/openai_agents/function_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from openai import AsyncAzureOpenAI

from agents import set_default_openai_client

from order_returns.order_return_orchestrators import register_order_return_orchestrators

#region Regular Azure OpenAI setup

Expand All @@ -36,6 +36,7 @@ def get_azure_token():


app = df.DFApp(http_auth_level=func.AuthLevel.FUNCTION)
register_order_return_orchestrators(app)

@app.route(route="orchestrators/{functionName}")
@app.durable_client_input(client_name="client")
Expand All @@ -46,6 +47,24 @@ async def orchestration_starter(req: func.HttpRequest, client):
response = client.create_check_status_response(req, instance_id)
return response

@app.route(route="order_return_processor")
@app.durable_client_input(client_name="client")
async def orchestration_order_return_processor(req: func.HttpRequest, client):
# Extract input data from request body
input_data = None
try:
if req.get_body():
input_data = req.get_json()
except Exception as e:
return func.HttpResponse(
f"Invalid JSON in request body: {str(e)}",
status_code=400
)

# Starting a new orchestration instance with input data
instance_id = await client.start_new("order_return_processor", client_input=input_data)
response = client.create_check_status_response(req, instance_id)
return response

@app.orchestration_trigger(context_name="context")
@app.durable_openai_agent_orchestrator
Expand Down
12 changes: 12 additions & 0 deletions samples-v2/openai_agents/infra/abbreviations.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"cognitiveServicesAccounts": "oai-",
"dts": "dts-",
"insightsComponents": "appi-",
"managedIdentityUserAssignedIdentities": "id-",
"operationalInsightsWorkspaces": "log-",
"resourcesResourceGroups": "rg-",
"storageStorageAccounts": "st",
"taskhub": "th",
"webServerFarms": "plan-",
"webSitesFunctions": "func-"
}
38 changes: 38 additions & 0 deletions samples-v2/openai_agents/infra/app/dts.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
@description('Name of the Durable Task Scheduler')
param name string

@description('Name of the task hub')
param taskhubname string

@description('Location for the resource')
param location string

@description('Tags for the resource')
param tags object = {}

@description('IP allowlist for the scheduler')
param ipAllowlist array = ['0.0.0.0/0']

@description('SKU name')
param skuName string = 'Consumption'

resource scheduler 'Microsoft.DurableTask/schedulers@2024-10-01-preview' = {
name: name
location: location
tags: tags
properties: {
ipAllowlist: ipAllowlist
sku: {
name: skuName
}
}
}

resource taskhub 'Microsoft.DurableTask/schedulers/taskHubs@2024-10-01-preview' = {
parent: scheduler
name: taskhubname
}

output dts_ID string = scheduler.id
output dts_URL string = scheduler.properties.endpoint
output TASKHUB_NAME string = taskhub.name
Loading