-
Notifications
You must be signed in to change notification settings - Fork 0
39 lines (32 loc) · 1.01 KB
/
Copy pathtoken-count.yml
File metadata and controls
39 lines (32 loc) · 1.01 KB
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
name: Update token count
on:
push:
paths:
- "instructions.txt"
workflow_dispatch:
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
jobs:
count:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Count tokens
run: |
pip install tiktoken -q
python3 -c "
import tiktoken, pathlib, re
text = pathlib.Path('instructions.txt').read_text()
oai = tiktoken.get_encoding('cl100k_base')
oai_count = len(oai.encode(text))
readme = pathlib.Path('README.md').read_text()
readme = re.sub(r'Tokens--GPT-~[0-9]*', f'Tokens--GPT-~{oai_count}', readme)
pathlib.Path('README.md').write_text(readme)
"
- name: Commit updated README
run: |
git config user.name "github-actions"
git config user.email "actions@github.com"
git diff --quiet || (git add README.md && git commit -m "Update token count" && git push)