Skip to content

Commit 90d390b

Browse files
committed
Extract invoke_model_activity to a separate file
1 parent 0add9aa commit 90d390b

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed
Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import azure.functions as func
2-
from agents import ModelResponse
32
from model_invoker import ModelInvoker, ActivityModelInput
43
from durable_decorators import durable_openai_agent_orchestrator
4+
from model_activity import create_invoke_model_activity
55

66

77
app = func.FunctionApp(http_auth_level=func.AuthLevel.FUNCTION)
88

9+
# TODO: Can we hide this line?
10+
create_invoke_model_activity(app)
11+
912

1013
@app.route(route="orchestrators/{functionName}")
1114
@app.durable_client_input(client_name="client")
@@ -22,14 +25,3 @@ def basic_hello_world_orchestrator(context):
2225
from basic.hello_world import main
2326
result = main()
2427
return result
25-
26-
27-
@app.activity_trigger(input_name="input")
28-
async def invoke_model_activity(input: str):
29-
activity_input = ActivityModelInput.from_json(input)
30-
31-
model_invoker = ModelInvoker()
32-
result = await model_invoker.invoke_model_activity(activity_input)
33-
34-
json_obj = ModelResponse.__pydantic_serializer__.to_json(result)
35-
return json_obj.decode()
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import azure.functions as func
2+
from agents import ModelResponse
3+
from model_invoker import ModelInvoker, ActivityModelInput
4+
5+
6+
def create_invoke_model_activity(app: func.FunctionApp):
7+
"""Create and register the invoke_model_activity function with the provided FunctionApp."""
8+
9+
@app.activity_trigger(input_name="input")
10+
async def invoke_model_activity(input: str):
11+
activity_input = ActivityModelInput.from_json(input)
12+
13+
model_invoker = ModelInvoker()
14+
result = await model_invoker.invoke_model_activity(activity_input)
15+
16+
json_obj = ModelResponse.__pydantic_serializer__.to_json(result)
17+
return json_obj.decode()
18+
19+
return invoke_model_activity

0 commit comments

Comments
 (0)