diff --git a/examples/openai-server/dataflow.yml b/examples/openai-server/dataflow.yml index 6b4efdce5..4941df1ae 100644 --- a/examples/openai-server/dataflow.yml +++ b/examples/openai-server/dataflow.yml @@ -5,7 +5,7 @@ nodes: outputs: - v1/chat/completions inputs: - echo: dora-echo/echo + v1/chat/completions: dora-echo/echo - id: dora-echo build: pip install -e ../../node-hub/dora-echo diff --git a/node-hub/dora-openai-server/dora_openai_server/main.py b/node-hub/dora-openai-server/dora_openai_server/main.py index fa2d90f26..115d37ed5 100644 --- a/node-hub/dora-openai-server/dora_openai_server/main.py +++ b/node-hub/dora-openai-server/dora_openai_server/main.py @@ -68,13 +68,17 @@ async def create_chat_completion(request: ChatCompletionRequest): node.send_output("v1/chat/completions", data) # Wait for response from dora-echo - event = node.next(timeout=DORA_RESPONSE_TIMEOUT) - if event["type"] == "ERROR": - print("Timedout") - response_str = "No response received" - else: - response = event["value"] - response_str = response[0].as_py() if response else "No response received" + while True: + event = node.next(timeout=DORA_RESPONSE_TIMEOUT) + if event["type"] == "ERROR": + response_str = "No response received. Err: " + event["value"][0].as_py() + break + elif event["type"] == "INPUT" and event["id"] == "v1/chat/completions": + response = event["value"] + response_str = response[0].as_py() if response else "No response received" + break + else: + pass return ChatCompletionResponse( id="chatcmpl-1234",