07 Skills Auto Optimize
* Optional Features: Auto Optimize a Skill¶
leveraging the code_test_agent
and refactor_agent
functions, we can automatically optimize a skill by running the following code:
def auto_optimize(skill, retry_times=3):
skill = self.model_copy(deep=True)
refined = False
for i in range(retry_times):
if skill.test_summary is None:
test_summary = skill.test()
if test_summary is None:
print("> Skill test failed, cannot auto optimize", print_type="markdown")
return skill
all_passed = all(test_case.is_passed for test_case in test_summary.test_cases)
if all_passed and refined:
return skill
print(f"> Auto Refine Skill {i+1}/{retry_times}", print_type="markdown")
skill = skill > "I have tested the skill, but it failed, please refine it."
if all_passed:
skill.test_summary = test_summary
refined = True
return skill
Recommend Model: gpt-4
In [1]:
Copied!
from creator import create, search, save
from creator import create, search, save
In [2]:
Copied!
skills = search("solver of 24 game")
if skills:
game_of_24_skill = skills[0]
skills = search("solver of 24 game")
if skills:
game_of_24_skill = skills[0]
▌ loading vector database...
In [3]:
Copied!
game_of_24_skill.show()
game_of_24_skill.show()
Skill Details: • Name: solve_game_of_24 • Description: This skill solves the Game of 24 by finding a way to combine four given numbers using basic arithmetic operations to obtain the result of 24. • Version: 1.0.0 • Usage: numbers = [1, 1, 2, 12] solution = solve_game_of_24(numbers) print(solution) • Parameters: • numbers (array): An array of four numbers to be used in the Game of 24. • Required: True • Returns: • solution (string): The solution expression that equals 24, or 'No solution found' if no solution is found.
In [4]:
Copied!
game_of_24_skill.show_code()
game_of_24_skill.show_code()
from itertools import permutations def solve_game_of_24(numbers): for permutation in permutations(numbers): a, b, c, d = permutation # Try all possible combinations of arithmetic operations for ops in ['+', '-', '*', '/']: expression = f'(({a} {ops[0]} {b}) {ops[1]} {c}) {ops[2]} {d}' try: result = eval(expression) if result == 24: return expression except ZeroDivisionError: pass return 'No solution found'
In [5]:
Copied!
optimized_skill = game_of_24_skill.auto_optimize()
optimized_skill = game_of_24_skill.auto_optimize()
▌ Installing dependencies
pip show itertools || pip install "itertools"
▌ Install dependencies result: {'status': 'success', 'stdout': '', 'stderr': '\x1b[33mWARNING: Package(s) not ▌ found: itertools\x1b[0m\x1b[33m\n\x1b[0m\x1b[31mERROR: Could not find a version that satisfies the requirement ▌ itertools (from versions: none)\x1b[0m\x1b[31m\n'}
Output()
Output()
Output()
Output()
Output()
▌ Auto Refine Skill 1/3
Output()
In [6]:
Copied!
optimized_skill.show()
optimized_skill.show()
Skill Details: • Name: solve_game_of_24 • Description: This skill solves the Game of 24 by finding a way to combine four given numbers using basic arithmetic operations to obtain the result of 24. • Version: 1.0.0 • Usage: numbers = [1, 1, 2, 12] solution = solve_game_of_24(numbers) print(solution) • Parameters: • numbers (array): An array of four numbers to be used in the Game of 24. • Required: True • Returns: • solution (string): The solution expression that equals 24, or 'No solution found' if no solution is found.
In [7]:
Copied!
optimized_skill.show_code()
optimized_skill.show_code()
from itertools import permutations, product def solve_game_of_24(numbers): for permutation in permutations(numbers): a, b, c, d = permutation # Try all possible combinations of arithmetic operations for ops in product(['+', '-', '*', '/'], repeat=3): expression = f'(({a} {ops[0]} {b}) {ops[1]} {c}) {ops[2]} {d}' try: result = eval(expression) if result == 24: return expression except ZeroDivisionError: pass return 'No solution found'
In [ ]:
Copied!
Last update:
October 31, 2023
Created: October 18, 2023
Created: October 18, 2023