prgen-cli 0.3.0__tar.gz → 0.4.1__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.
- {prgen_cli-0.3.0 → prgen_cli-0.4.1}/PKG-INFO +20 -4
- {prgen_cli-0.3.0 → prgen_cli-0.4.1}/README.md +17 -1
- {prgen_cli-0.3.0 → prgen_cli-0.4.1}/pyproject.toml +3 -3
- {prgen_cli-0.3.0 → prgen_cli-0.4.1}/src/prgen/api_errors.py +46 -17
- {prgen_cli-0.3.0 → prgen_cli-0.4.1}/src/prgen/cli.py +52 -7
- prgen_cli-0.4.1/src/prgen/http_debug.py +223 -0
- prgen_cli-0.4.1/src/prgen/providers/gemini_provider.py +58 -0
- {prgen_cli-0.3.0 → prgen_cli-0.4.1}/src/prgen/providers/ollama_provider.py +30 -2
- prgen_cli-0.4.1/src/prgen/providers/openai_provider.py +60 -0
- {prgen_cli-0.3.0 → prgen_cli-0.4.1}/src/prgen_cli.egg-info/PKG-INFO +20 -4
- {prgen_cli-0.3.0 → prgen_cli-0.4.1}/src/prgen_cli.egg-info/SOURCES.txt +1 -0
- prgen_cli-0.3.0/src/prgen/providers/gemini_provider.py +0 -28
- prgen_cli-0.3.0/src/prgen/providers/openai_provider.py +0 -27
- {prgen_cli-0.3.0 → prgen_cli-0.4.1}/LICENSE +0 -0
- {prgen_cli-0.3.0 → prgen_cli-0.4.1}/setup.cfg +0 -0
- {prgen_cli-0.3.0 → prgen_cli-0.4.1}/src/prgen/__main__.py +0 -0
- {prgen_cli-0.3.0 → prgen_cli-0.4.1}/src/prgen/about.py +0 -0
- {prgen_cli-0.3.0 → prgen_cli-0.4.1}/src/prgen/config.py +0 -0
- {prgen_cli-0.3.0 → prgen_cli-0.4.1}/src/prgen/defaults.py +0 -0
- {prgen_cli-0.3.0 → prgen_cli-0.4.1}/src/prgen/git_utils.py +0 -0
- {prgen_cli-0.3.0 → prgen_cli-0.4.1}/src/prgen/prompting.py +0 -0
- {prgen_cli-0.3.0 → prgen_cli-0.4.1}/src/prgen/prompts/pr_description.txt +0 -0
- {prgen_cli-0.3.0 → prgen_cli-0.4.1}/src/prgen/ui.py +0 -0
- {prgen_cli-0.3.0 → prgen_cli-0.4.1}/src/prgen_cli.egg-info/dependency_links.txt +0 -0
- {prgen_cli-0.3.0 → prgen_cli-0.4.1}/src/prgen_cli.egg-info/entry_points.txt +0 -0
- {prgen_cli-0.3.0 → prgen_cli-0.4.1}/src/prgen_cli.egg-info/requires.txt +0 -0
- {prgen_cli-0.3.0 → prgen_cli-0.4.1}/src/prgen_cli.egg-info/top_level.txt +0 -0
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: prgen-cli
|
|
3
|
-
Version: 0.
|
|
4
|
-
Summary: Generate PR titles and descriptions from git diff
|
|
3
|
+
Version: 0.4.1
|
|
4
|
+
Summary: Generate PR titles and descriptions from git diff using LLMs
|
|
5
5
|
Author: Jean Paul Fernandez
|
|
6
6
|
License-Expression: GPL-3.0-only
|
|
7
7
|
Project-URL: Homepage, https://github.com/jpxoi/prgen
|
|
8
8
|
Project-URL: Repository, https://github.com/jpxoi/prgen
|
|
9
9
|
Project-URL: Issues, https://github.com/jpxoi/prgen/issues
|
|
10
|
-
Keywords: cli,git,pull-request,diff,llm,openai,gemini
|
|
10
|
+
Keywords: cli,git,pull-request,diff,llm,openai,gemini,ollama
|
|
11
11
|
Classifier: Development Status :: 4 - Beta
|
|
12
12
|
Classifier: Environment :: Console
|
|
13
13
|
Classifier: Intended Audience :: Developers
|
|
@@ -28,7 +28,7 @@ Dynamic: license-file
|
|
|
28
28
|
|
|
29
29
|
Generate a pull request title and description from `git diff` and commit history.
|
|
30
30
|
|
|
31
|
-

|
|
31
|
+

