mirror of
https://github.com/aljazceru/dev-gpt.git
synced 2025-12-29 11:24:21 +01:00
🪓 feat: sub task refinement
This commit is contained in:
31
test/conftest.py
Normal file
31
test/conftest.py
Normal file
@@ -0,0 +1,31 @@
|
||||
import os
|
||||
from typing import List, Generator
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
def input_generator(input_sequence: list) -> Generator[str, None, None]:
|
||||
"""
|
||||
Creates a generator that yields input strings from the given sequence.
|
||||
|
||||
:param input_sequence: A list of input strings.
|
||||
:return: A generator that yields input strings.
|
||||
"""
|
||||
yield from input_sequence
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_input_sequence(request, monkeypatch) -> None:
|
||||
gen = input_generator(request.param)
|
||||
monkeypatch.setattr("builtins.input", lambda _: next(gen))
|
||||
|
||||
@pytest.fixture
|
||||
def microservice_dir(tmpdir) -> str:
|
||||
"""
|
||||
Creates a temporary directory for a microservice.
|
||||
|
||||
:param tmpdir: A temporary directory.
|
||||
:return: The path of the temporary directory.
|
||||
"""
|
||||
return os.path.join(str(tmpdir), "microservice")
|
||||
|
||||
@@ -7,7 +7,8 @@ from dev_gpt.options.generate.generator import Generator
|
||||
|
||||
# The cognitive difficulty level is determined by the number of requirements the microservice has.
|
||||
|
||||
def test_generation_level_0(tmpdir):
|
||||
@pytest.mark.parametrize('mock_input_sequence', [['y']], indirect=True)
|
||||
def test_generation_level_0(microservice_dir, mock_input_sequence):
|
||||
"""
|
||||
Requirements:
|
||||
coding challenge: ❌
|
||||
@@ -20,15 +21,15 @@ def test_generation_level_0(tmpdir):
|
||||
os.environ['VERBOSE'] = 'true'
|
||||
generator = Generator(
|
||||
"The microservice is very simple, it does not take anything as input and only outputs the word 'test'",
|
||||
str(tmpdir),
|
||||
microservice_dir,
|
||||
'gpt-3.5-turbo'
|
||||
)
|
||||
assert generator.generate() == 0
|
||||
|
||||
|
||||
|
||||
|
||||
def test_generation_level_1(tmpdir):
|
||||
@pytest.mark.parametrize('mock_input_sequence', [['y']], indirect=True)
|
||||
def test_generation_level_1(microservice_dir):
|
||||
"""
|
||||
Requirements:
|
||||
coding challenge: ❌
|
||||
@@ -44,13 +45,14 @@ def test_generation_level_1(tmpdir):
|
||||
Example tweet:
|
||||
\'When your coworker microwaves fish in the break room... AGAIN. 🐟🤢
|
||||
But hey, at least SOMEONE's enjoying their lunch. #officelife\'''',
|
||||
str(tmpdir),
|
||||
str(microservice_dir),
|
||||
'gpt-3.5-turbo'
|
||||
)
|
||||
assert generator.generate() == 0
|
||||
|
||||
|
||||
def test_generation_level_2(tmpdir):
|
||||
@pytest.mark.parametrize('mock_input_sequence', [['y']], indirect=True)
|
||||
def test_generation_level_2(microservice_dir):
|
||||
"""
|
||||
Requirements:
|
||||
coding challenge: ❌
|
||||
@@ -63,12 +65,13 @@ def test_generation_level_2(tmpdir):
|
||||
os.environ['VERBOSE'] = 'true'
|
||||
generator = Generator(
|
||||
"The input is a PDF like https://www.africau.edu/images/default/sample.pdf and the output the summarized text (50 words).",
|
||||
str(tmpdir),
|
||||
str(microservice_dir),
|
||||
'gpt-3.5-turbo'
|
||||
)
|
||||
assert generator.generate() == 0
|
||||
|
||||
def test_generation_level_3(tmpdir):
|
||||
@pytest.mark.parametrize('mock_input_sequence', [['y']], indirect=True)
|
||||
def test_generation_level_3(microservice_dir):
|
||||
"""
|
||||
Requirements:
|
||||
coding challenge: ✅ (calculate the average closing price)
|
||||
@@ -87,12 +90,13 @@ def test_generation_level_3(tmpdir):
|
||||
4. Return the summary as a string.
|
||||
Example input: 'AAPL'
|
||||
''',
|
||||
str(tmpdir),
|
||||
str(microservice_dir),
|
||||
'gpt-3.5-turbo'
|
||||
)
|
||||
assert generator.generate() == 0
|
||||
|
||||
def test_generation_level_4(tmpdir):
|
||||
@pytest.mark.parametrize('mock_input_sequence', [['y']], indirect=True)
|
||||
def test_generation_level_4(microservice_dir):
|
||||
"""
|
||||
Requirements:
|
||||
coding challenge: ❌
|
||||
@@ -123,13 +127,13 @@ print('This is the text from the audio file:', response.json()['text'])
|
||||
4. Return the the audio file as base64 encoded binary.
|
||||
Example input file: https://www.signalogic.com/melp/EngSamples/Orig/ENG_M.wav
|
||||
''',
|
||||
str(tmpdir),
|
||||
str(microservice_dir),
|
||||
'gpt-4'
|
||||
)
|
||||
assert generator.generate() == 0
|
||||
|
||||
|
||||
def test_generation_level_5(tmpdir):
|
||||
@pytest.mark.parametrize('mock_input_sequence', [['y']], indirect=True)
|
||||
def test_generation_level_5(microservice_dir):
|
||||
"""
|
||||
Requirements:
|
||||
coding challenge: ✅ (putting text on the image)
|
||||
@@ -163,15 +167,30 @@ The joke is the put on the image.
|
||||
The output is the image with the joke on it.
|
||||
Example input image: https://upload.wikimedia.org/wikipedia/commons/thumb/4/47/PNG_transparency_demonstration_1.png/560px-PNG_transparency_demonstration_1.png
|
||||
''',
|
||||
str(tmpdir),
|
||||
str(microservice_dir),
|
||||
'gpt-3.5-turbo'
|
||||
)
|
||||
assert generator.generate() == 0
|
||||
|
||||
@pytest.fixture
|
||||
def tmpdir():
|
||||
return 'microservice'
|
||||
# @pytest.fixture
|
||||
# def microservice_dir():
|
||||
# return 'microservice'
|
||||
|
||||
|
||||
# further ideas:
|
||||
# Create a wrapper around google called Joogle. It modifies the page summary preview text of the search results to insert the word Jina as much as possible.
|
||||
# # further ideas:
|
||||
# # Create a wrapper around google called Joogle. It modifies the page summary preview text of the search results to insert the word Jina as much as possible.
|
||||
#
|
||||
# import pytest
|
||||
#
|
||||
# # This is your fixture which can accept parameters
|
||||
# @pytest.fixture
|
||||
# def my_fixture(microservice_dir, request,):
|
||||
# return request.param # request.param will contain the parameter value
|
||||
#
|
||||
# # Here you parameterize the fixture for the test
|
||||
# @pytest.mark.parametrize('my_fixture', ['param1', 'param2', 'param3'], indirect=True)
|
||||
# def test_my_function(my_fixture, microservice_dir):
|
||||
# # 'my_fixture' now contains the value 'param1', 'param2', or 'param3'
|
||||
# # depending on the iteration
|
||||
# # Here you can write your test
|
||||
# ...
|
||||
|
||||
11
test/unit/test_construct_sub_task_tree.py
Normal file
11
test/unit/test_construct_sub_task_tree.py
Normal file
@@ -0,0 +1,11 @@
|
||||
import os
|
||||
|
||||
from dev_gpt.apis import gpt
|
||||
from dev_gpt.options.generate.pm.pm import PM
|
||||
|
||||
def test_construct_sub_task_tree():
|
||||
os.environ['VERBOSE'] = 'true'
|
||||
gpt_session = gpt.GPTSession('test', model='gpt-3.5-turbo')
|
||||
pm = PM(gpt_session)
|
||||
microservice_description = 'This microservice receives an image as input and generates a joke based on what is depicted on the image. The input must be a binary string of the image. The output is an image with the generated joke overlaid on it.'
|
||||
sub_task_tree = pm.construct_sub_task_tree(microservice_description)
|
||||
Reference in New Issue
Block a user