Skip to content

Instantly share code, notes, and snippets.

@mcejp
Created April 11, 2025 20:45
Show Gist options
  • Save mcejp/5f411ab5289a266234b69f7573392b2f to your computer and use it in GitHub Desktop.
Save mcejp/5f411ab5289a266234b69f7573392b2f to your computer and use it in GitHub Desktop.
import os
from pathlib import Path
from openai import OpenAI
client = OpenAI(
base_url="https://api.scaleway.ai/v1",
api_key=os.environ["SCW_SECRET_KEY"]
)
def convert_changelog(in_file, out_file):
PROMPT = '''You are an AI agent that converts changelogs to Markdown. Given a changelog for a software package, which may be in a variety of formats such as Markdown, reStructuredText, or a custom text format, you will extract the 3 most recent releases and re-format them in Markdown.
Example input:
```
09/01/2023 - 2.6.1
------------------------------
* [CGFES-1154] Initialize "user" acquisition field in CGAFG
* Update to FESA 8.3.0
```
Corresponding output:
```
### 2.6.1 (2023-01-09)
* [CGFES-1154] Initialize "user" acquisition field in CGAFG
* Update to FESA 8.3.0
```
'''
# Now follows the changelog:\n\n'''
# PROMPT += Path("changelog.txt").read_text()
PROMPT2 = "Now follows the changelog:\n\n" + Path(in_file).read_text()
response = client.chat.completions.create(
model="llama-3.1-8b-instruct",
# messages=[{"role": "system", "content": PROMPT}],
messages=[{"role": "system", "content": PROMPT}, {"role": "user", "content": PROMPT2}],
temperature=0.2,
max_tokens=500,
top_p=0.7
)
print("RESPONSE")
print(response)
print("CONTENT")
print(response.choices[0].message.content)
Path(out_file).write_text(response.choices[0].message.content)
convert_changelog("changelog.txt", "output.md")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment