|
| 1 | +import openai |
| 2 | + |
| 3 | +command = "findfaster" |
| 4 | +help = "Try to find a faster version of the provided library or program" |
| 5 | + |
| 6 | + |
| 7 | +def add_to_command_parser(subparsers): |
| 8 | + parser = subparsers.add_parser(command) |
| 9 | + parser.add_argument("-t", "--software-type", choices=["program", "library", "pylibrary"], default="library", |
| 10 | + help="Specify the type of software. Not necessary, but can lead to better results.") |
| 11 | + parser.add_argument("target", help="The program or library to find a faster version of") |
| 12 | + |
| 13 | + |
| 14 | +software_type_prompts = { |
| 15 | + "program": """What are the fastest and most memory-efficient programs that provide |
| 16 | + the same functionality as {target}, specifically those that use SIMD instructions |
| 17 | + or are optimized for high performance? Output the suggested programs in a list. |
| 18 | + For each program, give a summary.""", |
| 19 | + "library": """What are the fastest and most memory-efficient libraries that provide |
| 20 | + the same functionality as {target}, specifically those that use SIMD instructions |
| 21 | + or are optimized for high performance? Output the suggested libraries in a list. |
| 22 | + For each library, give a summary.""", |
| 23 | + "pylibrary": """What are the fastest and most memory-efficient Python libraries that |
| 24 | + provide the same functionality as Python's {target} library, specifically those that use |
| 25 | + SIMD instructions or are optimized for high performance? I'm also interested in any |
| 26 | + lightweight, low-level libraries that may provide better performance than pure-Python |
| 27 | + libraries. Output the suggested libraries in a list. For each library, give a summary.""" |
| 28 | +} |
| 29 | + |
| 30 | + |
| 31 | +def run(args_parser, args): |
| 32 | + target = args.target |
| 33 | + temp = args.temperature |
| 34 | + |
| 35 | + prompt = software_type_prompts[args.software_type] |
| 36 | + |
| 37 | + completion = openai.ChatCompletion.create( |
| 38 | + model="gpt-3.5-turbo", |
| 39 | + temperature=temp, |
| 40 | + messages=[ |
| 41 | + { |
| 42 | + "role": "system", |
| 43 | + "content": """You are perf-gpt, a helpful assistant for performance analysis and optimisation |
| 44 | + of software. Answer as concisely as possible.""" |
| 45 | + }, |
| 46 | + { |
| 47 | + "role": "user", |
| 48 | + "content": prompt.format(target=target) |
| 49 | + } |
| 50 | + ] |
| 51 | + ) |
| 52 | + |
| 53 | + result = completion['choices'][0]['message']['content'] |
| 54 | + print(result) |
| 55 | + return 0 |
0 commit comments