promptfoo / promptfoo

Test your prompts, agents, and RAGs. Use LLM evals to improve your app's quality and catch problems. Compare performance of GPT, Claude, Gemini, Llama, and more. Simple declarative configs with command line and CI/CD integration.

Home Page:https://www.promptfoo.dev/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add support for picking up variables from .env file

abhagsain opened this issue · comments

It would be great to have support for picking up environment variables from the .env file (I tried it's not working).
Also, I sourced the env variables in my terminal session but they are also not getting picked. I'm not sure what am I doing wrong.

I don't want to add env variables in the yaml file to avoid committing it to git

image

This is my yaml

description: "My first eval"

prompts:
  - "Write a tweet about {{topic}}"
  - "Write a very concise, funny tweet about {{topic}}"

providers:
  - id: azureopenai:chat:gpt-35-16k
    config:
      apiHost: https://<endpoint>.openai.azure.com
      temperature: 0.4
      apiVersion: 2024-02-15-preview
  - id: openai:gpt-4
    config:
      temperature: 0.4

tests:
  - vars:
      topic: bananas

  - vars:
      topic: avocado toast
    assert:
      # For more information on assertions, see https://promptfoo.dev/docs/configuration/expected-outputs
      - type: icontains
        value: avocado
      - type: javascript
        value: 1 / (output.length + 1) # prefer shorter outputs

  - vars:
      topic: new york city
    assert:
      # For more information on model-graded evals, see https://promptfoo.dev/docs/configuration/expected-outputs/model-graded
      - type: llm-rubric
        value: ensure that the output is funny

I have seen mentions of export OPENAI_API_KEY=your_api_key_here in the docs, so it should work.
I'm using Turbo repo and this is my path /Documents/projects/cool-ai-project/packages/prompts. If it helps investigating the issue.

For now, I'll hardcode API keys in yaml but not commit anything.

This was actually just added in #602! It'll be in the next published release (probably published within the next 12 hours)

This change is released in 0.50.0. Thanks!

Hello, thanks for adding this. Is it possible to pass a non-standard path to an .env file to the CLI? While our npm scripts are run from the repo root, we prefer not to have any number of .env files cluttering it up, so they tend to go in package-specific sub-directories along with config files (such as promptfooconfig.yaml).

@alexclaydon Made a PR here that allows you to override the .env path: #615