Skip to content

Commit

Permalink
Move promptfoo to its own folder in /backend. Load OpenAI key from en…
Browse files Browse the repository at this point in the history
…v file. Simplify test structure so less utility .py classes are needed
  • Loading branch information
IMladjenovic committed Nov 1, 2024
1 parent 20b1ad0 commit cbb7644
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 16 deletions.
21 changes: 21 additions & 0 deletions backend/promtfoo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Promptfoo

Promptfoo is a CLI and library for evaluating and red-teaming LLM apps.

See https://www.promptfoo.dev/docs/intro/

## Setup

### Install Promptfoo
Install promptfoo by running `npx install promptfoo`

### Activate Python venv
Promptfoo must be run in a python virtual environment as python is used to load the jinja prompt templates.
See [Running Locally](../README.md)

## Run Promptfoo
Promptfoo configuration (e.g. LLM model) can be set in `promptfooconfig.yaml`

* Use `promptfoo eval` to run all promptfoo tests.
* Use `promptfoo eval -c generate_message_suggestions_config.yaml` to run a specific test suite.
* Use `promptfoo view` to view the results in browser.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ providers:
config:
temperature: 0

prompts: file://get_generate_message_suggestions_prompt.py:get_prompt
prompts: file://prompt_foo_runner.py:generate_message_suggestions

tests:
- description: "test the output has the correct format and content when there is no chat history "
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
from prompting import PromptEngine
import sys
import os
sys.path.append("../")
from dotenv import load_dotenv, find_dotenv # noqa: E402
from src.prompts.prompting import PromptEngine # noqa: E402

load_dotenv(find_dotenv())

OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
engine = PromptEngine()


def get_prompt(context):
def generate_message_suggestions(context):
chat_history = context["vars"]["chatHistory"]

system_prompt = engine.load_prompt("generate_message_suggestions", chat_history=chat_history)
Expand Down
File renamed without changes.
7 changes: 4 additions & 3 deletions backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ pycodestyle==2.11.1
python-dotenv==1.0.1
neo4j==5.18.0
ruff==0.3.5
pytest==8.1.1
pytest-mock==3.14.0
pytest-asyncio==0.23.7
jinja2==3.1.3
websockets==12.0
azure-core==1.30.1
Expand All @@ -26,3 +23,7 @@ pypdf==4.3.1
hiredis==3.0.0
redis==5.0.8

# tests
pytest==8.1.1
pytest-mock==3.14.0
pytest-asyncio==0.23.7
10 changes: 0 additions & 10 deletions backend/src/prompts/README.md

This file was deleted.

0 comments on commit cbb7644

Please sign in to comment.