@@ -151,6 +151,7 @@ def update_changelog(ctx: Context, version: str | None = None, dry_run: bool = F
151
151
updating the actual change log file. Defaults to False.
152
152
"""
153
153
version = version or f"{ datetime .now (tz = timezone .utc ):%Y.%-m.%-d} "
154
+ __version__ = "2025.1.9"
154
155
print (f"Getting all comments since { __version__ } " )
155
156
output = subprocess .check_output (["git" , "log" , "--pretty=format:%s" , f"v{ __version__ } ..HEAD" ])
156
157
lines = []
@@ -174,11 +175,29 @@ def update_changelog(ctx: Context, version: str | None = None, dry_run: bool = F
174
175
lines += [f" { ll } " ]
175
176
else :
176
177
ignored_commits += [line ]
178
+
179
+ body = "\n " .join (lines )
180
+ try :
181
+ # Use OpenAI to improve changelog. Requires openai to be installed and an OPENAPI_KEY env variable.
182
+ from openai import OpenAI
183
+
184
+ client = OpenAI (api_key = os .environ ["OPENAPI_KEY" ])
185
+
186
+ messages = [{"role" : "user" , "content" : f"summarize, include authors: '{ body } '" }]
187
+ chat = client .chat .completions .create (model = "gpt-4o" , messages = messages )
188
+
189
+ reply = chat .choices [0 ].message .content
190
+ body = "\n " .join (reply .split ("\n " )[1 :])
191
+ body = body .strip ()
192
+ print (f"ChatGPT Summary of Changes:\n { body } " )
193
+
194
+ except BaseException as ex :
195
+ print (f"Unable to use openai due to { ex } " )
177
196
with open ("docs/CHANGES.md" , encoding = "utf-8" ) as file :
178
197
contents = file .read ()
179
198
delim = "##"
180
199
tokens = contents .split (delim )
181
- tokens .insert (1 , f"## v{ version } \n \n " + " \n " . join ( lines ) + " \n " )
200
+ tokens .insert (1 , f"## v{ version } \n \n { body } \n \n " )
182
201
if dry_run :
183
202
print (tokens [0 ] + "##" .join (tokens [1 :]))
184
203
else :
0 commit comments