-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from pavelkraleu/17-implement-docker-for-testing
Implement Docker and unit tests
- Loading branch information
Showing
5 changed files
with
68 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: Docker Build and Run | ||
|
||
on: | ||
push: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Build Docker Image | ||
run: | | ||
docker build . -t needle-in-a-haystack | ||
- name: Run Docker Container | ||
run: | | ||
docker run --entrypoint pytest -t needle-in-a-haystack |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
FROM python:3.12 | ||
|
||
ENV PYTHONPATH /app | ||
ENV PYTHONUNBUFFERED 1 | ||
|
||
WORKDIR /app | ||
|
||
COPY requirements.txt . | ||
|
||
RUN pip install --no-cache-dir -r requirements.txt | ||
|
||
COPY . . | ||
|
||
ENTRYPOINT ["python"] | ||
CMD ["main.py"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from unittest.mock import patch, MagicMock, call, ANY | ||
|
||
from needlehaystack.evaluators import OpenAIEvaluator | ||
|
||
QUESTION_ASKED = "What is the color of the sky?" | ||
QUESTION_ANSWER = "Sky is blue" | ||
API_KEY = "abc" | ||
SCORE = 123 | ||
TEMPERATURE = 0 | ||
MODEL = "gpt-3.5-turbo-0125" | ||
|
||
|
||
@patch('needlehaystack.evaluators.openai.ChatOpenAI') | ||
@patch('needlehaystack.evaluators.openai.load_evaluator') | ||
def test_openai(mock_load_evaluator, mock_chat_open_ai, monkeypatch): | ||
monkeypatch.setenv('NIAH_EVALUATOR_API_KEY', API_KEY) | ||
|
||
mock_evaluator = MagicMock() | ||
mock_evaluator.evaluate_strings.return_value = {'score': str(SCORE)} | ||
|
||
mock_load_evaluator.return_value = mock_evaluator | ||
|
||
evaluator = OpenAIEvaluator(question_asked=QUESTION_ASKED, true_answer=QUESTION_ANSWER) | ||
result = evaluator.evaluate_response("Something") | ||
|
||
assert mock_chat_open_ai.call_args == call(model=MODEL, temperature=TEMPERATURE, openai_api_key=API_KEY) | ||
assert mock_load_evaluator.call_args == call('labeled_score_string', criteria=OpenAIEvaluator.CRITERIA, llm=ANY) | ||
|
||
assert result == SCORE |