-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathusage_example.py
More file actions
29 lines (23 loc) · 959 Bytes
/
Copy pathusage_example.py
File metadata and controls
29 lines (23 loc) · 959 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env python3
"""
Example usage of GPTDiff API with generate_diff and smartapply.
This example demonstrates how to transform a simple codebase using AI-generated diffs.
"""
from patchling import generate_diff, smartapply, build_environment
import os
# Set the GPTDiff API key
os.environ['GPTDIFF_LLM_API_KEY'] = 'your-api-key'
# Original codebase represented as a dictionary
files = {
"main.py": "def old_name():\n print('Need renaming')\n"
}
# Generate a transformation diff to rename function from old_name to new_name and update its call sites
diff_text = generate_diff(
environment=build_environment(files),
goal='Rename function to new_name(): and update its call sites accordingly',
)
# Apply the AI-generated diff with smartapply, ensuring safe modifications
updated_files = smartapply(diff_text, files)
# Output the transformed codebase
print("Transformed codebase:")
print(updated_files.get("main.py", "File not found"))