Skip to content

Commit 9cab52c

Browse files
committed
Added a github action to update embeddings whenever prompts file is updated in a PR
Signed-off-by: Mystic-Slice <vaashwath@gmail.com>
1 parent c18baa3 commit 9cab52c

2 files changed

Lines changed: 57 additions & 3 deletions

File tree

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Update Embeddings
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- prompt-sentences-main/prompt_sentences.json
7+
workflow_dispatch: # To allow manual trigger of this workflow
8+
9+
permissions:
10+
contents: write
11+
pull-requests: write
12+
13+
jobs:
14+
regenerate:
15+
if: github.actor != 'ci-bot'
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- uses: actions/checkout@v4
20+
with:
21+
ref: ${{ github.head_ref }}
22+
23+
- uses: actions/setup-python@v5
24+
with:
25+
python-version: "3.11"
26+
27+
- uses: actions/cache@v4
28+
with:
29+
path: ~/.cache/pip
30+
key: pip-${{ runner.os }}-${{ hashFiles('requirements.txt') }}
31+
32+
- run: pip install -r requirements.txt
33+
34+
# Github actions can run for 6 hours maximum
35+
# For small updates to the prompts file, this should be plenty
36+
- name: Run generator
37+
run: python customize/customize_embeddings.py
38+
39+
- name: Commit if changed
40+
run: |
41+
git status
42+
if git diff --quiet; then
43+
echo "No changes"
44+
else
45+
git config user.name "ci-bot"
46+
git config user.email "ci-bot@users.noreply.github.com"
47+
git add -u
48+
git commit -m "chore: update embeddings" -s
49+
git push
50+
fi

customize/customize_embeddings.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
# Sentence transformer model HF
3535
model_path = 'models/all-MiniLM-L6-v2'
36-
model_id = model_path.split("/")[1]
36+
model_id = model_path.split("/")[1].lower()
3737

3838
# INPUT FILE
3939
# Default file with empty embeddings
@@ -43,13 +43,15 @@
4343
# OUTPUT FILE
4444
json_out_file_name = f'{json_in_file_name}-{model_id}.json'
4545

46+
print(f'Loading existing data')
47+
existing_data = None
4648
# check if the output file already exists
4749
if os.path.exists(json_out_file_name):
4850
try:
4951
# Load existing data from the output file
5052
existing_data = customize_helper.load_json(json_out_file_name)
5153
except Exception as e:
52-
existing_data = None
54+
print(f"Error loading existing data: {e}")
5355

5456
# hashmap
5557
prompts_embeddings = {}
@@ -62,8 +64,10 @@
6264
prompts_embeddings[p["text"]] = p["embedding"]
6365

6466

65-
67+
print("Populating embeddings and centroids")
6668
prompt_json = json.load(open(json_in_file))
6769
prompt_json_embeddings = customize_helper.populate_embeddings(prompt_json, model_path, prompts_embeddings)
6870
prompt_json_centroids = customize_helper.populate_centroids(prompt_json_embeddings)
71+
72+
print("Saving the embeddings")
6973
customize_helper.save_json(prompt_json_centroids, json_out_file_name)

0 commit comments

Comments
 (0)