Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
remove check function from code response
  • Loading branch information
sonichi committed Apr 3, 2023
commit a2242797affd5014e85d89c6b146c00a02925d8d
19 changes: 16 additions & 3 deletions flaml/autogen/code_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ def generate_assertions(
return assertions, cost


def _remove_check(response):
"""Remove the check function from the response."""
# find the position of the check function
pos = response.find("def check")
if pos == -1:
return response
return response[:pos]


def success_metrics(
responses: List[str],
definition: str,
Expand All @@ -82,7 +91,7 @@ def success_metrics(
# no assertion filter
success_list = []
for i in range(n):
response = responses[i]
response = _remove_check(responses[i])
code = f"{definition}{response}\n{test}\ncheck({entry_point})"
success = execute_code(code)
success_list.append(success)
Expand All @@ -97,7 +106,7 @@ def success_metrics(
gen_cost = 0
if n > 1 or test is None:
for i in range(n):
response = responses[i]
response = responses[i] = _remove_check(responses[i])
code = (
f"{response}\n{assertions}"
if response.startswith("def")
Expand All @@ -112,7 +121,11 @@ def success_metrics(
i, response = 0, responses[0]
if test is None:
# no test code
return {"succeed_assertions": succeed_assertions}
return {
"index_selected": i,
"succeed_assertions": succeed_assertions,
"gen_cost": gen_cost,
}
code_test = (
f"{response}\n{test}\ncheck({entry_point})"
if response.startswith("def")
Expand Down
2 changes: 1 addition & 1 deletion notebook/autogen_openai.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@
"from functools import partial\n",
"from flaml.autogen.code_utils import success_metrics, generate_assertions\n",
"\n",
"success_metrics_with_generated_assertions = partial(success_metrics,assertions=generate_assertions)"
"success_metrics_with_generated_assertions = partial(success_metrics, assertions=generate_assertions)"
]
},
{
Expand Down
Loading