MCPcopy
hub / github.com/granawkins/rawdog / write_finetuning_data

Function write_finetuning_data

scripts/generate_jsonl_from_examples.py:9–28  ·  view source on GitHub ↗
(path)

Source from the content-addressed store, hash-verified

7
8
9def 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
31def find_python_files(directory):

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected