From 919d2bdc529a88c062b70654d72eae579acd9b64 Mon Sep 17 00:00:00 2001 From: Wilder Lopes Date: Wed, 6 Nov 2024 22:04:11 -0600 Subject: [PATCH] Fixes and improvements. --- miniogre/actions.py | 22 +++++++++++----------- miniogre/constants.py | 2 ++ miniogre/main.py | 7 +++---- pyproject.toml | 2 +- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/miniogre/actions.py b/miniogre/actions.py index 5278fb6..f307e04 100644 --- a/miniogre/actions.py +++ b/miniogre/actions.py @@ -272,7 +272,7 @@ def query_pypi(module_name: str) -> str: pass return None # Not found on PyPI -def extract_requirements_from_code(project_path, ext, generate=True): +def extract_requirements_from_code(project_path, ext, generate=True, verbose=False): requirements_emoji() @@ -291,14 +291,17 @@ def extract_requirements_from_code(project_path, ext, generate=True): # Filter out None values (standard libraries) and display the necessary packages necessary_packages = {k: v for k, v in package_mapping.items() if v is not None} package_list = list(necessary_packages.values()) - print(f"> package_list: \n{package_list}") + if verbose: + print(f"> {filename}") + print(f"> package_list: \n{package_list}") external_imports.append(package_list) - print(f"> external_imports: \n{external_imports}") + #print(f"> external_imports: \n{external_imports}") # Collapse into a unique list with no duplicates unique_list = list(set(item for sublist in external_imports for item in sublist)) requirements = "\n".join(unique_list) - print(f"> requirements: \n{requirements}") + if verbose: + print(f"> requirements: \n{requirements}") else: with open( "{}/requirements.txt".format(os.getenv("OGRE_DIR", OGRE_DIR)), "r" @@ -456,7 +459,7 @@ def clean_requirements_gemini(requirements): client = googleai.GenerativeModel(model) full_prompt = f"{prompt}\n---\n{requirements}" # print(f"{full_prompt=}") - response = client.generate_content(full_prompt, request_options={"timeout": 1000}) + response = client.generate_content(full_prompt, request_options={"timeout": TIMEOUT_API_REQUEST}) requirements = response.text # print(f"{requirements=}") return requirements @@ -656,7 +659,7 @@ def rewrite_readme_gemini(readme): raise EnvironmentError("GEMINI_API_KEY environment variable not defined") try: client = googleai.GenerativeModel(model) - response = client.generate_content(full_prompt) + response = client.generate_content(full_prompt, request_options={"timeout": TIMEOUT_API_REQUEST}) new_readme = response.text except Exception as e: print(e) @@ -1016,7 +1019,7 @@ def evaluate_readme_gemini(readme, verbose): raise EnvironmentError("GEMINI_API_KEY environment variable not defined") try: client = googleai.GenerativeModel(model) - response = client.generate_content(prompt) + response = client.generate_content(prompt, request_options={"timeout": TIMEOUT_API_REQUEST}) score = response.text if verbose: print(f"\n{score=}\n") @@ -1186,7 +1189,6 @@ def ask_miniogre_openai(context, question): {"role": "user", "content": context}, ], ) - # print(completion) answer = completion.choices[0].message.content except Exception as e: print(e) @@ -1201,7 +1203,7 @@ def ask_miniogre_gemini(context, question): raise EnvironmentError("GEMINI_API_KEY environment variable not defined") try: client = googleai.GenerativeModel(model) - response = client.generate_content(full_prompt) + response = client.generate_content(full_prompt, request_options={"timeout": TIMEOUT_API_REQUEST}) answer = response.text except Exception as e: print(e) @@ -1231,8 +1233,6 @@ def ask_miniogre_ogre(context, question): # Send the POST request response = requests.post(api_server, headers=headers, json=data) - print(response) - input() # Process the response response_json = json.loads(response.json()['data']) answer = response_json['response'] diff --git a/miniogre/constants.py b/miniogre/constants.py index 80e275d..cbbd686 100644 --- a/miniogre/constants.py +++ b/miniogre/constants.py @@ -1,3 +1,5 @@ +TIMEOUT_API_REQUEST = 240 + DOCKERFILE = """ ENV TZ=America/Chicago WORKDIR /opt/{} diff --git a/miniogre/main.py b/miniogre/main.py index cfc0c3a..cc54e54 100644 --- a/miniogre/main.py +++ b/miniogre/main.py @@ -46,9 +46,8 @@ def ask(question: str = "", # Send request to API answer = ask_miniogre(provider, context_contents, question) - print(answer) - # Save answer - #readme_path = save_readme(new_readme, ogre_dir_path) + print(f"Here is the answer:\n{answer}") + # TODO: Save answer in Google Storage end_emoji() @@ -139,7 +138,7 @@ def run( project_path, ogre_dir_path, force_requirements_generation ) local_requirements = extract_requirements_from_code( - project_path, most_ext, generate_requirements + project_path, most_ext, generate_requirements, verbose ) final_requirements = clean_requirements(provider, local_requirements) requirements_fullpath = save_requirements(final_requirements, ogre_dir_path) diff --git a/pyproject.toml b/pyproject.toml index 3dfeffe..19417e9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "miniogre" -version = "0.10.0" +version = "0.10.1" description = "miniogre: from source code to reproducible environment, in seconds." readme = "README.md" authors = ["Wilder Lopes "]