From 035befcfb0d39a85856e17e3e08a4016eb7f5c1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Ho=CC=88nicke?= Date: Sat, 27 May 2023 16:31:49 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9E=95=20refactor:=20summarize=20error=20mes?= =?UTF-8?q?sage=20without=20line=20number?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../microservice/google_custom_search.py | 19 +++++++++++++++++-- test/integration/test_generator.py | 18 +++++------------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/dev_gpt/options/generate/static_files/microservice/google_custom_search.py b/dev_gpt/options/generate/static_files/microservice/google_custom_search.py index f112129..3f47a98 100644 --- a/dev_gpt/options/generate/static_files/microservice/google_custom_search.py +++ b/dev_gpt/options/generate/static_files/microservice/google_custom_search.py @@ -20,8 +20,23 @@ def google_search(search_term, search_type, top_n): return response.json() def search_images(search_term, top_n): - response = google_search(search_term, search_type="image", top_n=top_n) - return [item["link"] for item in response["items"]] + """ + Returns only images that have a 200 response code. + """ + response = google_search(search_term, search_type="image", top_n=10) + image_urls = [] + for item in response["items"]: + if len(image_urls) >= top_n: + break + try: + response = requests.head(item["link"], timeout=2) + if response.status_code == 200: + image_urls.append( + item["link"] + ) + except requests.exceptions.RequestException: + pass + return image_urls def search_web(search_term, top_n): response = google_search(search_term, search_type="web", top_n=top_n) diff --git a/test/integration/test_generator.py b/test/integration/test_generator.py index 2e8deee..11f663f 100644 --- a/test/integration/test_generator.py +++ b/test/integration/test_generator.py @@ -129,17 +129,9 @@ Example input: 'AAPL' 'y', 'https://www2.cs.uic.edu/~i101/SoundFiles/taunt.wav', f'''\ -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, data=data) -assert response.status_code == 200 -print('This is the text from the audio file:', response.text)''' +import openai +audio_file= open("/path/to/file/audio.mp3", "rb") +transcript = openai.Audio.transcribe("whisper-1", audio_file)''' ] ], indirect=True @@ -158,12 +150,12 @@ def test_generation_level_4(microservice_dir, mock_input_sequence): generator = Generator( f'''Given an audio file (1min wav) of speech, 1. convert it to text using the Whisper API. -2. Summarize the text (~50 words) while still maintaining the key facts. +2. Summarize the text while still maintaining the key facts. 3. Create an audio file of the summarized text using a tts library. 4. Return the the audio file as base64 encoded binary. ''', str(microservice_dir), - 'gpt-4', + 'gpt-3.5-turbo', # self_healing=False, ) assert generator.generate() == 0