diff --git a/dev_gpt/options/generate/static_files/microservice/apis.py b/dev_gpt/options/generate/static_files/microservice/google_custom_search.py similarity index 61% rename from dev_gpt/options/generate/static_files/microservice/apis.py rename to dev_gpt/options/generate/static_files/microservice/google_custom_search.py index def8830..f112129 100644 --- a/dev_gpt/options/generate/static_files/microservice/apis.py +++ b/dev_gpt/options/generate/static_files/microservice/google_custom_search.py @@ -1,29 +1,3 @@ -import os -import openai - - -openai.api_key = os.getenv("OPENAI_API_KEY") - - -class GPT_3_5_Turbo: - def __init__(self, system_string: str = ''): - self.system = system_string - - def __call__(self, prompt_string: str) -> str: - response = openai.ChatCompletion.create( - model="gpt-3.5-turbo", - messages=[{ - "role": 'system', - "content": self.system - }, { - "role": 'user', - "content": prompt_string - }] - ) - return response.choices[0]['message']['content'] - - - import os from typing import Optional @@ -52,4 +26,3 @@ def search_images(search_term, top_n): def search_web(search_term, top_n): response = google_search(search_term, search_type="web", top_n=top_n) return [item["snippet"] for item in response["items"]] - diff --git a/dev_gpt/options/generate/static_files/microservice/gpt_3_5_turbo.py b/dev_gpt/options/generate/static_files/microservice/gpt_3_5_turbo.py new file mode 100644 index 0000000..8b618ef --- /dev/null +++ b/dev_gpt/options/generate/static_files/microservice/gpt_3_5_turbo.py @@ -0,0 +1,24 @@ +import os +import openai + + +openai.api_key = os.getenv("OPENAI_API_KEY") + + +class GPT_3_5_Turbo: + def __init__(self, system_string: str = ''): + self.system = system_string + + def __call__(self, prompt_string: str) -> str: + response = openai.ChatCompletion.create( + model="gpt-3.5-turbo", + messages=[{ + "role": 'system', + "content": self.system + }, { + "role": 'user', + "content": prompt_string + }] + ) + return response.choices[0]['message']['content'] + diff --git a/dev_gpt/options/generate/templates_user.py b/dev_gpt/options/generate/templates_user.py index b2908a4..300a3c1 100644 --- a/dev_gpt/options/generate/templates_user.py +++ b/dev_gpt/options/generate/templates_user.py @@ -94,7 +94,7 @@ You must provide the complete {file_name} wrapped with the exact syntax shown ab gpt_35_turbo_usage_string = """If you need to use gpt_3_5_turbo, then use it like shown in the following example: ``` -from .apis import GPT_3_5_Turbo +from .gpt_3_5_turbo import GPT_3_5_Turbo gpt_3_5_turbo = GPT_3_5_Turbo( system_string=\'\'\' @@ -110,7 +110,7 @@ generated_string = gpt_3_5_turbo(prompt_string="example user prompt") # prompt_s google_custom_search_usage_string = """If you need to use google_custom_search, then use it like shown in the following example: a) when searching for text: ``` -from .apis import search_web +from .google_custom_search import search_web # input: search term (str), top_n (int) # output: list of strings @@ -118,7 +118,7 @@ string_list = search_web('', top_n=10) ``` b) when searching for images: ``` -from .apis import search_images +from .google_custom_search import search_images # input: search term (str), top_n (int) # output: list of image urls @@ -140,7 +140,7 @@ It will be tested with the following scenario: '{{test_description}}'. For the implementation use the following package(s): '{{packages}}'. The code must start with the following imports: -```{linebreak +'from .apis import GPT_3_5_Turbo' if is_using_gpt_3_5_turbo else ""}{linebreak + 'from .apis import search_web, search_images' if is_using_google_custom_search else ""}{linebreak} +```{linebreak +'from .gpt_3_5_turbo import GPT_3_5_Turbo' if is_using_gpt_3_5_turbo else ""}{linebreak + 'from .google_custom_search import search_web, search_images' if is_using_google_custom_search else ""}{linebreak} import json import requests diff --git a/test/unit/test_search.py b/test/unit/test_search.py index b5839fd..fdd38fb 100644 --- a/test/unit/test_search.py +++ b/test/unit/test_search.py @@ -1,4 +1,4 @@ -from dev_gpt.options.generate.static_files.microservice.apis import search_web, search_images +from dev_gpt.options.generate.static_files.microservice.google_custom_search import search_web, search_images def test_web_search():