code-review-ai-cli 2.2.4__tar.gz → 2.2.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. {code_review_ai_cli-2.2.4 → code_review_ai_cli-2.2.5}/PKG-INFO +1 -1
  2. {code_review_ai_cli-2.2.4 → code_review_ai_cli-2.2.5}/code_review_ai_cli.egg-info/PKG-INFO +1 -1
  3. {code_review_ai_cli-2.2.4 → code_review_ai_cli-2.2.5}/pyproject.toml +1 -1
  4. {code_review_ai_cli-2.2.4 → code_review_ai_cli-2.2.5}/src/llm_client.py +44 -30
  5. {code_review_ai_cli-2.2.4 → code_review_ai_cli-2.2.5}/src/prompts/config.yaml.template +1 -1
  6. {code_review_ai_cli-2.2.4 → code_review_ai_cli-2.2.5}/tests/test_llm_client.py +48 -10
  7. {code_review_ai_cli-2.2.4 → code_review_ai_cli-2.2.5}/README.md +0 -0
  8. {code_review_ai_cli-2.2.4 → code_review_ai_cli-2.2.5}/code_review_ai_cli.egg-info/SOURCES.txt +0 -0
  9. {code_review_ai_cli-2.2.4 → code_review_ai_cli-2.2.5}/code_review_ai_cli.egg-info/dependency_links.txt +0 -0
  10. {code_review_ai_cli-2.2.4 → code_review_ai_cli-2.2.5}/code_review_ai_cli.egg-info/entry_points.txt +0 -0
  11. {code_review_ai_cli-2.2.4 → code_review_ai_cli-2.2.5}/code_review_ai_cli.egg-info/requires.txt +0 -0
  12. {code_review_ai_cli-2.2.4 → code_review_ai_cli-2.2.5}/code_review_ai_cli.egg-info/top_level.txt +0 -0
  13. {code_review_ai_cli-2.2.4 → code_review_ai_cli-2.2.5}/setup.cfg +0 -0
  14. {code_review_ai_cli-2.2.4 → code_review_ai_cli-2.2.5}/src/__init__.py +0 -0
  15. {code_review_ai_cli-2.2.4 → code_review_ai_cli-2.2.5}/src/ai_review.py +0 -0
  16. {code_review_ai_cli-2.2.4 → code_review_ai_cli-2.2.5}/src/config.py +0 -0
  17. {code_review_ai_cli-2.2.4 → code_review_ai_cli-2.2.5}/src/context_extractor.py +0 -0
  18. {code_review_ai_cli-2.2.4 → code_review_ai_cli-2.2.5}/src/formatter.py +0 -0
  19. {code_review_ai_cli-2.2.4 → code_review_ai_cli-2.2.5}/src/git_utils.py +0 -0
  20. {code_review_ai_cli-2.2.4 → code_review_ai_cli-2.2.5}/src/prompt_utils.py +0 -0
  21. {code_review_ai_cli-2.2.4 → code_review_ai_cli-2.2.5}/src/prompts/review_prompt.md.template +0 -0
  22. {code_review_ai_cli-2.2.4 → code_review_ai_cli-2.2.5}/src/tfs_client.py +0 -0
  23. {code_review_ai_cli-2.2.4 → code_review_ai_cli-2.2.5}/src/token_estimator.py +0 -0
  24. {code_review_ai_cli-2.2.4 → code_review_ai_cli-2.2.5}/tests/test_ai_review.py +0 -0
  25. {code_review_ai_cli-2.2.4 → code_review_ai_cli-2.2.5}/tests/test_config.py +0 -0
  26. {code_review_ai_cli-2.2.4 → code_review_ai_cli-2.2.5}/tests/test_context_extractor.py +0 -0
  27. {code_review_ai_cli-2.2.4 → code_review_ai_cli-2.2.5}/tests/test_formatter.py +0 -0
  28. {code_review_ai_cli-2.2.4 → code_review_ai_cli-2.2.5}/tests/test_git_utils.py +0 -0
  29. {code_review_ai_cli-2.2.4 → code_review_ai_cli-2.2.5}/tests/test_prompt_utils.py +0 -0
  30. {code_review_ai_cli-2.2.4 → code_review_ai_cli-2.2.5}/tests/test_tfs_client.py +0 -0
  31. {code_review_ai_cli-2.2.4 → code_review_ai_cli-2.2.5}/tests/test_token_estimator.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: code-review-ai-cli
