Skip to content

Commit 094f2d1

Browse files
committed
Translate customer_service_client from PowerShell to Python
1 parent fcfe739 commit 094f2d1

File tree

2 files changed

+47
-34
lines changed

2 files changed

+47
-34
lines changed

samples-v2/openai_agents/customer_service/customer_service_client.ps1

Lines changed: 0 additions & 34 deletions
This file was deleted.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import argparse
2+
import requests
3+
import time
4+
import sys
5+
6+
7+
def main():
8+
parser = argparse.ArgumentParser(description='Customer Service Orchestration Client')
9+
parser.add_argument(
10+
'--start-url',
11+
default='http://localhost:7071/api/orchestrators/customer_service',
12+
help='The orchestrator start URL'
13+
)
14+
args = parser.parse_args()
15+
16+
# Start the orchestration
17+
orchestration = requests.post(args.start_url).json()
18+
19+
while True:
20+
# Wait for a prompt in the custom status
21+
while True:
22+
status = requests.get(orchestration['statusQueryGetUri']).json()
23+
24+
if status['runtimeStatus'] == 'Completed':
25+
print(f"Orchestration completed with result: {status['output']}")
26+
sys.exit(0)
27+
28+
if status['runtimeStatus'] not in ['Pending', 'Running']:
29+
raise Exception(f"Unexpected orchestration status: {status['runtimeStatus']}")
30+
31+
if status.get('customStatus') and status['customStatus'] != 'Thinking...':
32+
break
33+
34+
time.sleep(1)
35+
36+
# Prompt the user for input interactively
37+
user_input = input(status['customStatus'] + ' ')
38+
39+
# Send the user input to the orchestration as an external event
40+
event_url = orchestration['sendEventPostUri'].replace('{eventName}', 'UserInput')
41+
requests.post(event_url, json=user_input)
42+
43+
time.sleep(2)
44+
45+
46+
if __name__ == '__main__':
47+
main()

0 commit comments

Comments
 (0)