gpt-pr 0.4.0__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.

Files changed (26) hide show
  1. {gpt-pr-0.4.0 → gpt-pr-0.5.0}/PKG-INFO +1 -1
  2. {gpt-pr-0.4.0 → gpt-pr-0.5.0}/README.md +13 -13
  3. {gpt-pr-0.4.0 → gpt-pr-0.5.0}/gpt_pr.egg-info/PKG-INFO +1 -1
  4. {gpt-pr-0.4.0 → gpt-pr-0.5.0}/gpt_pr.egg-info/requires.txt +3 -3
  5. {gpt-pr-0.4.0 → gpt-pr-0.5.0}/gptpr/checkversion.py +2 -1
  6. {gpt-pr-0.4.0 → gpt-pr-0.5.0}/gptpr/config.py +6 -3
  7. {gpt-pr-0.4.0 → gpt-pr-0.5.0}/gptpr/prdata.py +49 -32
  8. {gpt-pr-0.4.0 → gpt-pr-0.5.0}/gptpr/test_config.py +21 -4
  9. gpt-pr-0.5.0/gptpr/version.py +1 -0
  10. {gpt-pr-0.4.0 → gpt-pr-0.5.0}/requirements.txt +3 -3
  11. gpt-pr-0.4.0/gptpr/version.py +0 -1
  12. {gpt-pr-0.4.0 → gpt-pr-0.5.0}/MANIFEST.in +0 -0
  13. {gpt-pr-0.4.0 → gpt-pr-0.5.0}/gpt_pr.egg-info/SOURCES.txt +0 -0
  14. {gpt-pr-0.4.0 → gpt-pr-0.5.0}/gpt_pr.egg-info/dependency_links.txt +0 -0
  15. {gpt-pr-0.4.0 → gpt-pr-0.5.0}/gpt_pr.egg-info/entry_points.txt +0 -0
  16. {gpt-pr-0.4.0 → gpt-pr-0.5.0}/gpt_pr.egg-info/not-zip-safe +0 -0
  17. {gpt-pr-0.4.0 → gpt-pr-0.5.0}/gpt_pr.egg-info/top_level.txt +0 -0
  18. {gpt-pr-0.4.0 → gpt-pr-0.5.0}/gptpr/__init__.py +0 -0
  19. {gpt-pr-0.4.0 → gpt-pr-0.5.0}/gptpr/consolecolor.py +0 -0
  20. {gpt-pr-0.4.0 → gpt-pr-0.5.0}/gptpr/gh.py +0 -0
  21. {gpt-pr-0.4.0 → gpt-pr-0.5.0}/gptpr/gitutil.py +0 -0
  22. {gpt-pr-0.4.0 → gpt-pr-0.5.0}/gptpr/main.py +0 -0
  23. {gpt-pr-0.4.0 → gpt-pr-0.5.0}/gptpr/test_checkversion.py +0 -0
  24. {gpt-pr-0.4.0 → gpt-pr-0.5.0}/gptpr/test_prdata.py +0 -0
  25. {gpt-pr-0.4.0 → gpt-pr-0.5.0}/setup.cfg +0 -0
  26. {gpt-pr-0.4.0 → gpt-pr-0.5.0}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: gpt-pr
3
- Version: 0.4.0
3
+ Version: 0.5.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
@@ -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-3.5-turbo
134
+ gpt-pr-config set openai_model gpt-4o-mini
129
135
  ```
130
136
 
131
- To see a full list of available models, access [OpenAI Models Documentation](https://platform.openai.com/docs/models)
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
- ```bash
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,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: gpt-pr
3
- Version: 0.4.0
3
+ Version: 0.5.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
@@ -1,5 +1,5 @@
1
1
  cffi==1.15.1
2
- cryptography==42.0.7
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.1
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.2.2
33
+ certifi==2024.7.4
34
34
  distro==1.9.0
35
35
  pynacl==1.5.0
36
36
  wrapt==1.16.0
@@ -24,7 +24,8 @@ def cache_daily_version(func):
24
24
  if datetime.now() - last_checked < CACHE_DURATION:
25
25
  # Use cached version info
26
26
  latest_version = cache.get('latest_version')
27
- return latest_version
27
+ if latest_version:
28
+ return latest_version
28
29
 
29
30
  latest_version = func(*args, **kwargs)
30
31
  cache = {
@@ -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#authentication--api-keys'
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
- current_total_length = sum([len(m['content']) for m in messages])
147
+ joined_messages = '\n'.join([m['content'] for m in messages])
148
+ current_total_tokens = _count_tokens(joined_messages)
116
149
 
117
- if current_total_length / TOKENIZER_RATIO > MAX_TOKENS:
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
- total_length_with_diff = current_total_length + len(branch_info.diff)
121
- if total_length_with_diff / TOKENIZER_RATIO > MAX_TOKENS:
122
- print('Total content length (with diff) is too big.', cc.red('Skipping diff content...'))
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
- client = OpenAI(api_key=_get_open_ai_key())
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', 'openai_model', 'gpt-4o'),
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', 'openai_model', 'gpt-4o'),
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.2.2; python_version >= '3.6'
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==42.0.7
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.1; python_version < '3.11'
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'
@@ -1 +0,0 @@
1
- __version__ = "0.4.0"
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