3
- Version: 2.2.4
3
+ Version: 2.2.5
4
4
  Summary: Automated AI-powered code review CLI for Azure DevOps / TFS Pull Requests
5
5
  License: MIT
6
6
  Keywords: code-review,ai,azure-devops,tfs,pull-request,llm
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: code-review-ai-cli
3
- Version: 2.2.4
3
+ Version: 2.2.5
4
4
  Summary: Automated AI-powered code review CLI for Azure DevOps / TFS Pull Requests
5
5
  License: MIT
6
6
  Keywords: code-review,ai,azure-devops,tfs,pull-request,llm
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "code-review-ai-cli"
7
- version = "2.2.4"
7
+ version = "2.2.5"
8
8
  description = "Automated AI-powered code review CLI for Azure DevOps / TFS Pull Requests"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -591,8 +591,9 @@ class LLMClient:
591
591
  {"role": "user", "content": user_message},
592
592
  ],
593
593
  "max_tokens": self.config.max_tokens,
594
- "temperature": self.config.temperature,
595
594
  }
595
+ if self.config.temperature != 99:
596
+ payload["temperature"] = self.config.temperature
596
597
 
597
598
  return self._http_openai_compatible(url, headers, payload)
598
599
 
@@ -637,10 +638,11 @@ class LLMClient:
637
638
  "parts": [{"text": system_prompt}]
638
639
  },
639
640
  "generationConfig": {
640
- "temperature": self.config.temperature,
641
641
  "maxOutputTokens": self.config.max_tokens,
642
642
  },
643
643
  }
644
+ if self.config.temperature != 99:
645
+ payload["generationConfig"]["temperature"] = self.config.temperature
644
646
 
645
647
  try:
646
648
  resp = requests.post(url, headers=headers, json=payload, timeout=180)
@@ -715,12 +717,13 @@ class LLMClient:
715
717
  payload = {
716
718
  "model": model,
717
719
  "max_tokens": self.config.max_tokens,
718
- "temperature": self.config.temperature,
719
720
  "system": system_prompt,
720
721
  "messages": [
721
722
  {"role": "user", "content": user_message},
722
723
  ],
723
724
  }
725
+ if self.config.temperature != 99:
726
+ payload["temperature"] = self.config.temperature
724
727
 
725
728
  try:
726
729
  resp = requests.post(url, headers=headers, json=payload, timeout=180)
@@ -793,9 +796,10 @@ class LLMClient:
793
796
  {"role": "system", "content": system_prompt},
794
797
  {"role": "user", "content": user_message},
795
798
  ],
796
- "temperature": self.config.temperature,
797
799
  "stream": False,
798
800
  }
801
+ if self.config.temperature != 99:
802
+ payload["temperature"] = self.config.temperature
799
803
 
800
804
  # Ollama does not require an API key, but we add max_tokens if configured
801
805
  if self.config.max_tokens:
@@ -912,8 +916,9 @@ class LLMClient:
912
916
  {"role": "system", "content": system_prompt},
913
917
  {"role": "user", "content": user_message},
914
918
  ],
915
- "temperature": self.config.temperature,
916
919
  }
920
+ if self.config.temperature != 99:
921
+ payload["temperature"] = self.config.temperature
917
922
 
918
923
  # Add max_tokens if configured (some Copilot models
919
924
  # may not support this parameter)
@@ -1028,7 +1033,7 @@ class LLMClient:
1028
1033
  system_prompt: str,
1029
1034
  user_message: str,
1030
1035
  ) -> str:
