Skip to content

Commit 260a5ca

Browse files
Allow the prompt request to specify the prompt ID. (Comfy-Org#8189)
This makes it easier to write asynchronous clients that submit requests, because they can store the task immediately. Duplicate prompt IDs are rejected by the job queue.
1 parent 861c3bb commit 260a5ca

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

script_examples/websockets_api_example.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
server_address = "127.0.0.1:8188"
1111
client_id = str(uuid.uuid4())
1212

13-
def queue_prompt(prompt):
14-
p = {"prompt": prompt, "client_id": client_id}
13+
def queue_prompt(prompt, prompt_id):
14+
p = {"prompt": prompt, "client_id": client_id, "prompt_id": prompt_id}
1515
data = json.dumps(p).encode('utf-8')
16-
req = urllib.request.Request("http://{}/prompt".format(server_address), data=data)
17-
return json.loads(urllib.request.urlopen(req).read())
16+
req = urllib.request.Request("http://{}/prompt".format(server_address), data=data)
17+
urllib.request.urlopen(req).read()
1818

1919
def get_image(filename, subfolder, folder_type):
2020
data = {"filename": filename, "subfolder": subfolder, "type": folder_type}
@@ -27,7 +27,8 @@ def get_history(prompt_id):
2727
return json.loads(response.read())
2828

2929
def get_images(ws, prompt):
30-
prompt_id = queue_prompt(prompt)['prompt_id']
30+
prompt_id = str(uuid.uuid4())
31+
queue_prompt(prompt, prompt_id)
3132
output_images = {}
3233
while True:
3334
out = ws.recv()

server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ async def post_prompt(request):
678678

679679
if "prompt" in json_data:
680680
prompt = json_data["prompt"]
681-
prompt_id = str(uuid.uuid4())
681+
prompt_id = str(json_data.get("prompt_id", uuid.uuid4()))
682682
valid = await execution.validate_prompt(prompt_id, prompt)
683683
extra_data = {}
684684
if "extra_data" in json_data:

0 commit comments

Comments
 (0)