Skip to content

Commit dcba5c2

Browse files
author
Adil Wahab Bhatti
authored
Add GitHub Actions workflow to count tokens
1 parent e4cd4e9 commit dcba5c2

1 file changed

Lines changed: 61 additions & 0 deletions

File tree

.github/workflows/token-count.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Update token count
2+
3+
on:
4+
push:aname: Update token count
5+
6+
on:
7+
push:
8+
paths:
9+
- 'instructions.txt'
10+
workflow_dispatch:
11+
12+
jobs:
13+
count:
14+
runs-on: ubuntu-latest
15+
permissions:
16+
contents: write
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Count tokens
21+
run: |
22+
pip install tiktoken -q
23+
COUNT=$(python3 -c "
24+
import tiktoken
25+
enc = tiktoken.get_encoding('cl100k_base')
26+
print(len(enc.encode(open('instructions.txt').read())))
27+
")
28+
sed -i "s/Tokens-~[0-9]*/Tokens-~$COUNT/" README.md
29+
30+
- name: Commit updated README
31+
run: |
32+
git config user.name "github-actions"
33+
git config user.email "actions@github.com"
34+
git diff --quiet || (git add README.md && git commit -m "Update token count" && git push)
35+
36+
paths:
37+
- "instructions.txt"
38+
39+
jobs:
40+
count:
41+
runs-on: ubuntu-latest
42+
permissions:
43+
contents: write
44+
steps:
45+
- uses: actions/checkout@v4
46+
47+
- name: Count tokens
48+
run: |
49+
pip install tiktoken -q
50+
COUNT=$(python3 -c "
51+
import tiktoken
52+
enc = tiktoken.get_encoding('cl100k_base')
53+
print(len(enc.encode(open('instructions.txt').read())))
54+
")
55+
sed -i "s/Tokens-~[0-9]*/Tokens-~$COUNT/" README.md
56+
57+
- name: Commit updated README
58+
run: |
59+
git config user.name "github-actions"
60+
git config user.email "actions@github.com"
61+
git diff --quiet || (git add README.md && git commit -m "Update token count" && git push)

0 commit comments

Comments
 (0)