1031
- """Calls Bedrock InvokeModel using an HTTP Bearer token (long-term API key).
1036
+ """Calls Bedrock Converse using an HTTP Bearer token (long-term API key).
1032
1037
 
1033
1038
  Args:
1034
1039
  region: AWS region, e.g. ``us-east-1``.
@@ -1051,14 +1056,19 @@ class LLMClient:
1051
1056
 
1052
1057
  # The model ARN contains ':' and '/' that must be URL-encoded in the path
1053
1058
  model_encoded = urllib.parse.quote(self.config.model, safe="")
1054
- url = f"https://bedrock-runtime.{region}.amazonaws.com/model/{model_encoded}/invoke"
1059
+ url = f"https://bedrock-runtime.{region}.amazonaws.com/model/{model_encoded}/converse"
1060
+
1061
+ inference_config = {"maxTokens": self.config.max_tokens}
1062
+ if self.config.temperature != 99:
1063
+ inference_config["temperature"] = self.config.temperature
1055
1064
 
1056
1065
  payload = json.dumps({
1057
- "anthropic_version": "bedrock-2023-05-31",
1058
- "max_tokens": self.config.max_tokens,
1059
- "temperature": self.config.temperature,
1060
- "system": system_prompt,
1061
- "messages": [{"role": "user", "content": user_message}],
1066
+ "system": [{"text": system_prompt}],
1067
+ "messages": [{
1068
+ "role": "user",
1069
+ "content": [{"text": user_message}],
1070
+ }],
1071
+ "inferenceConfig": inference_config,
1062
1072
  }, separators=(",", ":"))
1063
1073
 
1064
1074
  headers = {
@@ -1084,10 +1094,9 @@ class LLMClient:
1084
1094
  except ValueError as exc:
1085
1095
  raise LLMError(f"Invalid JSON from Bedrock: {resp.text[:500]}") from exc
1086
1096
 
1087
- content = data.get("content", [])
1097
+ content = data.get("output", {}).get("message", {}).get("content", [])
1088
1098
  text_parts = [
1089
- item["text"] for item in content
1090
- if item.get("type") == "text" and "text" in item
1099
+ item["text"] for item in content if "text" in item
1091
1100
  ]
1092
1101
  text = "\n".join(part for part in text_parts if part).strip()
1093
1102
  if not text:
@@ -1103,7 +1112,7 @@ class LLMClient:
1103
1112
  system_prompt: str,
1104
1113
  user_message: str,
1105
1114
  ) -> str:
1106
- """Calls Bedrock InvokeModel with manual AWS SigV4 HMAC-SHA256 signing.
1115
+ """Calls Bedrock Converse with manual AWS SigV4 HMAC-SHA256 signing.
1107
1116
 
1108
1117
  Equivalent to the C# BedrockLlmClient implementation.
1109
1118
 
@@ -1135,15 +1144,20 @@ class LLMClient:
1135
1144
 
1136
1145
  host = f"bedrock-runtime.{region}.amazonaws.com"
1137
1146
  model_encoded = urllib.parse.quote(self.config.model, safe="")
1138
- endpoint = f"https://{host}/model/{model_encoded}/invoke"
1147
+ endpoint = f"https://{host}/model/{model_encoded}/converse"
1139
1148
  service = "bedrock"
1140
1149
 
1150
+ inference_config = {"maxTokens": self.config.max_tokens}
1151
+ if self.config.temperature != 99:
1152
+ inference_config["temperature"] = self.config.temperature
1153
+
1141
1154
  payload = json.dumps({
1142
- "anthropic_version": "bedrock-2023-05-31",
1143
- "max_tokens": self.config.max_tokens,
1144
- "temperature": self.config.temperature,
1145
- "system": system_prompt,
1146
- "messages": [{"role": "user", "content": user_message}],
1155
+ "system": [{"text": system_prompt}],
1156
+ "messages": [{
1157
+ "role": "user",
1158
+ "content": [{"text": user_message}],
1159
+ }],
1160
+ "inferenceConfig": inference_config,
1147
1161
  }, separators=(",", ":"))
