Skip to content

[BUG] pf flow test --flow . --interactive for streaming promptflows with multiple outputs fails #673

@danielsc

Description

@danielsc

Describe the bug
pf flow test --flow . --interactive for streaming promptflows with multiple outputs

Session log:

=========================================
Welcome to chat flow, Template Chat Flow.
Press Enter to send your message.
You can quit with ctrl+C.
=========================================
User: Hello World!
Bot: Traceback (most recent call last):
  File "/usr/local/Caskroom/miniconda/base/envs/dash/bin/pf", line 8, in <module>
    sys.exit(main())
  File "/usr/local/Caskroom/miniconda/base/envs/dash/lib/python3.10/site-packages/promptflow/_cli/_pf/entry.py", line 93, in main
    entry(command_args)
  File "/usr/local/Caskroom/miniconda/base/envs/dash/lib/python3.10/site-packages/promptflow/_cli/_pf/entry.py", line 75, in entry
    raise ex
  File "/usr/local/Caskroom/miniconda/base/envs/dash/lib/python3.10/site-packages/promptflow/_cli/_pf/entry.py", line 59, in entry
    dispatch_flow_commands(args)
  File "/usr/local/Caskroom/miniconda/base/envs/dash/lib/python3.10/site-packages/promptflow/_cli/_pf/_flow.py", line 60, in dispatch_flow_commands
    test_flow(args)
  File "/usr/local/Caskroom/miniconda/base/envs/dash/lib/python3.10/site-packages/promptflow/_cli/_utils.py", line 363, in wrapper
    raise e
  File "/usr/local/Caskroom/miniconda/base/envs/dash/lib/python3.10/site-packages/promptflow/_cli/_utils.py", line 351, in wrapper
    return func(*args, **kwargs)
  File "/usr/local/Caskroom/miniconda/base/envs/dash/lib/python3.10/site-packages/promptflow/_cli/_pf/_flow.py", line 336, in test_flow
    pf_client.flows._chat(
  File "/usr/local/Caskroom/miniconda/base/envs/dash/lib/python3.10/site-packages/promptflow/_sdk/operations/_flow_operations.py", line 183, in _chat
    submitter._chat_flow(
  File "/usr/local/Caskroom/miniconda/base/envs/dash/lib/python3.10/site-packages/promptflow/_sdk/operations/_test_submitter.py", line 301, in _chat_flow
    print_chat_output(flow_result.output[output_name])
  File "/usr/local/Caskroom/miniconda/base/envs/dash/lib/python3.10/site-packages/promptflow/_sdk/operations/_test_submitter.py", line 227, in print_chat_output
    for event in get_result_output(output):
  File "/usr/local/Caskroom/miniconda/base/envs/dash/lib/python3.10/site-packages/promptflow/_sdk/operations/_test_submitter.py", line 241, in get_result_output
    proxy = output.gi_frame.f_locals["proxy"]
KeyError: 'proxy'

How To Reproduce the bug
Create a PF with the following flow.dag.yaml:

id: template_chat_flow
name: Template Chat Flow
environment:
  python_requirements_txt: requirements.txt
inputs:
  chat_history:
    type: list
    is_chat_history: true
  question:
    type: string
    is_chat_input: true
outputs:
  answer:
    type: string
    reference: ${stream.output.answer}
    is_chat_output: true
nodes:
- name: stream
  type: python
  source:
    type: code
    path: stream.py
  inputs:
    chat_history: ${inputs.chat_history}
    question: ${inputs.question}

And the following stream.py:

from promptflow import tool
from typing import Generator

def stream(question: str) -> Generator[str, None, None]:
  for word in question:
    yield word

@tool
def my_python_tool(chat_history: list[dict], question: str) -> dict:
  return {"answer": stream(question)}

Run:
pf flow test --flow . --interactive

You are prompted to enter the user's message, the you get the above error.

Expected behavior
No error

Running Information(please complete the following information):

  • Promptflow Package Version using pf -v: 0.1.0b7.post1
  • Operating System: MacOS 13.5.2 (22G91)
  • Python Version using python --version: Python 3.10.12

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions