-
Notifications
You must be signed in to change notification settings - Fork 3
67 lines (57 loc) · 2.7 KB
/
sqlite_documentation_gen.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
name: ChatGPT Workflow
on:
push:
paths:
- 'src/tasks.py'
workflow_dispatch:
jobs:
update-readme:
runs-on: ubuntu-latest
steps:
- name: Check for rebuild-docs
run: |
echo "Commit message: '${{ steps.commit.outputs.message }}'"
if [[ "${{ steps.commit.outputs.message }}" == *"--rebuild-docs"* ]]; then
echo "Commit message contains --rebuild-docs. Continue to next step."
else
echo "Commit message does not contain --rebuild-docs. Skipping subsequent steps."
exit 78
shell: bash
continue-on-error: true
- name: Checkout Repository
uses: actions/checkout@v2
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install openai
- name: Read tasks.py and Generate README
run: |
python -c "
import openai
import os
# Read content
with open('src/tasks.py', 'r') as file:
lines = file.readlines()
start_line = next(i for i, line in enumerate(lines, start=1) if '# auto-generated SQLite documentation starts here' in line)
content = ''.join(lines[start_line-1:])
# Call to ChatGPT
openai.api_key = os.getenv('OPENAI_API_KEY')
prompt = content
response = openai.ChatCompletion.create(model='gpt-4', messages=[{'role': 'user', 'content': f'{prompt}\nGenerate a documentation markdown table for each table of the SQLite database (including package_data). For example:\n\n**activity table**\n|Column|Description\n|event_name|One sentence to explain to the developers what kind of data they will find here. If the code provided allows you to provide an example of data format or value that is great, but do not invent anything.|same for this column|etc.\n\n**Table 2**\n|Column|Description|...\n\netc.'}])
readme_content = response.choices[0].message.content.strip()
# Write to db_doc.md
with open('docs/sqlite_database_structure.md', 'w') as file:
readme_content = 'Note: this documentation was generated automatically from the tasks.py code using an AI. Although we are confident in the reliability of the data displayed here, errors may occur.\n\n\n' + readme_content
file.write(readme_content)
"
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
- name: Commit and Push
uses: EndBug/add-and-commit@v7
with:
message: 'Update sqlite_database_structure.md'
add: 'docs/sqlite_database_structure.md'