1148
1162
 
1149
1163
  now = datetime.datetime.now(datetime.timezone.utc)
@@ -1157,7 +1171,7 @@ class LLMClient:
1157
1171
  # Splitting by '/' and encoding each segment mirrors the C# SigV4 implementation.
1158
1172
  canonical_uri = "/".join(
1159
1173
  urllib.parse.quote(seg, safe="")
1160
- for seg in f"/model/{self.config.model}/invoke".split("/")
1174
+ for seg in f"/model/{self.config.model}/converse".split("/")
1161
1175
  )
1162
1176
 
1163
1177
  headers_to_sign = {
@@ -1227,10 +1241,9 @@ class LLMClient:
1227
1241
  except ValueError as exc:
1228
1242
  raise LLMError(f"Invalid JSON from Bedrock: {resp.text[:500]}") from exc
1229
1243
 
1230
- content = data.get("content", [])
1244
+ content = data.get("output", {}).get("message", {}).get("content", [])
1231
1245
  text_parts = [
1232
- item["text"] for item in content
1233
- if item.get("type") == "text" and "text" in item
1246
+ item["text"] for item in content if "text" in item
1234
1247
  ]
1235
1248
  text = "\n".join(part for part in text_parts if part).strip()
1236
1249
  if not text:
@@ -1277,6 +1290,10 @@ class LLMClient:
1277
1290
  session = boto3.Session(**session_kwargs)
1278
1291
  client = session.client("bedrock-runtime", region_name=region)
1279
1292
 
1293
+ inference_config = {"maxTokens": self.config.max_tokens}
1294
+ if self.config.temperature != 99:
1295
+ inference_config["temperature"] = self.config.temperature
1296
+
1280
1297
  response = client.converse(
1281
1298
  modelId=self.config.model,
1282
1299
  system=[{"text": system_prompt}],
@@ -1286,10 +1303,7 @@ class LLMClient:
1286
1303
  "content": [{"text": user_message}],
1287
1304
  }
1288
1305
  ],
1289
- inferenceConfig={
1290
- "temperature": self.config.temperature,
1291
- "maxTokens": self.config.max_tokens,
1292
- },
1306
+ inferenceConfig=inference_config,
1293
1307
  )
1294
1308
 
