(path)
| 7 | |
| 8 | |
| 9 | def write_finetuning_data(path): |
| 10 | try: |
| 11 | spec = importlib.util.spec_from_file_location("", path) |
| 12 | module = importlib.util.module_from_spec(spec) |
| 13 | spec.loader.exec_module(module) |
| 14 | if hasattr(module, "conversation"): |
| 15 | conversation = module.conversation |
| 16 | for message in conversation: |
| 17 | if message["role"] == "assistant": |
| 18 | function_name = message["content"] |
| 19 | function = getattr(module, function_name) |
| 20 | function_source = inspect.getsource(function).split("\n", 1)[1] |
| 21 | message["content"] = "```\n" + dedent(function_source) + "```" |
| 22 | conversation = conversation[2:] |
| 23 | data = {"messages": conversation} |
| 24 | with open("training_data.jsonl", "a") as f: |
| 25 | json.dump(data, f) |
| 26 | f.write("\n") |
| 27 | except Exception as e: |
| 28 | print(f"Failed to import {path}: {e}") |
| 29 | |
| 30 | |
| 31 | def find_python_files(directory): |
no outgoing calls
no test coverage detected