Skip to content

Commit 81cf7dd

Browse files
authored
Merge pull request #218 from satti-hari-krishna-reddy/master
feat: add GitHub Actions workflow to sync docs with OpenAI vector store
2 parents 1eb738d + a1fdd54 commit 81cf7dd

File tree

4 files changed

+210
-2
lines changed

4 files changed

+210
-2
lines changed

.github/openai-file-map.json

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
"docs/about.md": {
3+
"file_id": "file-AzfzUW2xMs6yDbGjRkoCdf",
4+
"hash": "6f1bddf26c36be9e3ee8f00ebfe7959c3db8f6b7629b5db22e97ee0abd9791c6"
5+
},
6+
"docs/AI.md": {
7+
"file_id": "file-4gRa9ee9iST2qnnmu4S2La",
8+
"hash": "db14b672ffed31d1a92a3bd29f74daefb7ebb44c734a72cd11417868f6deb2c0"
9+
},
10+
"docs/API.md": {
11+
"file_id": "file-3ALFqypGXjfS3MsyZke1ca",
12+
"hash": "77b4633187816433d92bbd833277aee26e0ade2fc3b992655259a3ed0c2b5336"
13+
},
14+
"docs/apps.md": {
15+
"file_id": "file-NivELeCPkvDSNFSEf9CtvU",
16+
"hash": "6e6b13a1499dd555fb81fc6c50ccc4d85ec7c6a809efc9c5f65a3f273dc40052"
17+
},
18+
"docs/architecture.md": {
19+
"file_id": "file-1vJkH5FjEvf1k84XMJaKBr",
20+
"hash": "f187e54d3692af5dc9ca78eb9dd5a99f685853fa77011115fa9249a8dfab662e"
21+
},
22+
"docs/configuration.md": {
23+
"file_id": "file-MKKafNkugWBMVdpKcFuwe2",
24+
"hash": "a05f696ba0cddb92aa1fb3a61269e44c7618d740bbf9d2e19c7dd05b59c3cafb"
25+
},
26+
"docs/creators.md": {
27+
"file_id": "file-3nGiHFWH6oNcX3NCNNK6PV",
28+
"hash": "8d754bdd7b1953b2cd05617bb3afa0cead051cd3d6e0e5ea469a2041e86bc7e4"
29+
},
30+
"docs/extensions.md": {
31+
"file_id": "file-2C3XApcxBWSjzpTdJeeFoa",
32+
"hash": "c557bb3edbb46fd40801acab6c9226d7ac815895fa4cb8b8c87d4e5ecce1650e"
33+
},
34+
"docs/features.md": {
35+
"file_id": "file-Ueb9hgh2GkT4aZvdVqBT1R",
36+
"hash": "0504f63a75efbafda83a637d0630b6a0f2db29bd984976cd985e2d8d82c1cef4"
37+
},
38+
"docs/getting_started.md": {
39+
"file_id": "file-1WXn3ormjcadCchiJJpJHw",
40+
"hash": "db77d9a74df99a7c4c757a58ab7e22f93b6b4a6dba65d1575e1af585551bc3bd"
41+
},
42+
"docs/liquid.md": {
43+
"file_id": "file-KvBc6d8MWAWfi65y5xx6ZU",
44+
"hash": "ee962e1870d1b7998314a69a0ed29d7d3b93a70ebd48c4b56d7e52f4c66fa9f0"
45+
},
46+
"docs/organizations.md": {
47+
"file_id": "file-VVKqtp2vMBfLbp1XBzX4ad",
48+
"hash": "a9c1135cbc4c6abaa6f2ca8204e1636ebf9bb014d642ab69acb3546eea4206fa"
49+
},
50+
"docs/triggers.md": {
51+
"file_id": "file-Q1JYeWM3R8dgjjRBNQXBKv",
52+
"hash": "447346bba4519fa44443cd14ad46be7743c45eb582cc9eb17ffc98c91c9e85be"
53+
},
54+
"docs/troubleshooting.md": {
55+
"file_id": "file-BAzqnXh5TPqLvq6y9DCsFR",
56+
"hash": "8e7c42ae6ac80fd4397f951596d1db9abb59db799b4b76720079f6149f6043cb"
57+
},
58+
"docs/workflows.md": {
59+
"file_id": "file-5ZzHyGGVpGanyTVt6XPfAc",
60+
"hash": "f6d0b5259a047c2a21610cadfff90b9a873f8b107f15ee480a261ec07d8e6e57"
61+
}
62+
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
import os
2+
import json
3+
import hashlib
4+
from pathlib import Path
5+
from openai import OpenAI
6+
7+
DOCS_DIR = Path("docs")
8+
MAP_FILE = Path(".github/openai-file-map.json")
9+
10+
OPENAI_API_KEY = os.environ.get("OPENAI_API_KEY")
11+
VECTOR_STORE_ID = os.environ.get("OPENAI_DOCS_VS_ID")
12+
13+
if not OPENAI_API_KEY or not VECTOR_STORE_ID:
14+
raise RuntimeError("Missing OPENAI_API_KEY or OPENAI_DOCS_VS_ID")
15+
16+
client = OpenAI(api_key=OPENAI_API_KEY)
17+
18+
def compute_hash(path: Path) -> str:
19+
h = hashlib.sha256()
20+
with open(path, "rb") as f:
21+
for chunk in iter(lambda: f.read(8192), b""):
22+
h.update(chunk)
23+
return h.hexdigest()
24+
25+
def load_map() -> dict:
26+
if MAP_FILE.exists():
27+
with open(MAP_FILE, "r") as f:
28+
return json.load(f)
29+
return {}
30+
31+
def save_map(m: dict):
32+
MAP_FILE.parent.mkdir(parents=True, exist_ok=True)
33+
with open(MAP_FILE, "w") as f:
34+
json.dump(m, f, indent=2)
35+
36+
def upload_and_attach(path: Path) -> str:
37+
print(f"Uploading: {path}")
38+
39+
uploaded = client.files.create(
40+
file=open(path, "rb"),
41+
purpose="assistants"
42+
)
43+
44+
client.vector_stores.files.create(
45+
vector_store_id=VECTOR_STORE_ID,
46+
file_id=uploaded.id
47+
)
48+
49+
return uploaded.id
50+
51+
def delete_from_vector_store(file_id: str, path: str):
52+
try:
53+
client.vector_stores.files.delete(
54+
vector_store_id=VECTOR_STORE_ID,
55+
file_id=file_id
56+
)
57+
print(f"Deleted from vector store: {path}")
58+
except Exception as e:
59+
print(f"Warning: failed to delete {path}: {e}")
60+
61+
file_map = load_map()
62+
63+
current_files = {}
64+
for f in DOCS_DIR.rglob("*"):
65+
if f.is_file():
66+
rel_path = f.as_posix()
67+
current_files[rel_path] = compute_hash(f)
68+
69+
indexed = 0
70+
deleted = 0
71+
72+
# Handle new + updated files
73+
for path, current_hash in current_files.items():
74+
if path not in file_map:
75+
file_id = upload_and_attach(Path(path))
76+
file_map[path] = {
77+
"file_id": file_id,
78+
"hash": current_hash
79+
}
80+
indexed += 1
81+
82+
else:
83+
# Existing file, check content
84+
if file_map[path]["hash"] != current_hash:
85+
delete_from_vector_store(file_map[path]["file_id"], path)
86+
file_id = upload_and_attach(Path(path))
87+
file_map[path] = {
88+
"file_id": file_id,
89+
"hash": current_hash
90+
}
91+
indexed += 1
92+
93+
# Handle deleted files
94+
for path in list(file_map.keys()):
95+
if path not in current_files:
96+
delete_from_vector_store(file_map[path]["file_id"], path)
97+
del file_map[path]
98+
deleted += 1
99+
100+
save_map(file_map)
101+
102+
print("Sync complete.")
103+
print(f"Uploaded/updated: {indexed}")
104+
print(f"Deleted: {deleted}")
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Sync Vector Store
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
paths-ignore:
8+
- ".github/openai-file-map.json"
9+
10+
permissions:
11+
contents: write
12+
13+
jobs:
14+
sync:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- uses: actions/setup-python@v5
21+
with:
22+
python-version: "3.11"
23+
24+
- run: pip install openai
25+
26+
- name: Sync docs to vector store
27+
env:
28+
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
29+
OPENAI_DOCS_VS_ID: ${{ secrets.OPENAI_DOCS_VS_ID }}
30+
run: |
31+
python .github/scripts/sync_vector_store.py
32+
33+
- name: Commit updated map
34+
run: |
35+
if git status --porcelain | grep ".github/openai-file-map.json"; then
36+
git config user.name "github-actions[bot]"
37+
git config user.email "github-actions[bot]@users.noreply.github.com"
38+
git add .github/openai-file-map.json
39+
git commit -m "chore: sync vector store"
40+
git push
41+
else
42+
echo "No changes"
43+
fi

docs/workflows.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -765,5 +765,4 @@ Azure DevOps integration enables workflow backup with your organization’s Azur
765765
4. **Username**
766766
- Use your **Azure DevOps email address** as the username.
767767
768-
Note: Azure devops support is available from version 2.1.1 and above
769-
768+
Note: Azure devops support is available from version 2.1.1 and above

0 commit comments

Comments
 (0)