1295
1309
  content = (
@@ -26,7 +26,7 @@ llm:
26
26
  # Maximum tokens in response
27
27
  max_tokens: 4096
28
28
 
29
- # Temperature (0.0 = deterministic, 1.0 = creative)
29
+ # Temperature (0.0 = deterministic, 1.0 = creative, 99 omits it for all models that dont support this)
30
30
  temperature: 0.0
31
31
 
32
32
  # ---------------------------------------------------------------------------
@@ -5,6 +5,7 @@
5
5
 
6
6
  from __future__ import annotations
7
7
 
8
+ import json
8
9
  import re
9
10
  import sys
10
11
  from pathlib import Path
@@ -606,7 +607,10 @@ def test_bedrock_boto3_success_and_error_paths(monkeypatch: pytest.MonkeyPatch)
606
607
  class FakeBedrockClient:
607
608
  """Stub Bedrock runtime client."""
608
609
 
610
+ last_converse_kwargs: dict[str, object] = {}
611
+
609
612
  def converse(self, **kwargs: object) -> dict:
613
+ FakeBedrockClient.last_converse_kwargs = kwargs
610
614
  return {"output": {"message": {"content": [{"text": "bedrock ok"}]}}}
611
615
 
612
616
  class FakeSession:
@@ -638,6 +642,12 @@ def test_bedrock_boto3_success_and_error_paths(monkeypatch: pytest.MonkeyPatch)
638
642
  assert client._call_bedrock("sys", "user") == "bedrock ok"
639
643
  assert client._call_bedrock_boto3("us-east-1", "sys", "user") == "bedrock ok"
640
644
 
645
+ client.config.temperature = 99
646
+ assert client._call_bedrock_boto3("us-east-1", "sys", "user") == "bedrock ok"
647
+ assert FakeBedrockClient.last_converse_kwargs["inferenceConfig"] == {
648
+ "maxTokens": 256,
649
+ }
650
+
641
651
  class BrokenSession(FakeSession):
642
652
  """Session that raises provider-side failures."""
643
653
 
@@ -689,8 +699,8 @@ def test_call_bedrock_routing_dispatches_correct_method(mocker) -> None:
689
699
 
690
700
 
691
701
  def test_call_bedrock_bearer_success_and_errors(monkeypatch: pytest.MonkeyPatch) -> None:
692
- """_call_bedrock_bearer should use Bearer auth, URL-encode the model ARN and parse content."""
693
- model_arn = "arn:aws:bedrock:us-east-1::foundation-model/anthropic.claude-3-sonnet"
702
+ """_call_bedrock_bearer should use the provider-agnostic Converse API."""
703
+ model_arn = "arn:aws:bedrock:us-east-1::foundation-model/openai.gpt-oss-120b-1:0"
694
704
  client = LLMClient(
695
705
  make_llm_config(
696
706
  llm_provider="bedrock",
@@ -703,15 +713,31 @@ def test_call_bedrock_bearer_success_and_errors(monkeypatch: pytest.MonkeyPatch)
703
713
  )
704
714
 
705
715
  # Success path: response parsed correctly, model ARN URL-encoded in URL
706
- success_resp = FakeResponse(json_data={"content": [{"type": "text", "text": "bearer ok"}]})
716
+ success_resp = FakeResponse(
717
+ json_data={"output": {"message": {"content": [{"text": "bearer ok"}]}}}
718
+ )
707
719
  req_module = install_requests_raw(monkeypatch, success_resp)
708
720
  result = client._call_bedrock_bearer("us-east-1", "my-bearer-key", "sys", "user")
709
721
  assert result == "bearer ok"
710
722
  call = req_module._calls[0]
711
723
  assert "arn%3Aaws%3Abedrock" in call["url"] # ':' encoded as %3A
712
- assert "anthropic.claude-3-sonnet" in call["url"]
724
+ assert "openai.gpt-oss-120b-1%3A0" in call["url"]
725
+ assert call["url"].endswith("/converse")
713
726
  assert call["headers"]["Authorization"] == "Bearer my-bearer-key"
714
727
  assert call["headers"]["Content-Type"] == "application/json"
728
+ payload = json.loads(call["data"])
729
+ assert "anthropic_version" not in payload
730
+ assert payload == {
731
+ "system": [{"text": "sys"}],
732
+ "messages": [{"role": "user", "content": [{"text": "user"}]}],
733
+ "inferenceConfig": {"temperature": 0.2, "maxTokens": 256},
734
+ }
735
+
736
+ client.config.temperature = 99
737
+ req_module = install_requests_raw(monkeypatch, success_resp)
738
+ assert client._call_bedrock_bearer("us-east-1", "my-bearer-key", "sys", "user") == "bearer ok"
739
+ sentinel_payload = json.loads(req_module._calls[0]["data"])
740
+ assert sentinel_payload["inferenceConfig"] == {"maxTokens": 256}
715
741
 
716
742
  # 401 → specific authentication error message
717
743
  install_requests_raw(monkeypatch, FakeResponse(status_code=401))
@@ -724,12 +750,12 @@ def test_call_bedrock_bearer_success_and_errors(monkeypatch: pytest.MonkeyPatch)
724
750
  client._call_bedrock_bearer("us-east-1", "my-bearer-key", "sys", "user")
725
751
 
726
752
  # Empty content list → Unexpected response error
727
- install_requests_raw(monkeypatch, FakeResponse(json_data={"content": []}))
753
+ install_requests_raw(monkeypatch, FakeResponse(json_data={"output": {"message": {"content": []}}}))
728
754
  with pytest.raises(LLMError, match="Unexpected Bedrock response"):
729
755
  client._call_bedrock_bearer("us-east-1", "my-bearer-key", "sys", "user")
730
756
 
731
757
  # Content items with no text type → Unexpected response error
732
- install_requests_raw(monkeypatch, FakeResponse(json_data={"content": [{"type": "image", "data": "..."}]}))
758
+ install_requests_raw(monkeypatch, FakeResponse(json_data={"output": {"message": {"content": [{"image": {}}]}}}))
733
759
  with pytest.raises(LLMError, match="Unexpected Bedrock response"):
734
760
  client._call_bedrock_bearer("us-east-1", "my-bearer-key", "sys", "user")
735
761
 
@@ -741,18 +767,20 @@ def test_call_bedrock_bearer_success_and_errors(monkeypatch: pytest.MonkeyPatch)
741
767
 
742
768
 
743
769
  def test_call_bedrock_sigv4_success_and_errors(monkeypatch: pytest.MonkeyPatch) -> None:
744
- """_call_bedrock_sigv4 should add SigV4 headers and parse content correctly."""
770
+ """_call_bedrock_sigv4 should use Converse with correctly signed requests."""
745
771
  client = LLMClient(
746
772
  make_llm_config(
747
773
  llm_provider="bedrock",
748
774
  api_key="",
749
- model="anthropic.claude-3-sonnet",
775
+ model="openai.gpt-oss-120b-1:0",
750
776
  bedrock_region="us-east-1",
751
777
  bedrock_access_key_id="AKID",
752
778
  bedrock_secret_access_key="secret",
753
779
  )
754
780
  )
755
- success_resp = FakeResponse(json_data={"content": [{"type": "text", "text": "sigv4 ok"}]})
781
+ success_resp = FakeResponse(
782
+ json_data={"output": {"message": {"content": [{"text": "sigv4 ok"}]}}}
783
+ )
756
784
 
757
785
  # Success path: SigV4 headers present in request
758
786
  req_module = install_requests_raw(monkeypatch, success_resp)
@@ -763,6 +791,16 @@ def test_call_bedrock_sigv4_success_and_errors(monkeypatch: pytest.MonkeyPatch)
763
791
  assert "x-amz-date" in call["headers"]
764
792
  assert "x-amz-content-sha256" in call["headers"]
765
793
  assert "x-amz-security-token" not in call["headers"]
794
+ assert call["url"].endswith("/converse")
795
+ payload = json.loads(call["data"])
796
+ assert "anthropic_version" not in payload
797
+ assert payload["inferenceConfig"] == {"temperature": 0.2, "maxTokens": 256}
798
+
799
+ client.config.temperature = 99
800
+ req_module = install_requests_raw(monkeypatch, success_resp)
801
+ assert client._call_bedrock_sigv4("us-east-1", "AKID", "secret", "", "sys", "user") == "sigv4 ok"
802
+ sentinel_payload = json.loads(req_module._calls[0]["data"])
803
+ assert sentinel_payload["inferenceConfig"] == {"maxTokens": 256}
766
804
 
767
805
  # Session token is forwarded as x-amz-security-token
768
806
  req_module = install_requests_raw(monkeypatch, success_resp)
@@ -782,7 +820,7 @@ def test_call_bedrock_sigv4_success_and_errors(monkeypatch: pytest.MonkeyPatch)
782
820
  client._call_bedrock_sigv4("us-east-1", "AKID", "secret", "", "sys", "user")
783
821
 
784
822
  # Empty content → Unexpected response error
785
- install_requests_raw(monkeypatch, FakeResponse(json_data={"content": []}))
823
+ install_requests_raw(monkeypatch, FakeResponse(json_data={"output": {"message": {"content": []}}}))
786
824
  with pytest.raises(LLMError, match="Unexpected Bedrock response"):
787
825
  client._call_bedrock_sigv4("us-east-1", "AKID", "secret", "", "sys", "user")
788
826