Skip to content

Commit cef3c5d

Browse files
authored
Merge pull request #117 from restackio/re-act-update
Update re_act example
2 parents 74fb1a8 + 734539e commit cef3c5d

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

re_act/schedule_workflow.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ async def main():
1111
workflow_name="ParentWorkflow",
1212
workflow_id=workflow_id,
1313
input={
14-
"email": "john.doe@example.com",
15-
"current_accepted_applicants_count": 9
14+
"email": "admin@example.com",
15+
"current_accepted_applicants_count": 10
1616
}
1717
)
1818

re_act/src/functions/decide.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,25 @@ async def decide(input: DecideInput):
1919

2020
client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))
2121

22+
tools = [
23+
{
24+
"type": "function",
25+
"function": {
26+
"name": "accept_applicant",
27+
"description": "Accept the applicant",
28+
"parameters": {}
29+
}
30+
},
31+
{
32+
"type": "function",
33+
"function": {
34+
"name": "reject_applicant",
35+
"description": "Reject the applicant",
36+
"parameters": {}
37+
}
38+
}
39+
]
40+
2241
response = client.chat.completions.create(
2342
model="gpt-4o-mini",
2443
messages=[
@@ -38,17 +57,13 @@ async def decide(input: DecideInput):
3857
The maximum number of accepted applicants is: 10
3958
4059
Decide if the applicant should be accepted or rejected.
41-
Return only a JSON object with these exact fields:
42-
{{
43-
"accepted": boolean
44-
}}
4560
""",
4661
}
4762
],
48-
response_format={"type": "json_object"},
63+
tools=tools
4964
)
5065

51-
return response.choices[0].message.content
66+
return response.choices[0].message.tool_calls
5267
except Exception as e:
5368
log.error("Failed to decide", error=e)
5469
raise FunctionFailure("Failed to decide", non_retryable=True)

re_act/src/workflows/parent_workflow.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@ async def run(self, input: ParentWorkflowInput):
2828
start_to_close_timeout=timedelta(seconds=120)
2929
)
3030

31-
decision = json.loads(decide_result)["accepted"]
31+
decision = decide_result[0]['function']['name']
3232

3333
child_workflow_result = None
34-
if decision:
34+
if decision == "accept_applicant":
3535
child_workflow_result = await workflow.child_execute(
3636
ChildWorkflowA,
3737
workflow_id=f"{parent_workflow_id}-child-a",
3838
input=input.email
3939
)
40-
elif not decision:
40+
elif decision == "reject_applicant":
4141
child_workflow_result = await workflow.child_execute(
4242
ChildWorkflowB,
4343
workflow_id=f"{parent_workflow_id}-child-b",

0 commit comments

Comments
 (0)