Skip to content

Commit

Permalink
Fixes and improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
wilderlopes committed Nov 7, 2024
1 parent f4ed3f4 commit 919d2bd
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
22 changes: 11 additions & 11 deletions miniogre/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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']
Expand Down
2 changes: 2 additions & 0 deletions miniogre/constants.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
TIMEOUT_API_REQUEST = 240

DOCKERFILE = """
ENV TZ=America/Chicago
WORKDIR /opt/{}
Expand Down
7 changes: 3 additions & 4 deletions miniogre/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
Expand Down

0 comments on commit 919d2bd

Please sign in to comment.