a few more
This commit is contained in:
parent
3f2f996ff2
commit
23e4a29608
5 changed files with 16 additions and 14 deletions
|
|
@ -27,14 +27,14 @@ def parse_python_version(version: str) -> tuple[int, int, int]:
|
|||
split_version = version.split(".")
|
||||
if len(split_version) != 3:
|
||||
raise ValueError("Invalid version format")
|
||||
version_tuple = tuple(map(int, split_version))
|
||||
assert version_tuple[0] == 3, "Only Python 3 is supported"
|
||||
assert version_tuple[1] >= 9, "Only Python 3.9 and above is supported"
|
||||
assert version_tuple[1] <= 14, "Unsupported Python version"
|
||||
assert version_tuple[2] >= 0, "Only Python 3.9 and above is supported"
|
||||
assert version_tuple[2] < 100, "Invalid version format"
|
||||
major, minor, patch = int(split_version[0]), int(split_version[1]), int(split_version[2])
|
||||
assert major == 3, "Only Python 3 is supported"
|
||||
assert minor >= 9, "Only Python 3.9 and above is supported"
|
||||
assert minor <= 14, "Unsupported Python version"
|
||||
assert patch >= 0, "Only Python 3.9 and above is supported"
|
||||
assert patch < 100, "Invalid version format"
|
||||
|
||||
return version_tuple
|
||||
return (major, minor, patch)
|
||||
|
||||
|
||||
def validate_trace_id(trace_id: str) -> bool:
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ async def log_optimization_event(
|
|||
) -> OptimizationEvents:
|
||||
if repository_id is None and repo_owner and repo_name:
|
||||
repository = await get_repository(repo_owner, repo_name)
|
||||
repository_id = repository.id if repository else None
|
||||
repository_id = str(repository.id) if repository else None
|
||||
|
||||
return await OptimizationEvents.objects.acreate(
|
||||
id=str(uuid4()),
|
||||
|
|
@ -70,7 +70,7 @@ async def get_or_create_optimization_event(
|
|||
"""
|
||||
if repository_id is None and repo_owner and repo_name:
|
||||
repository = await get_repository(repo_owner, repo_name)
|
||||
repository_id = repository.id if repository else None
|
||||
repository_id = str(repository.id) if repository else None
|
||||
|
||||
event, created = await OptimizationEvents.objects.aupdate_or_create(
|
||||
trace_id=trace_id,
|
||||
|
|
|
|||
|
|
@ -210,10 +210,10 @@ async def optimization_review(
|
|||
response_code, output = await get_optimization_review(request, data)
|
||||
try:
|
||||
if response_code == 200:
|
||||
review_event = output.review.value
|
||||
review_explanation = output.review_explanation
|
||||
review_event = output.review.value # ty:ignore[possibly-missing-attribute]
|
||||
review_explanation = output.review_explanation # ty:ignore[possibly-missing-attribute]
|
||||
else:
|
||||
review_event = output.error
|
||||
review_event = output.error # ty:ignore[possibly-missing-attribute]
|
||||
review_explanation = ""
|
||||
await update_optimization_features_review(
|
||||
trace_id=data.trace_id,
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ class BaseOptimizerContext:
|
|||
# multi-file context with only a single file, we can use the old single context
|
||||
file_name = files[0]
|
||||
return SingleOptimizerContext(
|
||||
system_prompt, user_prompt, source_code=file_to_code.get(file_name), file_name=file_name
|
||||
system_prompt, user_prompt, source_code=file_to_code[file_name], file_name=file_name
|
||||
)
|
||||
# only multi optimizer context can accept a diff method
|
||||
return MultiOptimizerContext(system_prompt, user_prompt, source_code, diff_method=diff_method)
|
||||
|
|
@ -344,6 +344,8 @@ class MultiOptimizerContext(BaseOptimizerContext):
|
|||
)
|
||||
|
||||
def is_valid_code(self) -> bool:
|
||||
if self.extracted_code_and_expl is None:
|
||||
return False
|
||||
changed = is_markdown_structure_changed(self.source_code, self.extracted_code_and_expl.code)
|
||||
if changed:
|
||||
debug_log_sensitive_data(
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ async def optimize_python_code_line_profiler_single(
|
|||
# TODO: Experiment with iterative chain-of-thought generation. ask what is the
|
||||
# function doing and then ask it to describe how to speed it up and then generate optimization
|
||||
system_prompt = ctx.get_system_prompt(python_version_str=python_version_str)
|
||||
user_prompt = ctx.get_user_prompt(dependency_code, line_profiler_results)
|
||||
user_prompt = ctx.get_user_prompt(dependency_code or "", line_profiler_results)
|
||||
|
||||
system_message = ChatCompletionSystemMessageParam(role="system", content=system_prompt)
|
||||
user_message = ChatCompletionUserMessageParam(role="user", content=user_prompt)
|
||||
|
|
|
|||
Loading…
Reference in a new issue