promptflow icon indicating copy to clipboard operation
promptflow copied to clipboard

[BUG] pf flow serve is broken in promptflow==1.10.0 (NotADirectoryError)

Open asos-oliverfrost opened this issue 9 months ago • 3 comments

Clearly state that you are going to take on implementing it, if that's the case. You can request that the issue be assigned to you.

I'm happy to implement this seems straightforward (possible solution provided below, please confirm if this is the expected behaviour)

Describe the bug

Serving the interactive chat UI appears to have broken. Flask app 'promptflow.core._serving.app' does not start successfully, resulting in an exception and the local app server doesn't open in a browser.

How To Reproduce the bug

Using the following flow.dag.yaml:

$schema: https://azuremlschemas.azureedge.net/promptflow/latest/Flow.schema.json
inputs:
  question:
    type: string
    is_chat_input: true
nodes:
- name: parrot
  type: python
  source:
    type: code
    path: ./parrot.py
  inputs:
    question: ${inputs.question}
outputs:
  answer:
    type: string
    reference: ${parrot.output}
    is_chat_output: true

and parrot.py (both files in the same source directory):

from promptflow.core import tool

@tool
def print_hi(question: str):
    return question.upper()

To reproduce the error, run any of the following pf commands below:

pf flow serve --source ./
pf flow serve --source .
pf flow serve --source flow.dag.yaml

Exception raised:

  File "/Users/oliver.frost/.pyenv/versions/3.11.4/lib/python3.11/site-packages/promptflow/_sdk/_utils/serve_utils.py", line 112, in serve_python_flow
    os.chdir(flow_dir)
NotADirectoryError: [Errno 20] Not a directory: '/Users/oliver.frost/PycharmProjects/pf-bug-example/flow.dag.yaml'

Issue resolves when you adjust _resolve_python_flow_additional_includes() to return the parent of the source instead, included below:

def _resolve_python_flow_additional_includes(source) -> Path:
    # Resolve flow additional includes
    from promptflow.client import load_flow

    flow = load_flow(source)
    from promptflow._sdk.operations import FlowOperations

    with FlowOperations._resolve_additional_includes(flow.path) as resolved_flow_path:
        if resolved_flow_path == flow.path:
            # HERE
            return source.parent

Expected behavior

Flask app 'promptflow.core._serving.app' serves successfully and a browser window opens:

Screenshot 2024-04-28 at 09 56 54

Screenshots

Screenshot 2024-04-28 at 09 48 59 Above: the reproducible example in PyCharm. Screenshot 2024-04-28 at 09 54 00 ^ above: same error reproduced in Python 3.9.x

Running Information(please complete the following information):

  • Promptflow == 1.10.0
  • Operating System: Mac OS X 14.4.1 (23E224)
  • Python Version 3.11.4

asos-oliverfrost avatar Apr 28 '24 08:04 asos-oliverfrost

@asos-oliverfrost Thanks for reporting this! We will fix this asap in the postfix 1.10.1.

brynn-code avatar Apr 29 '24 10:04 brynn-code

Thanks for the reply! I was hoping to take a crack at this, as we've worked a lot with promptflow and I was hoping to become more active as a contributor :)

asos-oliverfrost avatar Apr 29 '24 10:04 asos-oliverfrost

Haha, thank you, we are fixing this here #3070 because this related to some code refine works not so long ago, and this breaks 1.10.0 so it's a little hurry to ship the fix in 1.10.1, I believe you've been our contributor by reporting this, really appreciate it, and contribute code changes will not be too far for you 😆, thanks again. @asos-oliverfrost

brynn-code avatar Apr 30 '24 01:04 brynn-code