https://promptfoo.dev/ logo
How to specify prompt config with a prompt functio...
# ❓|questions
p
In my promptfoo config I'm referencing a python prompt function with configs like so:
Copy code
yaml
prompts:
  - file://../prompt/prompt.py
    config:
      templateSingleFilter: single_filter_test.txt.j2
      templateMultiFilter: multi_filter_test.txt.j2
when I run the eval, I'm getting a
bad indentation of a sequence entry
error. how are we suppose to format such configs? I tried this
Copy code
yaml
prompts:
  - id: file://../prompt/prompt.py
    config:
      templateSingleFilter: single_filter_test.txt.j2
      templateMultiFilter: multi_filter_test.txt.j2
and got
Error: Invariant failed: Invalid prompt
okay apparently adding a
label
solved these errors.
Copy code
yaml
prompts:
  - label: prompt
    id: file://../prompt/prompt.py
    config:
      templateSingleFilter: single_filter_test.txt.j2
      templateMultiFilter: multi_filter_test.txt.j2
but now I'm trying to access these configs in my prompt function and its running in KeyErrors
Copy code
python
def run(context: dict) -> str:
    template_single_filter = context['config']['templateSingleFilter']
    template_multi_filter = context['config']['templateMultiFilter']
is there any way to access these configs in the prompt function? all I am trying to do is be able to specify certain prompt templates to use in the promptfoo yaml as an input to the construction of the final prompt. the other solution that would be much more work is to somehow transfer the logic into the test cases
m
Hey @peanutshawn, currently, prompt functions only have access to the provider and vars via context, not the config section. I agree this would be useful, and I’ll add support for it later today. I’ll keep you posted!
p
thanks for the quick response!