gptdiff 0.1.18__tar.gz → 0.1.21__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {gptdiff-0.1.18 → gptdiff-0.1.21}/PKG-INFO +2 -2
- {gptdiff-0.1.18 → gptdiff-0.1.21}/gptdiff/gptdiff.py +39 -3
- {gptdiff-0.1.18 → gptdiff-0.1.21}/gptdiff.egg-info/PKG-INFO +2 -2
- {gptdiff-0.1.18 → gptdiff-0.1.21}/gptdiff.egg-info/SOURCES.txt +2 -1
- {gptdiff-0.1.18 → gptdiff-0.1.21}/gptdiff.egg-info/requires.txt +1 -1
- {gptdiff-0.1.18 → gptdiff-0.1.21}/setup.py +2 -2
- gptdiff-0.1.21/tests/test_swallow_reasoning.py +156 -0
- {gptdiff-0.1.18 → gptdiff-0.1.21}/LICENSE.txt +0 -0
- {gptdiff-0.1.18 → gptdiff-0.1.21}/README.md +0 -0
- {gptdiff-0.1.18 → gptdiff-0.1.21}/gptdiff/__init__.py +0 -0
- {gptdiff-0.1.18 → gptdiff-0.1.21}/gptdiff/gptpatch.py +0 -0
- {gptdiff-0.1.18 → gptdiff-0.1.21}/gptdiff.egg-info/dependency_links.txt +0 -0
- {gptdiff-0.1.18 → gptdiff-0.1.21}/gptdiff.egg-info/entry_points.txt +0 -0
- {gptdiff-0.1.18 → gptdiff-0.1.21}/gptdiff.egg-info/top_level.txt +0 -0
- {gptdiff-0.1.18 → gptdiff-0.1.21}/setup.cfg +0 -0
- {gptdiff-0.1.18 → gptdiff-0.1.21}/tests/test_applydiff.py +0 -0
- {gptdiff-0.1.18 → gptdiff-0.1.21}/tests/test_applydiff_edgecases.py +0 -0
- {gptdiff-0.1.18 → gptdiff-0.1.21}/tests/test_diff_parse.py +0 -0
- {gptdiff-0.1.18 → gptdiff-0.1.21}/tests/test_failing_case.py +0 -0
- {gptdiff-0.1.18 → gptdiff-0.1.21}/tests/test_parse_diff_per_file.py +0 -0
- {gptdiff-0.1.18 → gptdiff-0.1.21}/tests/test_smartapply.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.2
|
2
2
|
Name: gptdiff
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.21
|
4
4
|
Summary: A tool to generate and apply git diffs using LLMs
|
5
5
|
Author: 255labs
|
6
6
|
Classifier: License :: OSI Approved :: MIT License
|
@@ -10,7 +10,7 @@ Description-Content-Type: text/markdown
|
|
10
10
|
License-File: LICENSE.txt
|
11
11
|
Requires-Dist: openai>=1.0.0
|
12
12
|
Requires-Dist: tiktoken>=0.5.0
|
13
|
-
Requires-Dist:
|
13
|
+
Requires-Dist: ai-agent-toolbox>=0.1.15
|
14
14
|
Provides-Extra: test
|
15
15
|
Requires-Dist: pytest; extra == "test"
|
16
16
|
Requires-Dist: pytest-mock; extra == "test"
|
@@ -202,7 +202,7 @@ def call_llm_for_diff(system_prompt, user_prompt, files_content, model, temperat
|
|
202
202
|
tool_prompt = formatter.usage_prompt(toolbox)
|
203
203
|
system_prompt += "\n"+tool_prompt
|
204
204
|
|
205
|
-
if
|
205
|
+
if 'gemini' in model:
|
206
206
|
user_prompt = system_prompt+"\n"+user_prompt
|
207
207
|
|
208
208
|
messages = [
|
@@ -241,6 +241,9 @@ def call_llm_for_diff(system_prompt, user_prompt, files_content, model, temperat
|
|
241
241
|
cost = (prompt_tokens / 1_000_000 * cost_per_million_prompt_tokens) + (completion_tokens / 1_000_000 * cost_per_million_completion_tokens)
|
242
242
|
|
243
243
|
full_response = response.choices[0].message.content.strip()
|
244
|
+
full_response, reasoning = swallow_reasoning(full_response)
|
245
|
+
if reasoning and len(reasoning) > 0:
|
246
|
+
print("Swallowed reasoning", reasoning)
|
244
247
|
|
245
248
|
events = parser.parse(full_response)
|
246
249
|
for event in events:
|
@@ -643,6 +646,9 @@ def call_llm_for_apply_with_think_tool_available(file_path, original_content, fi
|
|
643
646
|
formatter = FlatXMLPromptFormatter(tag="think")
|
644
647
|
toolbox = create_think_toolbox()
|
645
648
|
full_response = call_llm_for_apply(file_path, original_content, file_diff, model, api_key=api_key, base_url=base_url, extra_prompt=extra_prompt, max_tokens=max_tokens)
|
649
|
+
full_response, reasoning = swallow_reasoning(full_response)
|
650
|
+
if reasoning and len(reasoning) > 0:
|
651
|
+
print("Swallowed reasoning", reasoning)
|
646
652
|
notool_response = ""
|
647
653
|
events = parser.parse(full_response)
|
648
654
|
is_in_tool = False
|
@@ -707,7 +713,7 @@ Diff to apply:
|
|
707
713
|
```"""
|
708
714
|
if extra_prompt:
|
709
715
|
user_prompt += f"\n\n{extra_prompt}"
|
710
|
-
if
|
716
|
+
if 'gemini' in model:
|
711
717
|
user_prompt = system_prompt+"\n"+user_prompt
|
712
718
|
messages = [
|
713
719
|
{"role": "system", "content": system_prompt},
|
@@ -967,5 +973,35 @@ def main():
|
|
967
973
|
print(f"Total tokens: {total_tokens}")
|
968
974
|
#print(f"Total cost: ${cost:.4f}")
|
969
975
|
|
976
|
+
def swallow_reasoning(full_response: str) -> (str, str):
|
977
|
+
"""
|
978
|
+
Extracts and swallows the chain-of-thought reasoning section from the full LLM response.
|
979
|
+
Assumes the reasoning block starts with a line beginning with "> Reasoning"
|
980
|
+
and ends with a line matching 'Reasoned for <number> seconds'.
|
981
|
+
|
982
|
+
Returns:
|
983
|
+
A tuple (final_content, reasoning) where:
|
984
|
+
- final_content: The response with the reasoning block removed.
|
985
|
+
- reasoning: The extracted reasoning block, or an empty string if not found.
|
986
|
+
"""
|
987
|
+
pattern = re.compile(
|
988
|
+
r"(?P<reasoning>>\s*Reasoning.*?Reasoned.*?seconds)",
|
989
|
+
re.DOTALL
|
990
|
+
)
|
991
|
+
match = pattern.search(full_response)
|
992
|
+
if match:
|
993
|
+
raw_reasoning = match.group("reasoning")
|
994
|
+
# Remove any leading '+' characters and extra whitespace from each line
|
995
|
+
reasoning_lines = [line.lstrip('+').strip() for line in raw_reasoning.splitlines()]
|
996
|
+
reasoning = "\n".join(reasoning_lines).strip()
|
997
|
+
|
998
|
+
# Remove the reasoning block from the response using its exact span
|
999
|
+
final_content = full_response[:match.start()] + full_response[match.end():]
|
1000
|
+
final_content = final_content.strip()
|
1001
|
+
else:
|
1002
|
+
reasoning = ""
|
1003
|
+
final_content = full_response.strip()
|
1004
|
+
return final_content, reasoning
|
1005
|
+
|
970
1006
|
if __name__ == "__main__":
|
971
|
-
main()
|
1007
|
+
main()
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.2
|
2
2
|
Name: gptdiff
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.21
|
4
4
|
Summary: A tool to generate and apply git diffs using LLMs
|
5
5
|
Author: 255labs
|
6
6
|
Classifier: License :: OSI Approved :: MIT License
|
@@ -10,7 +10,7 @@ Description-Content-Type: text/markdown
|
|
10
10
|
License-File: LICENSE.txt
|
11
11
|
Requires-Dist: openai>=1.0.0
|
12
12
|
Requires-Dist: tiktoken>=0.5.0
|
13
|
-
Requires-Dist:
|
13
|
+
Requires-Dist: ai-agent-toolbox>=0.1.15
|
14
14
|
Provides-Extra: test
|
15
15
|
Requires-Dist: pytest; extra == "test"
|
16
16
|
Requires-Dist: pytest-mock; extra == "test"
|
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
|
|
2
2
|
|
3
3
|
setup(
|
4
4
|
name='gptdiff',
|
5
|
-
version='0.1.
|
5
|
+
version='0.1.21',
|
6
6
|
description='A tool to generate and apply git diffs using LLMs',
|
7
7
|
author='255labs',
|
8
8
|
packages=find_packages(), # Use find_packages() to automatically discover packages
|
@@ -12,7 +12,7 @@ setup(
|
|
12
12
|
install_requires=[
|
13
13
|
'openai>=1.0.0',
|
14
14
|
'tiktoken>=0.5.0',
|
15
|
-
'
|
15
|
+
'ai-agent-toolbox>=0.1.15'
|
16
16
|
],
|
17
17
|
extras_require={
|
18
18
|
'test': ['pytest', 'pytest-mock'],
|
@@ -0,0 +1,156 @@
|
|
1
|
+
import pytest
|
2
|
+
|
3
|
+
from gptdiff.gptdiff import swallow_reasoning
|
4
|
+
|
5
|
+
def test_swallow_reasoning_extraction():
|
6
|
+
llm_response = (
|
7
|
+
"+> Reasoning\n"
|
8
|
+
"+None\n"
|
9
|
+
"+Reasoned about summary drawer button 변경 for 15 seconds\n"
|
10
|
+
"+def new():\n"
|
11
|
+
"```"
|
12
|
+
)
|
13
|
+
final_content, reasoning = swallow_reasoning(llm_response)
|
14
|
+
expected_reasoning = (
|
15
|
+
"> Reasoning\n"
|
16
|
+
"**Applying the diff**\n"
|
17
|
+
"I'm piecing together how to efficiently apply a diff to a file...\n"
|
18
|
+
"**Returning the result**\n"
|
19
|
+
"I'm finalizing the method to apply the diff updates...\n"
|
20
|
+
"Reasoned for 6 seconds"
|
21
|
+
)
|
22
|
+
assert reasoning == expected_reasoning
|
23
|
+
# The final content should no longer contain the reasoning block.
|
24
|
+
assert expected_reasoning not in final_content
|
25
|
+
# And it should contain the diff block.
|
26
|
+
assert "```diff" in final_content
|
27
|
+
|
28
|
+
|
29
|
+
def test_swallow_reasoning_with_untested_response():
|
30
|
+
llm_response = (
|
31
|
+
"> Reasoning\n"
|
32
|
+
"**Considering the request**\n"
|
33
|
+
"I’m noting that the user wants me to apply a diff to a file and return the result in a block, ensuring the entire file is included.\n"
|
34
|
+
"**Ensuring comprehensive inclusion**\n"
|
35
|
+
"I'm making sure the entire file is included when presenting the result in a block, following the user's request carefully.\n"
|
36
|
+
"**Ensuring clarity**\n"
|
37
|
+
"I’m integrating the diff into the file and ensuring the entire file is returned as requested. This approach maintains precision and clarity in the response.\n"
|
38
|
+
"**Refining the response**\n"
|
39
|
+
"I’m focusing on how to structure the response by carefully integrating the diff and ensuring the entire file is included in a clear block format.\n"
|
40
|
+
"**Connecting the pieces**\n"
|
41
|
+
"I'm mapping out how to apply the diff to the file carefully and ensure the entire file is incorporated into the final block.\n"
|
42
|
+
"Reasoned for a few seconds\n"
|
43
|
+
"\n"
|
44
|
+
"```diff\n"
|
45
|
+
"--- a/file.py\n"
|
46
|
+
"+++ b/file.py\n"
|
47
|
+
"@@ -1,2 +1,2 @@\n"
|
48
|
+
"-def old():\n"
|
49
|
+
"+def new():\n"
|
50
|
+
"```"
|
51
|
+
)
|
52
|
+
final_content, reasoning = swallow_reasoning(llm_response)
|
53
|
+
|
54
|
+
expected_reasoning = (
|
55
|
+
"> Reasoning\n"
|
56
|
+
"**Considering the request**\n"
|
57
|
+
"I’m noting that the user wants me to apply a diff to a file and return the result in a block, ensuring the entire file is included.\n"
|
58
|
+
"**Ensuring comprehensive inclusion**\n"
|
59
|
+
"I'm making sure the entire file is included when presenting the result in a block, following the user's request carefully.\n"
|
60
|
+
"**Ensuring clarity**\n"
|
61
|
+
"I’m integrating the diff into the file and ensuring the entire file is returned as requested. This approach maintains precision and clarity in the response.\n"
|
62
|
+
"**Refining the response**\n"
|
63
|
+
"I’m focusing on how to structure the response by carefully integrating the diff and ensuring the entire file is included in a clear block format.\n"
|
64
|
+
"**Connecting the pieces**\n"
|
65
|
+
"I'm mapping out how to apply the diff to the file carefully and ensure the entire file is incorporated into the final block.\n"
|
66
|
+
"Reasoned for a few seconds"
|
67
|
+
)
|
68
|
+
|
69
|
+
assert reasoning == expected_reasoning
|
70
|
+
# The final content should no longer contain the reasoning block.
|
71
|
+
assert expected_reasoning not in final_content
|
72
|
+
# And it should contain the diff block.
|
73
|
+
assert "```diff" in final_content
|
74
|
+
|
75
|
+
def test_swallow_reasoning_extraction():
|
76
|
+
llm_response = (
|
77
|
+
"> Reasoning\n"
|
78
|
+
"**Applying the diff**\n"
|
79
|
+
"I'm piecing together how to efficiently apply a diff to a file...\n"
|
80
|
+
"**Returning the result**\n"
|
81
|
+
"I'm finalizing the method to apply the diff updates...\n"
|
82
|
+
"Reasoned for 6 seconds\n"
|
83
|
+
"\n"
|
84
|
+
"```diff\n"
|
85
|
+
"--- a/file.py\n"
|
86
|
+
"+++ b/file.py\n"
|
87
|
+
"@@ -1,2 +1,2 @@\n"
|
88
|
+
"-def old():\n"
|
89
|
+
"+def new():\n"
|
90
|
+
"```"
|
91
|
+
)
|
92
|
+
final_content, reasoning = swallow_reasoning(llm_response)
|
93
|
+
expected_reasoning = (
|
94
|
+
"> Reasoning\n"
|
95
|
+
"**Applying the diff**\n"
|
96
|
+
"I'm piecing together how to efficiently apply a diff to a file...\n"
|
97
|
+
"**Returning the result**\n"
|
98
|
+
"I'm finalizing the method to apply the diff updates...\n"
|
99
|
+
"Reasoned for 6 seconds"
|
100
|
+
)
|
101
|
+
assert reasoning == expected_reasoning
|
102
|
+
# The final content should no longer contain the reasoning block.
|
103
|
+
assert expected_reasoning not in final_content
|
104
|
+
# And it should contain the diff block.
|
105
|
+
assert "```diff" in final_content
|
106
|
+
|
107
|
+
|
108
|
+
def test_swallow_reasoning_no_reasoning():
|
109
|
+
llm_response = (
|
110
|
+
"```diff\n"
|
111
|
+
"--- a/file.py\n"
|
112
|
+
"+++ b/file.py\n"
|
113
|
+
"@@ -1,2 +1,2 @@\n"
|
114
|
+
"-def old():\n"
|
115
|
+
"+def new():\n"
|
116
|
+
"```"
|
117
|
+
)
|
118
|
+
final_content, reasoning = swallow_reasoning(llm_response)
|
119
|
+
assert reasoning == ""
|
120
|
+
assert final_content == llm_response.strip()
|
121
|
+
|
122
|
+
def test_swallow_reasoning_inline_newlines():
|
123
|
+
llm_response = (
|
124
|
+
"Prefix text before reasoning and some inline content "
|
125
|
+
"> Reasoning\n"
|
126
|
+
"Inline line 1\n"
|
127
|
+
"Inline line 2\n"
|
128
|
+
"Reasoned for 2 seconds "
|
129
|
+
"and then suffix text.\n"
|
130
|
+
"```diff\n"
|
131
|
+
"--- a/inline.py\n"
|
132
|
+
"+++ b/inline.py\n"
|
133
|
+
"@@ -1,2 +1,2 @@\n"
|
134
|
+
"-print('Old')\n"
|
135
|
+
"+print('New')\n"
|
136
|
+
"```"
|
137
|
+
)
|
138
|
+
final_content, reasoning = swallow_reasoning(llm_response)
|
139
|
+
expected_reasoning = (
|
140
|
+
"> Reasoning\n"
|
141
|
+
"Inline line 1\n"
|
142
|
+
"Inline line 2\n"
|
143
|
+
"Reasoned for 2 seconds"
|
144
|
+
)
|
145
|
+
# Count the newlines in the extracted reasoning block.
|
146
|
+
newline_count = reasoning.count('\n')
|
147
|
+
# There should be 3 newline characters: after "> Reasoning", after "Inline line 1", and after "Inline line 2"
|
148
|
+
assert newline_count == 3, f"Expected 3 newlines, got {newline_count}"
|
149
|
+
assert reasoning == expected_reasoning
|
150
|
+
# Ensure the reasoning block is removed from the final content.
|
151
|
+
assert expected_reasoning not in final_content
|
152
|
+
# Verify that surrounding content remains.
|
153
|
+
assert "Prefix text before reasoning" in final_content
|
154
|
+
assert "and then suffix text." in final_content
|
155
|
+
# Verify that the diff block is still present.
|
156
|
+
assert "```diff" in final_content
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|