gptdiff 0.1.18__py3-none-any.whl → 0.1.21__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- gptdiff/gptdiff.py +39 -3
- {gptdiff-0.1.18.dist-info → gptdiff-0.1.21.dist-info}/METADATA +2 -2
- gptdiff-0.1.21.dist-info/RECORD +9 -0
- gptdiff-0.1.18.dist-info/RECORD +0 -9
- {gptdiff-0.1.18.dist-info → gptdiff-0.1.21.dist-info}/LICENSE.txt +0 -0
- {gptdiff-0.1.18.dist-info → gptdiff-0.1.21.dist-info}/WHEEL +0 -0
- {gptdiff-0.1.18.dist-info → gptdiff-0.1.21.dist-info}/entry_points.txt +0 -0
- {gptdiff-0.1.18.dist-info → gptdiff-0.1.21.dist-info}/top_level.txt +0 -0
gptdiff/gptdiff.py
CHANGED
@@ -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"
|
@@ -0,0 +1,9 @@
|
|
1
|
+
gptdiff/__init__.py,sha256=o1hrK4GFvbfKcHPlLVArz4OunE3euIicEBYaLrdDo0k,198
|
2
|
+
gptdiff/gptdiff.py,sha256=kDp7gDgBydfKxNm73QIT54AKnv117cZdXhRYQnfJm6A,39426
|
3
|
+
gptdiff/gptpatch.py,sha256=Z8CWWIfIL2o7xPLVdhzN5GSyJq0vsK4XQRzu4hMWNQk,2194
|
4
|
+
gptdiff-0.1.21.dist-info/LICENSE.txt,sha256=zCJk7yUYpMjFvlipi1dKtaljF8WdZ2NASndBYYbU8BY,1228
|
5
|
+
gptdiff-0.1.21.dist-info/METADATA,sha256=Y5O4deytuqvxRV4WaK2vAw9jFuz0OdR3Rxm3lIBNxHk,8785
|
6
|
+
gptdiff-0.1.21.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
7
|
+
gptdiff-0.1.21.dist-info/entry_points.txt,sha256=0VlVNr-gc04a3SZD5_qKIBbtg_L5P2x3xlKE5ftcdkc,82
|
8
|
+
gptdiff-0.1.21.dist-info/top_level.txt,sha256=XNkQkQGINaDndEwRxg8qToOrJ9coyfAb-EHrSUXzdCE,8
|
9
|
+
gptdiff-0.1.21.dist-info/RECORD,,
|
gptdiff-0.1.18.dist-info/RECORD
DELETED
@@ -1,9 +0,0 @@
|
|
1
|
-
gptdiff/__init__.py,sha256=o1hrK4GFvbfKcHPlLVArz4OunE3euIicEBYaLrdDo0k,198
|
2
|
-
gptdiff/gptdiff.py,sha256=ZBkgPTcCDumOD7JcWxXDdhh8qykEJb31_AsxRJhRlCE,37876
|
3
|
-
gptdiff/gptpatch.py,sha256=Z8CWWIfIL2o7xPLVdhzN5GSyJq0vsK4XQRzu4hMWNQk,2194
|
4
|
-
gptdiff-0.1.18.dist-info/LICENSE.txt,sha256=zCJk7yUYpMjFvlipi1dKtaljF8WdZ2NASndBYYbU8BY,1228
|
5
|
-
gptdiff-0.1.18.dist-info/METADATA,sha256=vI9eBGXnzwiS67yxnZ6Op6lzm8ssLTq-KSLPWKjxL8w,8785
|
6
|
-
gptdiff-0.1.18.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
7
|
-
gptdiff-0.1.18.dist-info/entry_points.txt,sha256=0VlVNr-gc04a3SZD5_qKIBbtg_L5P2x3xlKE5ftcdkc,82
|
8
|
-
gptdiff-0.1.18.dist-info/top_level.txt,sha256=XNkQkQGINaDndEwRxg8qToOrJ9coyfAb-EHrSUXzdCE,8
|
9
|
-
gptdiff-0.1.18.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|