gpt-pr 0.4.1__tar.gz → 0.5.0__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.
Potentially problematic release.
This version of gpt-pr might be problematic. Click here for more details.
- {gpt-pr-0.4.1 → gpt-pr-0.5.0}/PKG-INFO +1 -1
- {gpt-pr-0.4.1 → gpt-pr-0.5.0}/README.md +13 -13
- {gpt-pr-0.4.1 → gpt-pr-0.5.0}/gpt_pr.egg-info/PKG-INFO +1 -1
- {gpt-pr-0.4.1 → gpt-pr-0.5.0}/gpt_pr.egg-info/requires.txt +3 -3
- {gpt-pr-0.4.1 → gpt-pr-0.5.0}/gptpr/config.py +6 -3
- {gpt-pr-0.4.1 → gpt-pr-0.5.0}/gptpr/prdata.py +49 -32
- {gpt-pr-0.4.1 → gpt-pr-0.5.0}/gptpr/test_config.py +21 -4
- gpt-pr-0.5.0/gptpr/version.py +1 -0
- {gpt-pr-0.4.1 → gpt-pr-0.5.0}/requirements.txt +3 -3
- gpt-pr-0.4.1/gptpr/version.py +0 -1
- {gpt-pr-0.4.1 → gpt-pr-0.5.0}/MANIFEST.in +0 -0
- {gpt-pr-0.4.1 → gpt-pr-0.5.0}/gpt_pr.egg-info/SOURCES.txt +0 -0
- {gpt-pr-0.4.1 → gpt-pr-0.5.0}/gpt_pr.egg-info/dependency_links.txt +0 -0
- {gpt-pr-0.4.1 → gpt-pr-0.5.0}/gpt_pr.egg-info/entry_points.txt +0 -0
- {gpt-pr-0.4.1 → gpt-pr-0.5.0}/gpt_pr.egg-info/not-zip-safe +0 -0
- {gpt-pr-0.4.1 → gpt-pr-0.5.0}/gpt_pr.egg-info/top_level.txt +0 -0
- {gpt-pr-0.4.1 → gpt-pr-0.5.0}/gptpr/__init__.py +0 -0
- {gpt-pr-0.4.1 → gpt-pr-0.5.0}/gptpr/checkversion.py +0 -0
- {gpt-pr-0.4.1 → gpt-pr-0.5.0}/gptpr/consolecolor.py +0 -0
- {gpt-pr-0.4.1 → gpt-pr-0.5.0}/gptpr/gh.py +0 -0
- {gpt-pr-0.4.1 → gpt-pr-0.5.0}/gptpr/gitutil.py +0 -0
- {gpt-pr-0.4.1 → gpt-pr-0.5.0}/gptpr/main.py +0 -0
- {gpt-pr-0.4.1 → gpt-pr-0.5.0}/gptpr/test_checkversion.py +0 -0
- {gpt-pr-0.4.1 → gpt-pr-0.5.0}/gptpr/test_prdata.py +0 -0
- {gpt-pr-0.4.1 → gpt-pr-0.5.0}/setup.cfg +0 -0
- {gpt-pr-0.4.1 → gpt-pr-0.5.0}/setup.py +0 -0
|
@@ -33,14 +33,12 @@ You can install and use GPT-PR in one of two ways. Choose the option that best s
|
|
|
33
33
|
|
|
34
34
|
### Option 1: Using `pip install` (Recommended)
|
|
35
35
|
|
|
36
|
-
1. Install the package:
|
|
36
|
+
1. Install OR Update the package:
|
|
37
37
|
|
|
38
38
|
```bash
|
|
39
39
|
pip install -U gpt-pr
|
|
40
40
|
```
|
|
41
41
|
|
|
42
|
-
> Note: Use this command to **update** gpt-pr package to the latest version.
|
|
43
|
-
|
|
44
42
|
2. Setup API keys for GitHub and OpenAI, take a look at [Configuration](#configuration).
|
|
45
43
|
|
|
46
44
|
3. Inside the Git repository you are working on, ensure you have pushed your branch to origin, then run:
|
|
@@ -49,7 +47,7 @@ pip install -U gpt-pr
|
|
|
49
47
|
gpt-pr --help
|
|
50
48
|
```
|
|
51
49
|
|
|
52
|
-
### Option 2: Cloning the code
|
|
50
|
+
### Option 2: Cloning the code (NOT recommended)
|
|
53
51
|
|
|
54
52
|
1. Clone the repository:
|
|
55
53
|
|
|
@@ -74,6 +72,14 @@ pipenv run python ~/workplace/gpt-pr/gptpr/main.py --help
|
|
|
74
72
|
|
|
75
73
|
## Configuration
|
|
76
74
|
|
|
75
|
+
### See all configs available
|
|
76
|
+
|
|
77
|
+
To print all default configs and what is being used, just run:
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
gpt-pr-config print
|
|
81
|
+
```
|
|
82
|
+
|
|
77
83
|
### Setting up GitHub Token (`GH_TOKEN`)
|
|
78
84
|
|
|
79
85
|
GPT-PR tool will look for a `GH_TOKEN` in current shell env var OR in gpt-pr config file (at `~/.gpt-pr.ini`).
|
|
@@ -125,18 +131,12 @@ export OPENAI_API_KEY=your_generated_api_key_here
|
|
|
125
131
|
To change OpenAI model, just run:
|
|
126
132
|
|
|
127
133
|
```bash
|
|
128
|
-
gpt-pr-config set openai_model gpt-
|
|
134
|
+
gpt-pr-config set openai_model gpt-4o-mini
|
|
129
135
|
```
|
|
130
136
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
### See all configs available
|
|
134
|
-
|
|
135
|
-
To print all default configs and what is being used, just run:
|
|
137
|
+
> Obs.: `gpt-4o-mini` already is the default model of the project
|
|
136
138
|
|
|
137
|
-
|
|
138
|
-
gpt-pr-config print
|
|
139
|
-
```
|
|
139
|
+
To see a full list of available models, access [OpenAI Models Documentation](https://platform.openai.com/docs/models)
|
|
140
140
|
|
|
141
141
|
### Reset config
|
|
142
142
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
cffi==1.15.1
|
|
2
|
-
cryptography==
|
|
2
|
+
cryptography==43.0.0
|
|
3
3
|
fire==0.6.0
|
|
4
4
|
pycparser==2.21
|
|
5
5
|
wcwidth==0.2.13
|
|
@@ -12,7 +12,7 @@ prompt-toolkit==3.0.43
|
|
|
12
12
|
openai==1.14.0
|
|
13
13
|
|
|
14
14
|
[:python_version < "3.11"]
|
|
15
|
-
exceptiongroup==1.2.
|
|
15
|
+
exceptiongroup==1.2.2
|
|
16
16
|
|
|
17
17
|
[:python_version < "3.8"]
|
|
18
18
|
cached-property==1.5.2
|
|
@@ -30,7 +30,7 @@ deprecated==1.2.14
|
|
|
30
30
|
idna==3.7
|
|
31
31
|
|
|
32
32
|
[:python_version >= "3.6"]
|
|
33
|
-
certifi==2024.
|
|
33
|
+
certifi==2024.7.4
|
|
34
34
|
distro==1.9.0
|
|
35
35
|
pynacl==1.5.0
|
|
36
36
|
wrapt==1.16.0
|
|
@@ -7,7 +7,7 @@ def config_command_example(name, value_sample):
|
|
|
7
7
|
return f'gpt-pr-config set {name} {value_sample}'
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
CONFIG_README_SECTION = 'https://github.com/alissonperez/gpt-pr?tab=readme-ov-file#
|
|
10
|
+
CONFIG_README_SECTION = 'https://github.com/alissonperez/gpt-pr?tab=readme-ov-file#configuration'
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
class Config:
|
|
@@ -18,8 +18,11 @@ class Config:
|
|
|
18
18
|
# Github
|
|
19
19
|
'GH_TOKEN': '',
|
|
20
20
|
|
|
21
|
+
# LLM input MAX Tokens
|
|
22
|
+
'INPUT_MAX_TOKENS': '15000',
|
|
23
|
+
|
|
21
24
|
# Open AI info
|
|
22
|
-
'OPENAI_MODEL': 'gpt-4o',
|
|
25
|
+
'OPENAI_MODEL': 'gpt-4o-mini',
|
|
23
26
|
'OPENAI_API_KEY': '',
|
|
24
27
|
}
|
|
25
28
|
|
|
@@ -66,7 +69,7 @@ class Config:
|
|
|
66
69
|
|
|
67
70
|
def set_user_config(self, name, value):
|
|
68
71
|
self.load()
|
|
69
|
-
self._config['user'][name] = value
|
|
72
|
+
self._config['user'][name] = str(value)
|
|
70
73
|
|
|
71
74
|
def reset_user_config(self, name):
|
|
72
75
|
self.load()
|
|
@@ -8,7 +8,6 @@ from gptpr.config import config
|
|
|
8
8
|
import gptpr.consolecolor as cc
|
|
9
9
|
|
|
10
10
|
TOKENIZER_RATIO = 4
|
|
11
|
-
MAX_TOKENS = 6000
|
|
12
11
|
|
|
13
12
|
DEFAULT_PR_TEMPLATE = ('### Ref. [Link]\n\n## What was done?\n[Fill here]\n\n'
|
|
14
13
|
'## How was it done?\n[Fill here]\n\n'
|
|
@@ -52,6 +51,10 @@ def _get_open_ai_key():
|
|
|
52
51
|
return api_key
|
|
53
52
|
|
|
54
53
|
|
|
54
|
+
def _count_tokens(text):
|
|
55
|
+
return len(text.split(' '))
|
|
56
|
+
|
|
57
|
+
|
|
55
58
|
@dataclass
|
|
56
59
|
class PrData():
|
|
57
60
|
branch_info: BranchInfo
|
|
@@ -91,6 +94,35 @@ functions = [
|
|
|
91
94
|
|
|
92
95
|
|
|
93
96
|
def get_pr_data(branch_info):
|
|
97
|
+
client = OpenAI(api_key=_get_open_ai_key())
|
|
98
|
+
|
|
99
|
+
messages = _get_messages(branch_info)
|
|
100
|
+
|
|
101
|
+
openai_model = config.get_user_config('OPENAI_MODEL')
|
|
102
|
+
print('Using OpenAI model:', cc.yellow(openai_model))
|
|
103
|
+
|
|
104
|
+
chat_completion = client.chat.completions.create(
|
|
105
|
+
messages=messages,
|
|
106
|
+
model=openai_model,
|
|
107
|
+
functions=functions,
|
|
108
|
+
function_call={'name': 'create_pr'},
|
|
109
|
+
temperature=0,
|
|
110
|
+
max_tokens=1000,
|
|
111
|
+
top_p=1,
|
|
112
|
+
frequency_penalty=0,
|
|
113
|
+
presence_penalty=0
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
arguments = _parse_json(chat_completion.choices[0].message.function_call.arguments)
|
|
117
|
+
|
|
118
|
+
return PrData(
|
|
119
|
+
branch_info=branch_info,
|
|
120
|
+
title=arguments['title'],
|
|
121
|
+
body=arguments['description']
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def _get_messages(branch_info):
|
|
94
126
|
system_content = ('You are a development assistant designed to craft Git pull requests '
|
|
95
127
|
'by incorporating information from main and secondary commits, diff changes, '
|
|
96
128
|
'and adhering to a provided PR template. Your output includes a complete PR '
|
|
@@ -108,45 +140,30 @@ def get_pr_data(branch_info):
|
|
|
108
140
|
messages.append({'role': 'user', 'content': 'main commits: ' + '\n'.join(branch_info.highlight_commits)})
|
|
109
141
|
messages.append({'role': 'user', 'content': 'secondary commits: ' + '\n'.join(branch_info.commits)})
|
|
110
142
|
else:
|
|
111
|
-
messages.append({'role': 'user', 'content': 'git commits: ' + '\n'.join(branch_info.commits)})
|
|
143
|
+
messages.append({'role': 'user', 'content': 'git commits: \n' + '\n'.join(branch_info.commits)})
|
|
112
144
|
|
|
113
145
|
messages.append({'role': 'user', 'content': 'PR template:\n' + _get_pr_template()})
|
|
114
146
|
|
|
115
|
-
|
|
147
|
+
joined_messages = '\n'.join([m['content'] for m in messages])
|
|
148
|
+
current_total_tokens = _count_tokens(joined_messages)
|
|
116
149
|
|
|
117
|
-
|
|
118
|
-
raise Exception(f'Current total length {current_total_length} is greater than max tokens {MAX_TOKENS}')
|
|
150
|
+
input_max_tokens = int(config.get_user_config('INPUT_MAX_TOKENS'))
|
|
119
151
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
152
|
+
if current_total_tokens > input_max_tokens:
|
|
153
|
+
exp_message = (f'Length of {current_total_tokens} tokens for basic prompt '
|
|
154
|
+
f'(description and commits) is greater than max tokens {input_max_tokens} '
|
|
155
|
+
'(config \'input_max_tokens\')')
|
|
156
|
+
raise Exception(exp_message)
|
|
157
|
+
|
|
158
|
+
total_tokens_with_diff = current_total_tokens + _count_tokens(branch_info.diff)
|
|
159
|
+
if total_tokens_with_diff > input_max_tokens:
|
|
160
|
+
print_msg = (f'Length git changes with diff is too big (total is {total_tokens_with_diff}, '
|
|
161
|
+
f'\'input_max_tokens\' config is {input_max_tokens}).')
|
|
162
|
+
print(print_msg, cc.red('Skipping changes diff content...'))
|
|
123
163
|
else:
|
|
124
164
|
messages.append({'role': 'user', 'content': 'Diff changes:\n' + branch_info.diff})
|
|
125
165
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
openai_model = config.get_user_config('OPENAI_MODEL')
|
|
129
|
-
print('Using OpenAI model:', cc.yellow(openai_model))
|
|
130
|
-
|
|
131
|
-
chat_completion = client.chat.completions.create(
|
|
132
|
-
messages=messages,
|
|
133
|
-
model=openai_model,
|
|
134
|
-
functions=functions,
|
|
135
|
-
function_call={'name': 'create_pr'},
|
|
136
|
-
temperature=0,
|
|
137
|
-
max_tokens=512,
|
|
138
|
-
top_p=1,
|
|
139
|
-
frequency_penalty=0,
|
|
140
|
-
presence_penalty=0
|
|
141
|
-
)
|
|
142
|
-
|
|
143
|
-
arguments = _parse_json(chat_completion.choices[0].message.function_call.arguments)
|
|
144
|
-
|
|
145
|
-
return PrData(
|
|
146
|
-
branch_info=branch_info,
|
|
147
|
-
title=arguments['title'],
|
|
148
|
-
body=arguments['description']
|
|
149
|
-
)
|
|
166
|
+
return messages
|
|
150
167
|
|
|
151
168
|
|
|
152
169
|
def _parse_json(content):
|
|
@@ -30,7 +30,7 @@ def test_init_config_file(temp_config):
|
|
|
30
30
|
assert os.path.isfile(os.path.join(str(temp_dir), config.config_filename))
|
|
31
31
|
|
|
32
32
|
_check_config(config, temp_dir, [
|
|
33
|
-
('DEFAULT', 'OPENAI_MODEL', 'gpt-4o'),
|
|
33
|
+
('DEFAULT', 'OPENAI_MODEL', 'gpt-4o-mini'),
|
|
34
34
|
('DEFAULT', 'OPENAI_API_KEY', ''),
|
|
35
35
|
])
|
|
36
36
|
|
|
@@ -66,6 +66,21 @@ def test_set_user_config(temp_config):
|
|
|
66
66
|
])
|
|
67
67
|
|
|
68
68
|
|
|
69
|
+
def test_set_user_config_with_int_value(temp_config):
|
|
70
|
+
config, temp_dir = temp_config
|
|
71
|
+
|
|
72
|
+
config.set_user_config('INPUT_MAX_TOKENS', 100)
|
|
73
|
+
config.persist()
|
|
74
|
+
|
|
75
|
+
# Read the configuration file and verify its contents
|
|
76
|
+
config_to_test = configparser.ConfigParser()
|
|
77
|
+
config_to_test.read(os.path.join(str(temp_dir), config.config_filename))
|
|
78
|
+
|
|
79
|
+
_check_config(config, temp_dir, [
|
|
80
|
+
('user', 'INPUT_MAX_TOKENS', '100'),
|
|
81
|
+
])
|
|
82
|
+
|
|
83
|
+
|
|
69
84
|
def test_all_values(temp_config):
|
|
70
85
|
config, temp_dir = temp_config
|
|
71
86
|
|
|
@@ -73,10 +88,12 @@ def test_all_values(temp_config):
|
|
|
73
88
|
|
|
74
89
|
assert all_values == [
|
|
75
90
|
('DEFAULT', 'gh_token', ''),
|
|
76
|
-
('DEFAULT', '
|
|
91
|
+
('DEFAULT', 'input_max_tokens', '15000'),
|
|
92
|
+
('DEFAULT', 'openai_model', 'gpt-4o-mini'),
|
|
77
93
|
('DEFAULT', 'openai_api_key', ''),
|
|
78
94
|
('user', 'gh_token', ''),
|
|
79
|
-
('user', '
|
|
95
|
+
('user', 'input_max_tokens', '15000'),
|
|
96
|
+
('user', 'openai_model', 'gpt-4o-mini'),
|
|
80
97
|
('user', 'openai_api_key', ''),
|
|
81
98
|
]
|
|
82
99
|
|
|
@@ -94,6 +111,6 @@ def test_reset_user_config(temp_config):
|
|
|
94
111
|
config_to_test.read(os.path.join(str(temp_dir), config.config_filename))
|
|
95
112
|
|
|
96
113
|
_check_config(config, temp_dir, [
|
|
97
|
-
('user', 'OPENAI_MODEL', 'gpt-4o'),
|
|
114
|
+
('user', 'OPENAI_MODEL', 'gpt-4o-mini'),
|
|
98
115
|
('user', 'OPENAI_API_KEY', ''),
|
|
99
116
|
])
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.5.0"
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
annotated-types==0.5.0; python_version >= '3.7'
|
|
3
3
|
anyio==3.7.1; python_version >= '3.7'
|
|
4
4
|
cached-property==1.5.2; python_version < '3.8'
|
|
5
|
-
certifi==2024.
|
|
5
|
+
certifi==2024.7.4; python_version >= '3.6'
|
|
6
6
|
cffi==1.15.1
|
|
7
7
|
charset-normalizer==3.3.2; python_full_version >= '3.7.0'
|
|
8
|
-
cryptography==
|
|
8
|
+
cryptography==43.0.0
|
|
9
9
|
deprecated==1.2.14; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
|
|
10
10
|
distro==1.9.0; python_version >= '3.6'
|
|
11
|
-
exceptiongroup==1.2.
|
|
11
|
+
exceptiongroup==1.2.2; python_version < '3.11'
|
|
12
12
|
fire==0.6.0
|
|
13
13
|
gitdb==4.0.11; python_version >= '3.7'
|
|
14
14
|
gitpython==3.1.42; python_version >= '3.7'
|
gpt-pr-0.4.1/gptpr/version.py
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.4.1"
|
|
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
|
|
File without changes
|
|
File without changes
|