gpt-pr 0.4.1__py3-none-any.whl → 0.6.0__py3-none-any.whl
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.dist-info → gpt_pr-0.6.0.dist-info}/METADATA +4 -4
- gpt_pr-0.6.0.dist-info/RECORD +17 -0
- gptpr/config.py +10 -3
- gptpr/gh.py +1 -1
- gptpr/prdata.py +60 -34
- gptpr/test_config.py +23 -4
- gptpr/version.py +1 -1
- gpt_pr-0.4.1.dist-info/RECORD +0 -17
- {gpt_pr-0.4.1.dist-info → gpt_pr-0.6.0.dist-info}/WHEEL +0 -0
- {gpt_pr-0.4.1.dist-info → gpt_pr-0.6.0.dist-info}/entry_points.txt +0 -0
- {gpt_pr-0.4.1.dist-info → gpt_pr-0.6.0.dist-info}/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: gpt-pr
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.6.0
|
|
4
4
|
Summary: Automate your GitHub workflow with GPT-PR: an OpenAI powered library for streamlined PR generation.
|
|
5
5
|
Home-page: http://github.com/alissonperez/gpt-pr
|
|
6
6
|
Author: Alisson R. Perez
|
|
@@ -8,20 +8,20 @@ Author-email: alissonperez@outlook.com
|
|
|
8
8
|
License: MIT
|
|
9
9
|
Requires-Python: >=3.7
|
|
10
10
|
Requires-Dist: cffi ==1.15.1
|
|
11
|
-
Requires-Dist: cryptography ==
|
|
11
|
+
Requires-Dist: cryptography ==43.0.0
|
|
12
12
|
Requires-Dist: fire ==0.6.0
|
|
13
13
|
Requires-Dist: pycparser ==2.21
|
|
14
14
|
Requires-Dist: wcwidth ==0.2.13
|
|
15
15
|
Requires-Dist: charset-normalizer ==3.3.2 ; python_full_version >= "3.7.0"
|
|
16
16
|
Requires-Dist: prompt-toolkit ==3.0.43 ; python_full_version >= "3.7.0"
|
|
17
17
|
Requires-Dist: openai ==1.14.0 ; python_full_version >= "3.7.1"
|
|
18
|
-
Requires-Dist: exceptiongroup ==1.2.
|
|
18
|
+
Requires-Dist: exceptiongroup ==1.2.2 ; python_version < "3.11"
|
|
19
19
|
Requires-Dist: cached-property ==1.5.2 ; python_version < "3.8"
|
|
20
20
|
Requires-Dist: importlib-metadata ==6.7.0 ; python_version == "3.7"
|
|
21
21
|
Requires-Dist: six ==1.16.0 ; python_version >= "2.7" and python_version not in "3.0, 3.1, 3.2"
|
|
22
22
|
Requires-Dist: deprecated ==1.2.14 ; python_version >= "2.7" and python_version not in "3.0, 3.1, 3.2, 3.3"
|
|
23
23
|
Requires-Dist: idna ==3.7 ; python_version >= "3.5"
|
|
24
|
-
Requires-Dist: certifi ==2024.
|
|
24
|
+
Requires-Dist: certifi ==2024.7.4 ; python_version >= "3.6"
|
|
25
25
|
Requires-Dist: distro ==1.9.0 ; python_version >= "3.6"
|
|
26
26
|
Requires-Dist: pynacl ==1.5.0 ; python_version >= "3.6"
|
|
27
27
|
Requires-Dist: wrapt ==1.16.0 ; python_version >= "3.6"
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
gptpr/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
gptpr/checkversion.py,sha256=PmbGiYJelecs1Fv2aAZwdr6wn-qDC826nsYI4A6LLvk,2389
|
|
3
|
+
gptpr/config.py,sha256=jOr95rErnk-MByWtC92bpgY2dyVc6bbrjaVoP61oO-s,2822
|
|
4
|
+
gptpr/consolecolor.py,sha256=_JmBMNjIflWMlgP2VkCWu6uQLR9oHBy52uV3TRJJgF4,800
|
|
5
|
+
gptpr/gh.py,sha256=E03xg8UHfZlHJAY-aAYphpgS3xl-FZ2dmI5oBC2XdoA,1136
|
|
6
|
+
gptpr/gitutil.py,sha256=NBD3iRnbFEPRU47w7c5TowwtZieDYkU4zybvv0PoOU0,5783
|
|
7
|
+
gptpr/main.py,sha256=gen_8YXYAUJU0BpzULZ28j9Br6Y9PTqTr9JEm4nwsJI,2694
|
|
8
|
+
gptpr/prdata.py,sha256=Uls18CtkxWlflfHKrB62hT21MTUVabf8JgJ6CxOOccQ,7053
|
|
9
|
+
gptpr/test_checkversion.py,sha256=WtJ3v4MMkFG0Kob0R1wi_nwVhcQFd4mXtKCKZHajEhM,4266
|
|
10
|
+
gptpr/test_config.py,sha256=iL3b-Ypv1TaMQTFb6mrDKw8fPio3WBpMcaFkWbiLdNQ,3369
|
|
11
|
+
gptpr/test_prdata.py,sha256=rSJ-yqOdw-iYdBWyqnA2SXbdrhT8KgIkRTTf9SY1S1g,474
|
|
12
|
+
gptpr/version.py,sha256=cID1jLnC_vj48GgMN6Yb1FA3JsQ95zNmCHmRYE8TFhY,22
|
|
13
|
+
gpt_pr-0.6.0.dist-info/METADATA,sha256=icdIGcBPO4a9U8vYfbR36tKdcKHPo0hfmBpTMimhKv0,2638
|
|
14
|
+
gpt_pr-0.6.0.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
|
15
|
+
gpt_pr-0.6.0.dist-info/entry_points.txt,sha256=WhcbcQXqo5-IGliYWiYMhop4-Wm7bcH2ljFKLWrmO7c,81
|
|
16
|
+
gpt_pr-0.6.0.dist-info/top_level.txt,sha256=DZcbzlsjh4BD8njGcvhOeCZ83U_oYWgCn0w8qx5--04,6
|
|
17
|
+
gpt_pr-0.6.0.dist-info/RECORD,,
|
gptpr/config.py
CHANGED
|
@@ -7,7 +7,8 @@ def config_command_example(name, value_sample):
|
|
|
7
7
|
return f'gpt-pr-config set {name} {value_sample}'
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
CONFIG_PROJECT_REPO_URL = 'https://github.com/alissonperez/gpt-pr'
|
|
11
|
+
CONFIG_README_SECTION = f'{CONFIG_PROJECT_REPO_URL}?tab=readme-ov-file#configuration'
|
|
11
12
|
|
|
12
13
|
|
|
13
14
|
class Config:
|
|
@@ -15,11 +16,17 @@ class Config:
|
|
|
15
16
|
config_filename = '.gpt-pr.ini'
|
|
16
17
|
|
|
17
18
|
_default_config = {
|
|
19
|
+
# Amenities
|
|
20
|
+
'ADD_TOOL_SIGNATURE': 'true', # Add GPT-PR signature to PRs
|
|
21
|
+
|
|
18
22
|
# Github
|
|
19
23
|
'GH_TOKEN': '',
|
|
20
24
|
|
|
25
|
+
# LLM input MAX Tokens
|
|
26
|
+
'INPUT_MAX_TOKENS': '15000',
|
|
27
|
+
|
|
21
28
|
# Open AI info
|
|
22
|
-
'OPENAI_MODEL': 'gpt-4o',
|
|
29
|
+
'OPENAI_MODEL': 'gpt-4o-mini',
|
|
23
30
|
'OPENAI_API_KEY': '',
|
|
24
31
|
}
|
|
25
32
|
|
|
@@ -66,7 +73,7 @@ class Config:
|
|
|
66
73
|
|
|
67
74
|
def set_user_config(self, name, value):
|
|
68
75
|
self.load()
|
|
69
|
-
self._config['user'][name] = value
|
|
76
|
+
self._config['user'][name] = str(value)
|
|
70
77
|
|
|
71
78
|
def reset_user_config(self, name):
|
|
72
79
|
self.load()
|
gptpr/gh.py
CHANGED
|
@@ -30,7 +30,7 @@ def create_pr(pr_data, yield_confirmation):
|
|
|
30
30
|
default=True).execute()
|
|
31
31
|
|
|
32
32
|
if pr_confirmation:
|
|
33
|
-
pr = repo.create_pull(title=pr_data.title, body=pr_data.
|
|
33
|
+
pr = repo.create_pull(title=pr_data.title, body=pr_data.create_body(),
|
|
34
34
|
head=pr_data.branch_info.branch, base=pr_data.branch_info.base_branch)
|
|
35
35
|
print("Pull request created successfully: ", pr.html_url)
|
|
36
36
|
else:
|
gptpr/prdata.py
CHANGED
|
@@ -4,11 +4,10 @@ import os
|
|
|
4
4
|
from openai import OpenAI
|
|
5
5
|
|
|
6
6
|
from gptpr.gitutil import BranchInfo
|
|
7
|
-
from gptpr.config import config
|
|
7
|
+
from gptpr.config import config, CONFIG_PROJECT_REPO_URL
|
|
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
|
|
@@ -64,9 +67,18 @@ class PrData():
|
|
|
64
67
|
f'{cc.bold("Title")}: {cc.yellow(self.title)}',
|
|
65
68
|
f'{cc.bold("Branch name")}: {cc.yellow(self.branch_info.branch)}',
|
|
66
69
|
f'{cc.bold("Base branch")}: {cc.yellow(self.branch_info.base_branch)}',
|
|
67
|
-
f'{cc.bold("PR Description")}:\n{self.
|
|
70
|
+
f'{cc.bold("PR Description")}:\n{self.create_body()}',
|
|
68
71
|
])
|
|
69
72
|
|
|
73
|
+
def create_body(self):
|
|
74
|
+
body = self.body
|
|
75
|
+
|
|
76
|
+
if config.get_user_config('ADD_TOOL_SIGNATURE') == 'true':
|
|
77
|
+
pr_signature = f'Generated by [GPT-PR]({CONFIG_PROJECT_REPO_URL})'
|
|
78
|
+
body += '\n\n---\n\n' + pr_signature
|
|
79
|
+
|
|
80
|
+
return body
|
|
81
|
+
|
|
70
82
|
|
|
71
83
|
functions = [
|
|
72
84
|
{
|
|
@@ -91,6 +103,35 @@ functions = [
|
|
|
91
103
|
|
|
92
104
|
|
|
93
105
|
def get_pr_data(branch_info):
|
|
106
|
+
client = OpenAI(api_key=_get_open_ai_key())
|
|
107
|
+
|
|
108
|
+
messages = _get_messages(branch_info)
|
|
109
|
+
|
|
110
|
+
openai_model = config.get_user_config('OPENAI_MODEL')
|
|
111
|
+
print('Using OpenAI model:', cc.yellow(openai_model))
|
|
112
|
+
|
|
113
|
+
chat_completion = client.chat.completions.create(
|
|
114
|
+
messages=messages,
|
|
115
|
+
model=openai_model,
|
|
116
|
+
functions=functions,
|
|
117
|
+
function_call={'name': 'create_pr'},
|
|
118
|
+
temperature=0,
|
|
119
|
+
max_tokens=1000,
|
|
120
|
+
top_p=1,
|
|
121
|
+
frequency_penalty=0,
|
|
122
|
+
presence_penalty=0
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
arguments = _parse_json(chat_completion.choices[0].message.function_call.arguments)
|
|
126
|
+
|
|
127
|
+
return PrData(
|
|
128
|
+
branch_info=branch_info,
|
|
129
|
+
title=arguments['title'],
|
|
130
|
+
body=arguments['description']
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def _get_messages(branch_info):
|
|
94
135
|
system_content = ('You are a development assistant designed to craft Git pull requests '
|
|
95
136
|
'by incorporating information from main and secondary commits, diff changes, '
|
|
96
137
|
'and adhering to a provided PR template. Your output includes a complete PR '
|
|
@@ -108,45 +149,30 @@ def get_pr_data(branch_info):
|
|
|
108
149
|
messages.append({'role': 'user', 'content': 'main commits: ' + '\n'.join(branch_info.highlight_commits)})
|
|
109
150
|
messages.append({'role': 'user', 'content': 'secondary commits: ' + '\n'.join(branch_info.commits)})
|
|
110
151
|
else:
|
|
111
|
-
messages.append({'role': 'user', 'content': 'git commits: ' + '\n'.join(branch_info.commits)})
|
|
152
|
+
messages.append({'role': 'user', 'content': 'git commits: \n' + '\n'.join(branch_info.commits)})
|
|
112
153
|
|
|
113
154
|
messages.append({'role': 'user', 'content': 'PR template:\n' + _get_pr_template()})
|
|
114
155
|
|
|
115
|
-
|
|
156
|
+
joined_messages = '\n'.join([m['content'] for m in messages])
|
|
157
|
+
current_total_tokens = _count_tokens(joined_messages)
|
|
158
|
+
|
|
159
|
+
input_max_tokens = int(config.get_user_config('INPUT_MAX_TOKENS'))
|
|
116
160
|
|
|
117
|
-
if
|
|
118
|
-
|
|
161
|
+
if current_total_tokens > input_max_tokens:
|
|
162
|
+
exp_message = (f'Length of {current_total_tokens} tokens for basic prompt '
|
|
163
|
+
f'(description and commits) is greater than max tokens {input_max_tokens} '
|
|
164
|
+
'(config \'input_max_tokens\')')
|
|
165
|
+
raise Exception(exp_message)
|
|
119
166
|
|
|
120
|
-
|
|
121
|
-
if
|
|
122
|
-
|
|
167
|
+
total_tokens_with_diff = current_total_tokens + _count_tokens(branch_info.diff)
|
|
168
|
+
if total_tokens_with_diff > input_max_tokens:
|
|
169
|
+
print_msg = (f'Length git changes with diff is too big (total is {total_tokens_with_diff}, '
|
|
170
|
+
f'\'input_max_tokens\' config is {input_max_tokens}).')
|
|
171
|
+
print(print_msg, cc.red('Skipping changes diff content...'))
|
|
123
172
|
else:
|
|
124
173
|
messages.append({'role': 'user', 'content': 'Diff changes:\n' + branch_info.diff})
|
|
125
174
|
|
|
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
|
-
)
|
|
175
|
+
return messages
|
|
150
176
|
|
|
151
177
|
|
|
152
178
|
def _parse_json(content):
|
gptpr/test_config.py
CHANGED
|
@@ -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,17 +66,36 @@ 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
|
|
|
72
87
|
all_values = config.all_values()
|
|
73
88
|
|
|
74
89
|
assert all_values == [
|
|
90
|
+
('DEFAULT', 'add_tool_signature', 'true'),
|
|
75
91
|
('DEFAULT', 'gh_token', ''),
|
|
76
|
-
('DEFAULT', '
|
|
92
|
+
('DEFAULT', 'input_max_tokens', '15000'),
|
|
93
|
+
('DEFAULT', 'openai_model', 'gpt-4o-mini'),
|
|
77
94
|
('DEFAULT', 'openai_api_key', ''),
|
|
95
|
+
('user', 'add_tool_signature', 'true'),
|
|
78
96
|
('user', 'gh_token', ''),
|
|
79
|
-
('user', '
|
|
97
|
+
('user', 'input_max_tokens', '15000'),
|
|
98
|
+
('user', 'openai_model', 'gpt-4o-mini'),
|
|
80
99
|
('user', 'openai_api_key', ''),
|
|
81
100
|
]
|
|
82
101
|
|
|
@@ -94,6 +113,6 @@ def test_reset_user_config(temp_config):
|
|
|
94
113
|
config_to_test.read(os.path.join(str(temp_dir), config.config_filename))
|
|
95
114
|
|
|
96
115
|
_check_config(config, temp_dir, [
|
|
97
|
-
('user', 'OPENAI_MODEL', 'gpt-4o'),
|
|
116
|
+
('user', 'OPENAI_MODEL', 'gpt-4o-mini'),
|
|
98
117
|
('user', 'OPENAI_API_KEY', ''),
|
|
99
118
|
])
|
gptpr/version.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "0.
|
|
1
|
+
__version__ = "0.6.0"
|
gpt_pr-0.4.1.dist-info/RECORD
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
gptpr/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
gptpr/checkversion.py,sha256=PmbGiYJelecs1Fv2aAZwdr6wn-qDC826nsYI4A6LLvk,2389
|
|
3
|
-
gptpr/config.py,sha256=YVQgTuJYVwqAabqK-E3xSzlc4QUvZb0q4dUW-_pY2cg,2609
|
|
4
|
-
gptpr/consolecolor.py,sha256=_JmBMNjIflWMlgP2VkCWu6uQLR9oHBy52uV3TRJJgF4,800
|
|
5
|
-
gptpr/gh.py,sha256=uSWY_TzbrAM00neOBkyfV5vxDO4FzMtIrs-Zczp-Tck,1127
|
|
6
|
-
gptpr/gitutil.py,sha256=NBD3iRnbFEPRU47w7c5TowwtZieDYkU4zybvv0PoOU0,5783
|
|
7
|
-
gptpr/main.py,sha256=gen_8YXYAUJU0BpzULZ28j9Br6Y9PTqTr9JEm4nwsJI,2694
|
|
8
|
-
gptpr/prdata.py,sha256=ejx4zLRViJ83OmqvlxGWnw7alo8RPL_YdlwEJFhMQ8g,6183
|
|
9
|
-
gptpr/test_checkversion.py,sha256=WtJ3v4MMkFG0Kob0R1wi_nwVhcQFd4mXtKCKZHajEhM,4266
|
|
10
|
-
gptpr/test_config.py,sha256=_vP-3RJf8WXGGQESr5bCUbmxf8owc1uVJXMSBF_MtH0,2712
|
|
11
|
-
gptpr/test_prdata.py,sha256=rSJ-yqOdw-iYdBWyqnA2SXbdrhT8KgIkRTTf9SY1S1g,474
|
|
12
|
-
gptpr/version.py,sha256=pMtTmSUht-XtbR_7Doz6bsQqopJJd8rZ8I8zy2HwwoA,22
|
|
13
|
-
gpt_pr-0.4.1.dist-info/METADATA,sha256=xcj4KIGRUS5pFaXrVe7AM5YOfy7dm9JA8VE-IVVwsHI,2638
|
|
14
|
-
gpt_pr-0.4.1.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
|
15
|
-
gpt_pr-0.4.1.dist-info/entry_points.txt,sha256=WhcbcQXqo5-IGliYWiYMhop4-Wm7bcH2ljFKLWrmO7c,81
|
|
16
|
-
gpt_pr-0.4.1.dist-info/top_level.txt,sha256=DZcbzlsjh4BD8njGcvhOeCZ83U_oYWgCn0w8qx5--04,6
|
|
17
|
-
gpt_pr-0.4.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|