Files
dev-gpt/test/test_generator.py
Florian Hönicke d52e7489c5 🧪 test: level 2
2023-05-01 11:41:26 +02:00

146 lines
4.3 KiB
Python

import os
import pytest
from src.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):
"""
Requirements:
coding challenge: ❌
pip packages: ❌
environment: ❌
GPT-3.5-turbo: ❌
APIs: ❌
Databases: ❌
"""
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',
'gpt-3.5-turbo'
)
assert generator.generate() == 0
# fixture
@pytest.fixture
def tmpdir():
return 'microservice'
def test_generation_level_1(tmpdir):
"""
Requirements:
coding challenge: ❌
pip packages: ❌
environment: ❌
GPT-3.5-turbo: ✅ (for summarizing the text)
APIs: ❌
Databases: ❌
"""
os.environ['VERBOSE'] = 'true'
generator = Generator(
'''Input is a tweet that might contain passive aggressive language. The output is the positive version of that tweet.
Example tweet:
\'When your coworker microwaves fish in the break room... AGAIN. 🐟🤢
But hey, at least SOMEONE's enjoying their lunch. #officelife\'''',
str(tmpdir) + 'microservice',
'gpt-3.5-turbo'
)
assert generator.generate() == 0
def test_generation_level_2(tmpdir):
"""
Requirements:
coding challenge: ❌
pip packages: ✅ (pdf parser)
environment: ❌
GPT-3.5-turbo: ✅ (for summarizing the text)
APIs: ❌
Databases: ❌
"""
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) + 'microservice',
'gpt-3.5-turbo'
)
assert generator.generate() == 0
#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.
@pytest.mark.skip(reason="not possible")
def test_generation_level_3(tmpdir):
"""
Requirements:
coding challenge: ❌
pip packages: ✅ (text to speech)
environment: ❌
GPT-3.5-turbo: ✅ (summarizing the text)
APIs: ✅ (whisper for speech to text)
Databases: ❌
"""
os.environ['VERBOSE'] = 'true'
generator = Generator(
f'''Given an audio file of speech like https://www.signalogic.com/melp/EngSamples/Orig/ENG_M.wav,
get convert it to text using the following api:
import requests
url = "https://transcribe.whisperapi.com"
headers = {{
'Authorization': 'Bearer {os.environ['WHISPER_API_KEY']}'
}}
data = {{
"url": "URL_OF_STORED_AUDIO_FILE"
}}
response = requests.post(url, headers=headers, files=file, data=data)
print(response.text)
Summarize the text.
Create an audio file of the summarized text.
''',
str(tmpdir) + 'microservice',
'gpt-3.5-turbo'
)
assert generator.generate() == 0
@pytest.mark.skip(reason="not possible")
def test_generation_level_4(tmpdir):
"""
Requirements:
coding challenge: ✅ (putting text on the image)
pip packages: ✅ (Pillow for image processing)
environment: ❌
GPT-3.5-turbo: ✅ (for writing the joke)
APIs: ✅ (scenex for image description)
Databases: ❌
"""
os.environ['VERBOSE'] = 'true'
generator = Generator(f'''
The input is an image like this: https://upload.wikimedia.org/wikipedia/commons/thumb/4/47/PNG_transparency_demonstration_1.png/560px-PNG_transparency_demonstration_1.png.
Use the following api to get the description of the image:
Request:
curl "https://us-central1-causal-diffusion.cloudfunctions.net/describe" \\
-H "x-api-key: token {os.environ['SCENEX_API_KEY']}" \\
-H "content-type: application/json" \\
--data '{{"data":[
{{"image": "<image url here>", "features": []}}
]}}'
Result format:
{{
"result": [
{{
"text": "<image description>"
}}
]
}}
The description is then used to generate a joke.
The joke is the put on the image.
The output is the image with the joke on it.''',
str(tmpdir) + 'microservice',
'gpt-3.5-turbo'
)
assert generator.generate() == 0