|
|
32
32
|
|
|
33
33
|
**Author:** Jean Paul Fernandez · [github.com/jpxoi/prgen](https://github.com/jpxoi/prgen)
|
|
34
34
|
|
|
@@ -196,6 +196,7 @@ Built-in defaults:
|
|
|
196
196
|
| `--model` | unset | Overrides tier selection; required for Ollama |
|
|
197
197
|
| `--context` | `none` | Extra text merged into the prompt |
|
|
198
198
|
| `--pull` | `false` | Only relevant for Ollama |
|
|
199
|
+
| `--verbose`, `-v` | `false` | Print usage, git size, and API response headers to stderr |
|
|
199
200
|
|
|
200
201
|
Config-file defaults apply only when you omit the matching flag:
|
|
201
202
|
|
|
@@ -246,12 +247,27 @@ Add extra context:
|
|
|
246
247
|
prgen --context "Focus on customer-facing impact and rollout notes."
|
|
247
248
|
```
|
|
248
249
|
|
|
250
|
+
Inspect API response headers (useful on rate-limit errors):
|
|
251
|
+
|
|
252
|
+
```bash
|
|
253
|
+
prgen --provider openai --verbose
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
With `--verbose`, prgen prints to stderr:
|
|
257
|
+
|
|
258
|
+
- provider, model, git base, commit count, and prompt size
|
|
259
|
+
- token usage (OpenAI / Gemini) or eval counts (Ollama)
|
|
260
|
+
- HTTP status and useful response headers (rate limits, request id)
|
|
261
|
+
|
|
262
|
+
Transport headers are omitted. Authorization values and API keys in URLs are redacted.
|
|
263
|
+
|
|
249
264
|
## Behavior Notes
|
|
250
265
|
|
|
251
266
|
- prgen validates that `--base` resolves before generating anything
|
|
252
267
|
- if there are no commits and no file changes vs the base ref, prgen exits with an error
|
|
253
268
|
- when `--provider ollama --pull` is used, prgen can download the model automatically
|
|
254
269
|
- when stderr is a TTY, loading states and Ollama downloads use Rich UI output
|
|
270
|
+
- `--verbose` prints usage and API response headers after the call (or after an error), including rate-limit metadata when the provider sends it
|
|
255
271
|
|
|
256
272
|
## Development
|
|
257
273
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Generate a pull request title and description from `git diff` and commit history.
|
|
4
4
|
|
|
5
|
-

|
|
5
|
+

|
|
6
6
|
|
|
7
7
|
**Author:** Jean Paul Fernandez · [github.com/jpxoi/prgen](https://github.com/jpxoi/prgen)
|
|
8
8
|
|
|
@@ -170,6 +170,7 @@ Built-in defaults:
|
|
|
170
170
|
| `--model` | unset | Overrides tier selection; required for Ollama |
|
|
171
171
|
| `--context` | `none` | Extra text merged into the prompt |
|
|
172
172
|
| `--pull` | `false` | Only relevant for Ollama |
|
|
173
|
+
| `--verbose`, `-v` | `false` | Print usage, git size, and API response headers to stderr |
|
|
173
174
|
|
|
174
175
|
Config-file defaults apply only when you omit the matching flag:
|
|
175
176
|
|
|
@@ -220,12 +221,27 @@ Add extra context:
|
|
|
220
221
|
prgen --context "Focus on customer-facing impact and rollout notes."
|
|
221
222
|
```
|
|
222
223
|
|
|
224
|
+
Inspect API response headers (useful on rate-limit errors):
|
|
225
|
+
|
|
226
|
+
```bash
|
|
227
|
+
prgen --provider openai --verbose
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
With `--verbose`, prgen prints to stderr:
|
|
231
|
+
|
|
232
|
+
- provider, model, git base, commit count, and prompt size
|
|
233
|
+
- token usage (OpenAI / Gemini) or eval counts (Ollama)
|
|
234
|
+
- HTTP status and useful response headers (rate limits, request id)
|
|
235
|
+
|
|
236
|
+
Transport headers are omitted. Authorization values and API keys in URLs are redacted.
|
|
237
|
+
|
|
223
238
|
## Behavior Notes
|
|
224
239
|
|
|
225
240
|
- prgen validates that `--base` resolves before generating anything
|
|
226
241
|
- if there are no commits and no file changes vs the base ref, prgen exits with an error
|
|
227
242
|
- when `--provider ollama --pull` is used, prgen can download the model automatically
|
|
228
243
|
- when stderr is a TTY, loading states and Ollama downloads use Rich UI output
|
|
244
|
+
- `--verbose` prints usage and API response headers after the call (or after an error), including rate-limit metadata when the provider sends it
|
|
229
245
|
|
|
230
246
|
## Development
|
|
231
247
|
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "prgen-cli"
|
|
3
|
-
version = "0.
|
|
4
|
-
description = "Generate PR titles and descriptions from git diff"
|
|
3
|
+
version = "0.4.1"
|
|
4
|
+
description = "Generate PR titles and descriptions from git diff using LLMs"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.10"
|
|
7
7
|
license = "GPL-3.0-only"
|
|
8
8
|
license-files = ["LICENSE"]
|
|
9
9
|
authors = [{ name = "Jean Paul Fernandez" }]
|
|
10
|
-
keywords = ["cli", "git", "pull-request", "diff", "llm", "openai", "gemini"]
|
|
10
|
+
keywords = ["cli", "git", "pull-request", "diff", "llm", "openai", "gemini", "ollama"]
|
|
11
11
|
classifiers = [
|
|
12
12
|
"Development Status :: 4 - Beta",
|
|
13
13
|
"Environment :: Console",
|
|
@@ -4,6 +4,8 @@ from __future__ import annotations
|
|
|
4
4
|
|
|
5
5
|
from typing import Literal
|
|
6
6
|
|
|
7
|
+
from prgen.http_debug import response_header
|
|
8
|
+
|
|
7
9
|
Backend = Literal["openai", "gemini", "ollama"]
|
|
8
10
|
|
|
9
11
|
|
|
@@ -14,12 +16,12 @@ def _trim(msg: str, max_len: int = 220) -> str:
|
|
|
14
16
|
return one[: max_len - 1] + "…"
|
|
15
17
|
|
|
16
18
|
|
|
17
|
-
def format_provider_error(exc: BaseException, *, backend: Backend) -> str:
|
|
19
|
+
def format_provider_error(exc: BaseException, *, backend: Backend, verbose: bool = False) -> str:
|
|
18
20
|
"""Map SDK exceptions to a short stderr-safe line (no traceback)."""
|
|
19
21
|
if backend == "openai":
|
|
20
|
-
return _openai_user_message(exc)
|
|
22
|
+
return _openai_user_message(exc, verbose=verbose)
|
|
21
23
|
if backend == "gemini":
|
|
22
|
-
return _gemini_user_message(exc)
|
|
24
|
+
return _gemini_user_message(exc, verbose=verbose)
|
|
23
25
|
return _ollama_user_message(exc)
|
|
24
26
|
|
|
25
27
|
|
|
@@ -41,24 +43,37 @@ def _ollama_user_message(exc: BaseException) -> str:
|
|
|
41
43
|
return f"Ollama: {_trim(str(exc))}"
|
|
42
44
|
|
|
43
45
|
|
|
44
|
-
def
|
|
46
|
+
def _rate_limit_hint(exc: BaseException, *, fallback: str) -> str:
|
|
47
|
+
retry_after = response_header(exc, "retry-after")
|
|
48
|
+
if retry_after:
|
|
49
|
+
return f"OpenAI: rate limited — retry after {retry_after}s, or check your plan."
|
|
50
|
+
return fallback
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _openai_user_message(exc: BaseException, *, verbose: bool = False) -> str:
|
|
54
|
+
detail_len = 2000 if verbose else 220
|
|
45
55
|
try:
|
|
46
56
|
import openai
|
|
47
57
|
except ImportError:
|
|
48
|
-
return f"OpenAI: {_trim(str(exc))}"
|
|
58
|
+
return f"OpenAI: {_trim(str(exc), detail_len)}"
|
|
49
59
|
|
|
50
60
|
if isinstance(exc, openai.AuthenticationError):
|
|
51
61
|
return "OpenAI: invalid or revoked API key — check OPENAI_API_KEY."
|
|
52
62
|
if isinstance(exc, openai.PermissionDeniedError):
|
|
53
63
|
return "OpenAI: permission denied — account or model may not be allowed."
|
|
54
64
|
if isinstance(exc, openai.RateLimitError):
|
|
55
|
-
|
|
65
|
+
msg = _rate_limit_hint(
|
|
66
|
+
exc, fallback="OpenAI: rate limited — wait and retry, or check your plan."
|
|
67
|
+
)
|
|
68
|
+
if verbose and exc.message:
|
|
69
|
+
return f"{msg} {_trim(exc.message, detail_len)}"
|
|
70
|
+
return msg
|
|
56
71
|
if isinstance(exc, (openai.APIConnectionError, openai.APITimeoutError)):
|
|
57
72
|
return "OpenAI: network error — check your connection and try again."
|
|
58
73
|
if isinstance(exc, openai.NotFoundError):
|
|
59
74
|
return "OpenAI: model not found — check --model / --tier."
|
|
60
75
|
if isinstance(exc, openai.BadRequestError):
|
|
61
|
-
return f"OpenAI: bad request — {_trim(exc.message)}"
|
|
76
|
+
return f"OpenAI: bad request — {_trim(exc.message, detail_len)}"
|
|
62
77
|
if isinstance(exc, openai.APIStatusError):
|
|
63
78
|
sc = exc.status_code
|
|
64
79
|
if sc == 401:
|
|
@@ -68,20 +83,26 @@ def _openai_user_message(exc: BaseException) -> str:
|
|
|
68
83
|
if sc == 404:
|
|
69
84
|
return "OpenAI: not found — model or endpoint unavailable."
|
|
70
85
|
if sc == 429:
|
|
71
|
-
|
|
86
|
+
msg = _rate_limit_hint(
|
|
87
|
+
exc, fallback="OpenAI: too many requests — retry after a short wait."
|
|
88
|
+
)
|
|
89
|
+
if verbose and exc.message:
|
|
90
|
+
return f"{msg} {_trim(exc.message, detail_len)}"
|
|
91
|
+
return msg
|
|
72
92
|
if sc >= 500:
|
|
73
93
|
return "OpenAI: server error — try again later."
|
|
74
|
-
return f"OpenAI: HTTP {sc} — {_trim(exc.message)}"
|
|
94
|
+
return f"OpenAI: HTTP {sc} — {_trim(exc.message, detail_len)}"
|
|
75
95
|
if isinstance(exc, openai.APIError):
|
|
76
|
-
return f"OpenAI: {_trim(exc.message)}"
|
|
77
|
-
return f"OpenAI: {_trim(str(exc))}"
|
|
96
|
+
return f"OpenAI: {_trim(exc.message, detail_len)}"
|
|
97
|
+
return f"OpenAI: {_trim(str(exc), detail_len)}"
|
|
78
98
|
|
|
79
99
|
|
|
80
|
-
def _gemini_user_message(exc: BaseException) -> str:
|
|
100
|
+
def _gemini_user_message(exc: BaseException, *, verbose: bool = False) -> str:
|
|
101
|
+
detail_len = 2000 if verbose else 220
|
|
81
102
|
try:
|
|
82
103
|
from google.genai import errors as genai_errors
|
|
83
104
|
except ImportError:
|
|
84
|
-
return f"Gemini: {_trim(str(exc))}"
|
|
105
|
+
return f"Gemini: {_trim(str(exc), detail_len)}"
|
|
85
106
|
|
|
86
107
|
if isinstance(exc, genai_errors.ClientError):
|
|
87
108
|
code = getattr(exc, "code", None)
|
|
@@ -90,12 +111,20 @@ def _gemini_user_message(exc: BaseException) -> str:
|
|
|
90
111
|
if code == 404:
|
|
91
112
|
return "Gemini: model or resource not found — check --model / --tier."
|
|
92
113
|
if code == 429:
|
|
93
|
-
|
|
114
|
+
retry_after = response_header(exc, "retry-after")
|
|
115
|
+
msg = (
|
|
116
|
+
f"Gemini: rate limited — retry after {retry_after}s."
|
|
117
|
+
if retry_after
|
|
118
|
+
else "Gemini: rate limited — wait and retry."
|
|
119
|
+
)
|
|
120
|
+
if verbose:
|
|
121
|
+
return f"{msg} {_trim(str(exc), detail_len)}"
|
|
122
|
+
return msg
|
|
94
123
|
if code is not None and 400 <= int(code) < 500:
|
|
95
|
-
return f"Gemini: request failed (HTTP {code}). {_trim(str(exc))}"
|
|
124
|
+
return f"Gemini: request failed (HTTP {code}). {_trim(str(exc), detail_len)}"
|
|
96
125
|
if isinstance(exc, genai_errors.ServerError):
|
|
97
126
|
return "Gemini: server error — try again later."
|
|
98
127
|
if isinstance(exc, genai_errors.APIError):
|
|
99
128
|
code = getattr(exc, "code", "?")
|
|
100
|
-
return f"Gemini: API error (HTTP {code}) — {_trim(str(exc))}"
|
|
101
|
-
return f"Gemini: {_trim(str(exc))}"
|
|
129
|
+
return f"Gemini: API error (HTTP {code}) — {_trim(str(exc), detail_len)}"
|
|
130
|
+
return f"Gemini: {_trim(str(exc), detail_len)}"
|
|
@@ -7,7 +7,6 @@ from pathlib import Path
|
|
|
7
7
|
from typing import Annotated, cast
|
|
8
8
|
|
|
9
9
|
import typer
|
|
10
|
-
from click.core import ParameterSource
|
|
11
10
|
from rich import box
|
|
12
11
|
from rich.console import Console
|
|
13
12
|
from rich.panel import Panel
|
|
@@ -37,10 +36,20 @@ from prgen.git_utils import (
|
|
|
37
36
|
git_repo_root,
|
|
38
37
|
verify_base_ref,
|
|
39
38
|
)
|
|
39
|
+
from prgen.http_debug import HttpDebugLog, print_http_debug
|
|
40
40
|
from prgen.prompting import build_prompt, load_prompt_template
|
|
41
41
|
from prgen.ui import loading, print_pr_summary
|
|
42
42
|
|
|
43
43
|
|
|
44
|
+
def _option_from_default(ctx: typer.Context, name: str) -> bool:
|
|
45
|
+
"""True when the user did not pass the option (Click/Typer default).
|
|
46
|
+
|
|
47
|
+
Avoid importing ``click``: recent Typer vendors Click and may not install it.
|
|
48
|
+
"""
|
|
49
|
+
source = ctx.get_parameter_source(name)
|
|
50
|
+
return source is None or getattr(source, "name", "") == "DEFAULT"
|
|
51
|
+
|
|
52
|
+
|
|
44
53
|
def _version_callback(value: bool) -> None:
|
|
45
54
|
if value:
|
|
46
55
|
typer.echo(f"prgen {package_version()}")
|
|
@@ -291,6 +300,7 @@ def run_summarize(
|
|
|
291
300
|
model: str | None,
|
|
292
301
|
context: str,
|
|
293
302
|
ollama_pull_if_missing: bool,
|
|
303
|
+
verbose: bool,
|
|
294
304
|
) -> int:
|
|
295
305
|
try:
|
|
296
306
|
ensure_git_available()
|
|
@@ -359,6 +369,16 @@ def run_summarize(
|
|
|
359
369
|
additional_context=context,
|
|
360
370
|
)
|
|
361
371
|
|
|
372
|
+
debug = HttpDebugLog() if verbose else None
|
|
373
|
+
if verbose:
|
|
374
|
+
commit_count = commits.count("<commit-message")
|
|
375
|
+
print(f"prgen: provider={backend} model={model_id}", file=sys.stderr)
|
|
376
|
+
print(
|
|
377
|
+
f"prgen: git base={base} commits={commit_count} "
|
|
378
|
+
f"diff_chars={len(diff)} prompt_chars={len(prompt)}",
|
|
379
|
+
file=sys.stderr,
|
|
380
|
+
)
|
|
381
|
+
|
|
362
382
|
try:
|
|
363
383
|
if backend == "ollama":
|
|
364
384
|
from prgen.providers.ollama_provider import OllamaProvider
|
|
@@ -366,27 +386,43 @@ def run_summarize(
|
|
|
366
386
|
output = OllamaProvider(
|
|
367
387
|
model=model_id,
|
|
368
388
|
pull_if_missing=ollama_pull_if_missing,
|
|
389
|
+
debug=debug,
|
|
369
390
|
).generate(prompt)
|
|
370
391
|
else:
|
|
371
392
|
with loading(model=model_id):
|
|
372
393
|
if backend == "openai":
|
|
373
394
|
from prgen.providers.openai_provider import OpenAIProvider
|
|
374
395
|
|
|
375
|
-
output = OpenAIProvider(
|
|
396
|
+
output = OpenAIProvider(
|
|
397
|
+
api_key=api_key,
|
|
398
|
+
model=model_id,
|
|
399
|
+
debug=debug,
|
|
400
|
+
).generate(prompt)
|
|
376
401
|
else:
|
|
377
402
|
from prgen.providers.gemini_provider import GeminiProvider
|
|
378
403
|
|
|
379
|
-
output = GeminiProvider(
|
|
404
|
+
output = GeminiProvider(
|
|
405
|
+
api_key=api_key,
|
|
406
|
+
model=model_id,
|
|
407
|
+
debug=debug,
|
|
408
|
+
).generate(prompt)
|
|
380
409
|
except ImportError as exc:
|
|
381
410
|
print(f"prgen: {exc}", file=sys.stderr)
|
|
382
411
|
return 1
|
|
383
412
|
except Exception as exc:
|
|
384
413
|
print(
|
|
385
|
-
|
|
414
|
+
"prgen: "
|
|
415
|
+
+ format_provider_error(exc, backend=cast(Backend, backend), verbose=verbose),
|
|
386
416
|
file=sys.stderr,
|
|
387
417
|
)
|
|
418
|
+
if debug is not None:
|
|
419
|
+
debug.add_exception(exc)
|
|
420
|
+
print_http_debug(debug)
|
|
388
421
|
return 1
|
|
389
422
|
|
|
423
|
+
if debug is not None:
|
|
424
|
+
print_http_debug(debug)
|
|
425
|
+
|
|
390
426
|
summary = extract_tag(output, "summary")
|
|
391
427
|
body = extract_tag(output, "body")
|
|
392
428
|
|
|
@@ -492,15 +528,23 @@ def _root(
|
|
|
492
528
|
help="With --provider ollama, download the model if missing locally.",
|
|
493
529
|
),
|
|
494
530
|
] = False,
|
|
531
|
+
verbose: Annotated[
|
|
532
|
+
bool,
|
|
533
|
+
typer.Option(
|
|
534
|
+
"--verbose",
|
|
535
|
+
"-v",
|
|
536
|
+
help="Print API response headers (rate limits, request id) to stderr.",
|
|
537
|
+
),
|
|
538
|
+
] = False,
|
|
495
539
|
) -> None:
|
|
496
540
|
if ctx.invoked_subcommand is not None:
|
|
497
541
|
return
|
|
498
542
|
cfg_base, cfg_provider, cfg_tier = read_cli_defaults_from_config()
|
|
499
|
-
if ctx
|
|
543
|
+
if _option_from_default(ctx, "base") and cfg_base is not None:
|
|
500
544
|
base = cfg_base
|
|
501
|
-
if ctx
|
|
545
|
+
if _option_from_default(ctx, "provider") and cfg_provider is not None:
|
|
502
546
|
provider = cfg_provider
|
|
503
|
-
if ctx
|
|
547
|
+
if _option_from_default(ctx, "tier") and cfg_tier is not None:
|
|
504
548
|
tier = cfg_tier
|
|
505
549
|
raise typer.Exit(
|
|
506
550
|
run_summarize(
|
|
@@ -511,6 +555,7 @@ def _root(
|
|
|
511
555
|
model=model,
|
|
512
556
|
context=context,
|
|
513
557
|
ollama_pull_if_missing=ollama_pull,
|
|
558
|
+
verbose=verbose,
|
|
514
559
|
)
|
|
515
560
|
)
|
|
516
561
|
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
"""Collect and print HTTP response headers for `--verbose` (rate limits, request id)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import sys
|
|
6
|
+
from dataclasses import dataclass, field
|
|
7
|
+
from typing import Any
|
|
8
|
+
from urllib.parse import parse_qsl, urlencode, urlsplit, urlunsplit
|
|
9
|
+
|
|
10
|
+
# Response headers we surface first (rate-limit + request id).
|
|
11
|
+
_PRIORITY_HEADERS = (
|
|
12
|
+
"retry-after",
|
|
13
|
+
"x-request-id",
|
|
14
|
+
"x-goog-request-id",
|
|
15
|
+
"openai-processing-ms",
|
|
16
|
+
"x-ratelimit-limit-requests",
|
|
17
|
+
"x-ratelimit-remaining-requests",
|
|
18
|
+
"x-ratelimit-reset-requests",
|
|
19
|
+
"x-ratelimit-limit-tokens",
|
|
20
|
+
"x-ratelimit-remaining-tokens",
|
|
21
|
+
"x-ratelimit-reset-tokens",
|
|
22
|
+
"x-ratelimit-limit-project-tokens",
|
|
23
|
+
"x-ratelimit-remaining-project-tokens",
|
|
24
|
+
"x-ratelimit-reset-project-tokens",
|
|
25
|
+
"x-ratelimit-limit",
|
|
26
|
+
"x-ratelimit-remaining",
|
|
27
|
+
"x-ratelimit-reset",
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
_REDACT_HEADERS = frozenset(
|
|
31
|
+
{
|
|
32
|
+
"authorization",
|
|
33
|
+
"proxy-authorization",
|
|
34
|
+
"cookie",
|
|
35
|
+
"set-cookie",
|
|
36
|
+
"x-api-key",
|
|
37
|
+
"api-key",
|
|
38
|
+
"x-goog-api-key",
|
|
39
|
+
}
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
_REDACT_QUERY = frozenset({"key", "api_key", "access_token", "token"})
|
|
43
|
+
|
|
44
|
+
# Transport / CORS noise; keep rate-limit, request id, org, timing, cf-ray.
|
|
45
|
+
_SKIP_HEADERS = frozenset(
|
|
46
|
+
{
|
|
47
|
+
"access-control-allow-origin",
|
|
48
|
+
"access-control-expose-headers",
|
|
49
|
+
"alt-svc",
|
|
50
|
+
"cf-cache-status",
|
|
51
|
+
"connection",
|
|
52
|
+
"content-encoding",
|
|
53
|
+
"content-length",
|
|
54
|
+
"content-type",
|
|
55
|
+
"server",
|
|
56
|
+
"set-cookie",
|
|
57
|
+
"strict-transport-security",
|
|
58
|
+
"transfer-encoding",
|
|
59
|
+
"vary",
|
|
60
|
+
"x-content-type-options",
|
|
61
|
+
"x-frame-options",
|
|
62
|
+
"x-xss-protection",
|
|
63
|
+
}
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
@dataclass(frozen=True)
|
|
68
|
+
class HttpExchange:
|
|
69
|
+
method: str
|
|
70
|
+
url: str
|
|
71
|
+
status_code: int
|
|
72
|
+
headers: tuple[tuple[str, str], ...]
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
@dataclass
|
|
76
|
+
class HttpDebugLog:
|
|
77
|
+
"""Accumulate HTTP exchanges (including SDK retries) and print them later."""
|
|
78
|
+
|
|
79
|
+
exchanges: list[HttpExchange] = field(default_factory=list)
|
|
80
|
+
notes: list[str] = field(default_factory=list)
|
|
81
|
+
|
|
82
|
+
def add_note(self, line: str) -> None:
|
|
83
|
+
text = line.strip()
|
|
84
|
+
if text:
|
|
85
|
+
self.notes.append(text)
|
|
86
|
+
|
|
87
|
+
def add_httpx_response(self, response: object) -> None:
|
|
88
|
+
"""httpx event-hook callback: record one response (headers only)."""
|
|
89
|
+
exchange = _exchange_from_response(response)
|
|
90
|
+
if exchange is None:
|
|
91
|
+
return
|
|
92
|
+
if self.exchanges and self.exchanges[-1] == exchange:
|
|
93
|
+
return
|
|
94
|
+
self.exchanges.append(exchange)
|
|
95
|
+
|
|
96
|
+
def add_exception(self, exc: BaseException) -> None:
|
|
97
|
+
"""Record headers from an SDK error if the hook did not already see them."""
|
|
98
|
+
response = getattr(exc, "response", None)
|
|
99
|
+
if response is None:
|
|
100
|
+
return
|
|
101
|
+
self.add_httpx_response(response)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def format_usage_line(pairs: list[tuple[str, object]]) -> str | None:
|
|
105
|
+
parts: list[str] = []
|
|
106
|
+
for key, value in pairs:
|
|
107
|
+
if value is None or value == "":
|
|
108
|
+
continue
|
|
109
|
+
parts.append(f"{key}={value}")
|
|
110
|
+
if not parts:
|
|
111
|
+
return None
|
|
112
|
+
return "usage " + " ".join(parts)
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def response_header(exc: BaseException, name: str) -> str | None:
|
|
116
|
+
"""Read a response header from an SDK exception (case-insensitive)."""
|
|
117
|
+
response = getattr(exc, "response", None)
|
|
118
|
+
if response is None:
|
|
119
|
+
return None
|
|
120
|
+
headers = getattr(response, "headers", None)
|
|
121
|
+
if headers is None:
|
|
122
|
+
return None
|
|
123
|
+
wanted = name.lower()
|
|
124
|
+
getter = getattr(headers, "get", None)
|
|
125
|
+
if callable(getter):
|
|
126
|
+
try:
|
|
127
|
+
value = getter(name)
|
|
128
|
+
except Exception:
|
|
129
|
+
value = None
|
|
130
|
+
if value is not None:
|
|
131
|
+
text = str(value).strip()
|
|
132
|
+
if text:
|
|
133
|
+
return text
|
|
134
|
+
try:
|
|
135
|
+
pairs = headers.items()
|
|
136
|
+
except Exception:
|
|
137
|
+
return None
|
|
138
|
+
for key, value in pairs:
|
|
139
|
+
if str(key).lower() == wanted:
|
|
140
|
+
text = str(value).strip()
|
|
141
|
+
return text or None
|
|
142
|
+
return None
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def print_http_debug(log: HttpDebugLog) -> None:
|
|
146
|
+
for note in log.notes:
|
|
147
|
+
print(f"prgen: {note}", file=sys.stderr)
|
|
148
|
+
if not log.exchanges:
|
|
149
|
+
return
|
|
150
|
+
for exchange in log.exchanges:
|
|
151
|
+
loc = " ".join(part for part in (exchange.method, exchange.url) if part)
|
|
152
|
+
if loc:
|
|
153
|
+
print(f"prgen: HTTP {exchange.status_code} {loc}", file=sys.stderr)
|
|
154
|
+
else:
|
|
155
|
+
print(f"prgen: HTTP {exchange.status_code}", file=sys.stderr)
|
|
156
|
+
for name, value in exchange.headers:
|
|
157
|
+
print(f" {name}: {value}", file=sys.stderr)
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def sanitize_url(url: str) -> str:
|
|
161
|
+
parts = urlsplit(url)
|
|
162
|
+
if not parts.query:
|
|
163
|
+
return url
|
|
164
|
+
pairs: list[tuple[str, str]] = []
|
|
165
|
+
changed = False
|
|
166
|
+
for key, value in parse_qsl(parts.query, keep_blank_values=True):
|
|
167
|
+
if key.lower() in _REDACT_QUERY:
|
|
168
|
+
pairs.append((key, "REDACTED"))
|
|
169
|
+
changed = True
|
|
170
|
+
else:
|
|
171
|
+
pairs.append((key, value))
|
|
172
|
+
if not changed:
|
|
173
|
+
return url
|
|
174
|
+
return urlunsplit((parts.scheme, parts.netloc, parts.path, urlencode(pairs), parts.fragment))
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
def sanitize_headers(headers: Any) -> tuple[tuple[str, str], ...]:
|
|
178
|
+
items: list[tuple[str, str]] = []
|
|
179
|
+
try:
|
|
180
|
+
pairs = headers.items()
|
|
181
|
+
except Exception:
|
|
182
|
+
return ()
|
|
183
|
+
for key, value in pairs:
|
|
184
|
+
name = str(key)
|
|
185
|
+
if name.lower() in _SKIP_HEADERS:
|
|
186
|
+
continue
|
|
187
|
+
text = str(value)
|
|
188
|
+
if name.lower() in _REDACT_HEADERS:
|
|
189
|
+
text = "<redacted>"
|
|
190
|
+
items.append((name, text))
|
|
191
|
+
return tuple(_sort_headers(items))
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
def _sort_headers(items: list[tuple[str, str]]) -> list[tuple[str, str]]:
|
|
195
|
+
priority = {name: index for index, name in enumerate(_PRIORITY_HEADERS)}
|
|
196
|
+
|
|
197
|
+
def key(item: tuple[str, str]) -> tuple[int, str]:
|
|
198
|
+
lower = item[0].lower()
|
|
199
|
+
if lower in priority:
|
|
200
|
+
return (0, f"{priority[lower]:02d}")
|
|
201
|
+
return (1, lower)
|
|
202
|
+
|
|
203
|
+
return sorted(items, key=key)
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
def _exchange_from_response(response: object) -> HttpExchange | None:
|
|
207
|
+
headers = getattr(response, "headers", None)
|
|
208
|
+
if headers is None:
|
|
209
|
+
return None
|
|
210
|
+
raw_status = getattr(response, "status_code", None)
|
|
211
|
+
try:
|
|
212
|
+
status_code = int(raw_status) if raw_status is not None else 0
|
|
213
|
+
except (TypeError, ValueError):
|
|
214
|
+
status_code = 0
|
|
215
|
+
request = getattr(response, "request", None)
|
|
216
|
+
method = str(getattr(request, "method", "") or "")
|
|
217
|
+
url = sanitize_url(str(getattr(request, "url", None) or getattr(response, "url", "") or ""))
|
|
218
|
+
return HttpExchange(
|
|
219
|
+
method=method,
|
|
220
|
+
url=url,
|
|
221
|
+
status_code=status_code,
|
|
222
|
+
headers=sanitize_headers(headers),
|
|
223
|
+
)
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
|
|
3
|
+
from prgen.defaults import GEMINI_MODELS
|
|
4
|
+
from prgen.http_debug import HttpDebugLog, format_usage_line
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@dataclass
|
|
8
|
+
class GeminiProvider:
|
|
9
|
+
api_key: str
|
|
10
|
+
model: str = GEMINI_MODELS["default"]
|
|
11
|
+
debug: HttpDebugLog | None = None
|
|
12
|
+
|
|
13
|
+
def generate(self, prompt: str) -> str:
|
|
14
|
+
try:
|
|
15
|
+
from google import genai
|
|
16
|
+
from google.genai import types
|
|
17
|
+
except ImportError as exc:
|
|
18
|
+
raise ImportError(
|
|
19
|
+
"The Google GenAI SDK is not installed. Install with: pip install google-genai"
|
|
20
|
+
) from exc
|
|
21
|
+
|
|
22
|
+
http_options = None
|
|
23
|
+
if self.debug is not None:
|
|
24
|
+
http_options = types.HttpOptions(
|
|
25
|
+
client_args={"event_hooks": {"response": [self.debug.add_httpx_response]}},
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
client = genai.Client(api_key=self.api_key, http_options=http_options)
|
|
29
|
+
response = client.models.generate_content(
|
|
30
|
+
model=self.model,
|
|
31
|
+
contents=prompt,
|
|
32
|
+
config=types.GenerateContentConfig(
|
|
33
|
+
max_output_tokens=8192,
|
|
34
|
+
),
|
|
35
|
+
)
|
|
36
|
+
if self.debug is not None:
|
|
37
|
+
_record_gemini_usage(self.debug, response)
|
|
38
|
+
return (response.text or "").strip()
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _record_gemini_usage(debug: HttpDebugLog, response: object) -> None:
|
|
42
|
+
model_version = getattr(response, "model_version", None)
|
|
43
|
+
if model_version:
|
|
44
|
+
debug.add_note(f"model_version {model_version}")
|
|
45
|
+
usage = getattr(response, "usage_metadata", None)
|
|
46
|
+
if usage is None:
|
|
47
|
+
return
|
|
48
|
+
line = format_usage_line(
|
|
49
|
+
[
|
|
50
|
+
("prompt", getattr(usage, "prompt_token_count", None)),
|
|
51
|
+
("candidates", getattr(usage, "candidates_token_count", None)),
|
|
52
|
+
("thoughts", getattr(usage, "thoughts_token_count", None)),
|
|
53
|
+
("cached", getattr(usage, "cached_content_token_count", None)),
|
|
54
|
+
("total", getattr(usage, "total_token_count", None)),
|
|
55
|
+
]
|
|
56
|
+
)
|
|
57
|
+
if line:
|
|
58
|
+
debug.add_note(line)
|
|
@@ -2,6 +2,7 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
from dataclasses import dataclass
|
|
4
4
|
|
|
5
|
+
from prgen.http_debug import HttpDebugLog, format_usage_line
|
|
5
6
|
from prgen.ui import loading, ollama_pull_with_ui
|
|
6
7
|
|
|
7
8
|
|
|
@@ -22,19 +23,28 @@ def _missing_model_error(exc: BaseException) -> bool:
|
|
|
22
23
|
class OllamaProvider:
|
|
23
24
|
model: str
|
|
24
25
|
pull_if_missing: bool = False
|
|
26
|
+
debug: HttpDebugLog | None = None
|
|
25
27
|
|
|
26
28
|
def generate(self, prompt: str) -> str:
|
|
27
29
|
try:
|
|
28
|
-
from ollama import ChatResponse, ResponseError, chat
|
|
30
|
+
from ollama import ChatResponse, Client, ResponseError, chat
|
|
29
31
|
except ImportError as exc:
|
|
30
32
|
raise ImportError(
|
|
31
33
|
"The ollama package is not installed. Install with: pip install ollama"
|
|
32
34
|
) from exc
|
|
33
35
|
|
|
34
36
|
messages = [{"role": "user", "content": prompt}]
|
|
37
|
+
client: Client | None = None
|
|
38
|
+
if self.debug is not None:
|
|
39
|
+
client = Client(event_hooks={"response": [self.debug.add_httpx_response]})
|
|
35
40
|
|
|
36
41
|
def run_chat() -> str:
|
|
37
|
-
|
|
42
|
+
if client is not None:
|
|
43
|
+
response: ChatResponse = client.chat(model=self.model, messages=messages)
|
|
44
|
+
else:
|
|
45
|
+
response = chat(model=self.model, messages=messages)
|
|
46
|
+
if self.debug is not None:
|
|
47
|
+
_record_ollama_usage(self.debug, response)
|
|
38
48
|
return (response.message.content or "").strip()
|
|
39
49
|
|
|
40
50
|
try:
|
|
@@ -46,3 +56,21 @@ class OllamaProvider:
|
|
|
46
56
|
ollama_pull_with_ui(self.model)
|
|
47
57
|
with loading(model=self.model):
|
|
48
58
|
return run_chat()
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def _ns_to_seconds(value: object) -> str | None:
|
|
62
|
+
if not isinstance(value, int | float):
|
|
63
|
+
return None
|
|
64
|
+
return f"{value / 1_000_000_000:.2f}s"
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def _record_ollama_usage(debug: HttpDebugLog, response: object) -> None:
|
|
68
|
+
line = format_usage_line(
|
|
69
|
+
[
|
|
70
|
+
("prompt", getattr(response, "prompt_eval_count", None)),
|
|
71
|
+
("eval", getattr(response, "eval_count", None)),
|
|
72
|
+
("duration", _ns_to_seconds(getattr(response, "total_duration", None))),
|
|
73
|
+
]
|
|
74
|
+
)
|
|
75
|
+
if line:
|
|
76
|
+
debug.add_note(line)
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
|
|
3
|
+
from prgen.defaults import OPENAI_MODELS
|
|
4
|
+
from prgen.http_debug import HttpDebugLog, format_usage_line
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@dataclass
|
|
8
|
+
class OpenAIProvider:
|
|
9
|
+
api_key: str
|
|
10
|
+
model: str = OPENAI_MODELS["default"]
|
|
11
|
+
debug: HttpDebugLog | None = None
|
|
12
|
+
|
|
13
|
+
def generate(self, prompt: str) -> str:
|
|
14
|
+
try:
|
|
15
|
+
from openai import OpenAI
|
|
16
|
+
except ImportError as exc:
|
|
17
|
+
raise ImportError(
|
|
18
|
+
"The OpenAI SDK is not installed. Install with: pip install openai"
|
|
19
|
+
) from exc
|
|
20
|
+
|
|
21
|
+
http_client = None
|
|
22
|
+
if self.debug is not None:
|
|
23
|
+
from openai import DefaultHttpxClient
|
|
24
|
+
|
|
25
|
+
http_client = DefaultHttpxClient(
|
|
26
|
+
event_hooks={"response": [self.debug.add_httpx_response]},
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
try:
|
|
30
|
+
client = OpenAI(api_key=self.api_key, http_client=http_client)
|
|
31
|
+
response = client.responses.create(
|
|
32
|
+
model=self.model,
|
|
33
|
+
input=prompt,
|
|
34
|
+
max_output_tokens=8192,
|
|
35
|
+
)
|
|
36
|
+
if self.debug is not None:
|
|
37
|
+
_record_openai_usage(self.debug, response)
|
|
38
|
+
return response.output_text.strip()
|
|
39
|
+
finally:
|
|
40
|
+
if http_client is not None:
|
|
41
|
+
http_client.close()
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _record_openai_usage(debug: HttpDebugLog, response: object) -> None:
|
|
45
|
+
usage = getattr(response, "usage", None)
|
|
46
|
+
if usage is None:
|
|
47
|
+
return
|
|
48
|
+
input_details = getattr(usage, "input_tokens_details", None)
|
|
49
|
+
output_details = getattr(usage, "output_tokens_details", None)
|
|
50
|
+
line = format_usage_line(
|
|
51
|
+
[
|
|
52
|
+
("input", getattr(usage, "input_tokens", None)),
|
|
53
|
+
("output", getattr(usage, "output_tokens", None)),
|
|
54
|
+
("total", getattr(usage, "total_tokens", None)),
|
|
55
|
+
("cached", getattr(input_details, "cached_tokens", None)),
|
|
56
|
+
("reasoning", getattr(output_details, "reasoning_tokens", None)),
|
|
57
|
+
]
|
|
58
|
+
)
|
|
59
|
+
if line:
|
|
60
|
+
debug.add_note(line)
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: prgen-cli
|
|
3
|
-
Version: 0.
|
|
4
|
-
Summary: Generate PR titles and descriptions from git diff
|
|
3
|
+
Version: 0.4.1
|
|
4
|
+
Summary: Generate PR titles and descriptions from git diff using LLMs
|
|
5
5
|
Author: Jean Paul Fernandez
|
|
6
6
|
License-Expression: GPL-3.0-only
|
|
7
7
|
Project-URL: Homepage, https://github.com/jpxoi/prgen
|
|
8
8
|
Project-URL: Repository, https://github.com/jpxoi/prgen
|
|
9
9
|
Project-URL: Issues, https://github.com/jpxoi/prgen/issues
|
|
10
|
-
Keywords: cli,git,pull-request,diff,llm,openai,gemini
|
|
10
|
+
Keywords: cli,git,pull-request,diff,llm,openai,gemini,ollama
|
|
11
11
|
Classifier: Development Status :: 4 - Beta
|
|
12
12
|
Classifier: Environment :: Console
|
|
13
13
|
Classifier: Intended Audience :: Developers
|
|
@@ -28,7 +28,7 @@ Dynamic: license-file
|
|
|
28
28
|
|
|
29
29
|
Generate a pull request title and description from `git diff` and commit history.
|
|
30
30
|
|
|
31
|
-

|
|
31
|
+

|
|
32
32
|
|
|
33
33
|
**Author:** Jean Paul Fernandez · [github.com/jpxoi/prgen](https://github.com/jpxoi/prgen)
|
|
34
34
|
|
|
@@ -196,6 +196,7 @@ Built-in defaults:
|
|
|
196
196
|
| `--model` | unset | Overrides tier selection; required for Ollama |
|
|
197
197
|
| `--context` | `none` | Extra text merged into the prompt |
|
|
198
198
|
| `--pull` | `false` | Only relevant for Ollama |
|
|
199
|
+
| `--verbose`, `-v` | `false` | Print usage, git size, and API response headers to stderr |
|
|
199
200
|
|
|
200
201
|
Config-file defaults apply only when you omit the matching flag:
|
|
201
202
|
|
|
@@ -246,12 +247,27 @@ Add extra context:
|
|
|
246
247
|
prgen --context "Focus on customer-facing impact and rollout notes."
|
|
247
248
|
```
|
|
248
249
|
|
|
250
|
+
Inspect API response headers (useful on rate-limit errors):
|
|
251
|
+
|
|
252
|
+
```bash
|
|
253
|
+
prgen --provider openai --verbose
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
With `--verbose`, prgen prints to stderr:
|
|
257
|
+
|
|
258
|
+
- provider, model, git base, commit count, and prompt size
|
|
259
|
+
- token usage (OpenAI / Gemini) or eval counts (Ollama)
|
|
260
|
+
- HTTP status and useful response headers (rate limits, request id)
|
|
261
|
+
|
|
262
|
+
Transport headers are omitted. Authorization values and API keys in URLs are redacted.
|
|
263
|
+
|
|
249
264
|
## Behavior Notes
|
|
250
265
|
|
|
251
266
|
- prgen validates that `--base` resolves before generating anything
|
|
252
267
|
- if there are no commits and no file changes vs the base ref, prgen exits with an error
|
|
253
268
|
- when `--provider ollama --pull` is used, prgen can download the model automatically
|
|
254
269
|
- when stderr is a TTY, loading states and Ollama downloads use Rich UI output
|
|
270
|
+
- `--verbose` prints usage and API response headers after the call (or after an error), including rate-limit metadata when the provider sends it
|
|
255
271
|
|
|
256
272
|
## Development
|
|
257
273
|
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
from dataclasses import dataclass
|
|
2
|
-
|
|
3
|
-
from prgen.defaults import GEMINI_MODELS
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
@dataclass
|
|
7
|
-
class GeminiProvider:
|
|
8
|
-
api_key: str
|
|
9
|
-
model: str = GEMINI_MODELS["default"]
|
|
10
|
-
|
|
11
|
-
def generate(self, prompt: str) -> str:
|
|
12
|
-
try:
|
|
13
|
-
from google import genai
|
|
14
|
-
from google.genai import types
|
|
15
|
-
except ImportError as exc:
|
|
16
|
-
raise ImportError(
|
|
17
|
-
"The Google GenAI SDK is not installed. Install with: pip install google-genai"
|
|
18
|
-
) from exc
|
|
19
|
-
|
|
20
|
-
client = genai.Client(api_key=self.api_key)
|
|
21
|
-
response = client.models.generate_content(
|
|
22
|
-
model=self.model,
|
|
23
|
-
contents=prompt,
|
|
24
|
-
config=types.GenerateContentConfig(
|
|
25
|
-
max_output_tokens=8192,
|
|
26
|
-
),
|
|
27
|
-
)
|
|
28
|
-
return (response.text or "").strip()
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
from dataclasses import dataclass
|
|
2
|
-
|
|
3
|
-
from prgen.defaults import OPENAI_MODELS
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
@dataclass
|
|
7
|
-
class OpenAIProvider:
|
|
8
|
-
api_key: str
|
|
9
|
-
model: str = OPENAI_MODELS["default"]
|
|
10
|
-
|
|
11
|
-
def generate(self, prompt: str) -> str:
|
|
12
|
-
try:
|
|
13
|
-
from openai import OpenAI
|
|
14
|
-
except ImportError as exc:
|
|
15
|
-
raise ImportError(
|
|
16
|
-
"The OpenAI SDK is not installed. Install with: pip install openai"
|
|
17
|
-
) from exc
|
|
18
|
-
|
|
19
|
-
client = OpenAI(api_key=self.api_key)
|
|
20
|
-
|
|
21
|
-
response = client.responses.create(
|
|
22
|
-
model=self.model,
|
|
23
|
-
input=prompt,
|
|
24
|
-
max_output_tokens=8192,
|
|
25
|
-
)
|
|
26
|
-
|
|
27
|
-
return response.output_text.strip()
|
|
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
|