https://promptfoo.dev/ logo
trying to get promptfoo progress bar using python ...
# ❓|questions
a
This isn't critical to get done but it would make testing locally a lot nicer. I'm running promptfoo from a python subprocess and I don't know how to print the progress bar. I'm using various solutions from here: https://stackoverflow.com/questions/2715847/read-streaming-input-from-subprocess-communicate/17698359#17698359 for ex:
Copy code
py
        with subprocess.Popen(
                ["promptfoo", "eval", "-o", "output.json", "--no-table"], stdout=subprocess.PIPE,
                stderr=subprocess.PIPE,
                text=True, encoding="utf-8", shell=True, bufsize=1, universal_newlines=True) as eval_result:
            for line in eval_result.stdout:
                print(line, end='')
I've tried variations as well, but all I'm seeing is the end result.
Copy code
cmd
Writing output to output.json
======================================================================
✔ Evaluation complete.
Run promptfoo view to use the local web viewer
Run promptfoo share to create a shareable URL
Run promptfoo feedback to share feedback with the developers of this tool
======================================================================
Successes: 3
Failures: 0
i
This directly connects the subprocess output to the python terminal. I was able to get it to show the progress bar this way:
Copy code
py
import subprocess

cmd = ['promptfoo', 'eval', '--no-table']
subprocess.run(cmd)
a
thanks! it turns out that for my purposes,
capture_output=True
or piping both the
stdout
and
stderr
was the culprit for not showing the output (i needed to capture
stdout
for later) so instead of
Copy code
py
subprocess.run(
            ["promptfoo", "eval",  "-o", "temp_output_holder.json", "--no-table"], capture_output=True,
            text=True, encoding="utf-8", shell=True)
i changed it to
Copy code
py
subprocess.run(
            ["promptfoo", "eval",  "-o", "temp_output_holder.json", "--no-table"], stdout=subprocess.PIPE,
            text=True, encoding="utf-8", shell=True)