gptdiff 0.1.16__py3-none-any.whl → 0.1.20__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
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 model == "gemini-2.0-flash-thinking-exp-01-21":
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
@@ -697,17 +703,17 @@ def call_llm_for_apply(file_path, original_content, file_diff, model, api_key=No
697
703
  4. You must return the entire file. It overwrites the existing file."""
698
704
  user_prompt = f"""File: {file_path}
699
705
  File contents:
700
- <filecontents>
706
+ ```
701
707
  {original_content}
702
- </filecontents>
708
+ ```
703
709
 
704
710
  Diff to apply:
705
- <diff>
711
+ ```diff
706
712
  {file_diff}
707
- </diff>"""
713
+ ```"""
708
714
  if extra_prompt:
709
715
  user_prompt += f"\n\n{extra_prompt}"
710
- if model == "gemini-2.0-flash-thinking-exp-01-21":
716
+ if 'gemini' in model:
711
717
  user_prompt = system_prompt+"\n"+user_prompt
712
718
  messages = [
713
719
  {"role": "system", "content": system_prompt},
@@ -867,7 +873,7 @@ def main():
867
873
  project_files.extend(load_project_files(additional_path, project_dir))
868
874
 
869
875
  if args.prepend:
870
- prepend = args.prepend
876
+ prepend = args.prepend+"\n"
871
877
  else:
872
878
  prepend = ""
873
879
 
@@ -885,10 +891,10 @@ def main():
885
891
  # If the specified prepend path does not exist, treat the value as literal content.
886
892
  prepend = prepend
887
893
 
888
- if not args.call and not args.apply:
889
- system_prompt = prepend + f"Output a git diff into a ```diff block"
890
- else:
891
- system_prompt = prepend + f"Output a git diff into a <diff> block."
894
+ if prepend != "":
895
+ prepend += "\n"
896
+
897
+ system_prompt = prepend + f"Output a git diff into a ```diff block"
892
898
 
893
899
  files_content = ""
894
900
  for file, content in project_files:
@@ -967,5 +973,29 @@ 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 for \d+\s*seconds)",
989
+ re.DOTALL
990
+ )
991
+ match = pattern.search(full_response)
992
+ if match:
993
+ reasoning = match.group("reasoning").strip()
994
+ final_content = full_response.replace(reasoning, "").strip()
995
+ else:
996
+ reasoning = ""
997
+ final_content = full_response.strip()
998
+ return final_content, reasoning
999
+
970
1000
  if __name__ == "__main__":
971
1001
  main()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: gptdiff
3
- Version: 0.1.16
3
+ Version: 0.1.20
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
@@ -0,0 +1,9 @@
1
+ gptdiff/__init__.py,sha256=o1hrK4GFvbfKcHPlLVArz4OunE3euIicEBYaLrdDo0k,198
2
+ gptdiff/gptdiff.py,sha256=LKBq_E9GanyDv-2FBbbWvP7JUl2Ignb6zvkD2GqmdPo,39074
3
+ gptdiff/gptpatch.py,sha256=Z8CWWIfIL2o7xPLVdhzN5GSyJq0vsK4XQRzu4hMWNQk,2194
4
+ gptdiff-0.1.20.dist-info/LICENSE.txt,sha256=zCJk7yUYpMjFvlipi1dKtaljF8WdZ2NASndBYYbU8BY,1228
5
+ gptdiff-0.1.20.dist-info/METADATA,sha256=v8-LTu-NVLikIexMY5RDEf2t2VTAh7t_3hch379VzFA,8785
6
+ gptdiff-0.1.20.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
7
+ gptdiff-0.1.20.dist-info/entry_points.txt,sha256=0VlVNr-gc04a3SZD5_qKIBbtg_L5P2x3xlKE5ftcdkc,82
8
+ gptdiff-0.1.20.dist-info/top_level.txt,sha256=XNkQkQGINaDndEwRxg8qToOrJ9coyfAb-EHrSUXzdCE,8
9
+ gptdiff-0.1.20.dist-info/RECORD,,
@@ -1,9 +0,0 @@
1
- gptdiff/__init__.py,sha256=o1hrK4GFvbfKcHPlLVArz4OunE3euIicEBYaLrdDo0k,198
2
- gptdiff/gptdiff.py,sha256=wvPbw_M4tXKpg6tTng4EsF4X5lBh1GM5KD6PJyRxoOc,37981
3
- gptdiff/gptpatch.py,sha256=Z8CWWIfIL2o7xPLVdhzN5GSyJq0vsK4XQRzu4hMWNQk,2194
4
- gptdiff-0.1.16.dist-info/LICENSE.txt,sha256=zCJk7yUYpMjFvlipi1dKtaljF8WdZ2NASndBYYbU8BY,1228
5
- gptdiff-0.1.16.dist-info/METADATA,sha256=hhm98oDVM9WIzcNJ9IHcM6auJcGBf46XmLJ9JPLUe_E,8785
6
- gptdiff-0.1.16.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
7
- gptdiff-0.1.16.dist-info/entry_points.txt,sha256=0VlVNr-gc04a3SZD5_qKIBbtg_L5P2x3xlKE5ftcdkc,82
8
- gptdiff-0.1.16.dist-info/top_level.txt,sha256=XNkQkQGINaDndEwRxg8qToOrJ9coyfAb-EHrSUXzdCE,8
9
- gptdiff-0.1.16.dist-info/RECORD,,