-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathingest.py
More file actions
59 lines (45 loc) · 1.46 KB
/
ingest.py
File metadata and controls
59 lines (45 loc) · 1.46 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from pathlib import Path
import typer
from os import getenv
from mixedbread import Mixedbread
from rich import print
mxbai = Mixedbread(api_key=getenv('MIXEDBREAD_APIKEY'))
STORE_IDENTIFIER = "Air-Documentation"
def delete_current():
results = mxbai.stores.files.list(
store_identifier=STORE_IDENTIFIER,
limit=100,
)
for record in results.data:
print(f'[red bold]Deleting {record.filename}[/red bold]')
mxbai.stores.files.delete(
store_identifier=STORE_IDENTIFIER,
file_id=record.id,
)
def ingest_latest(path: Path):
doc_paths = path.glob('**/*.md')
count = 0
for fpath in doc_paths:
strpath = str(fpath)
print(f"Ingesting {strpath}")
baselink = strpath.replace("../air/docs/", "")
baselink = baselink.replace('index.md', '')
baselink = baselink.replace('.md', '')
link = f'https://feldroy.github.io/air/{baselink}'
print(f'{link=}')
mxbai.stores.files.upload(
store_identifier=STORE_IDENTIFIER,
file=fpath,
metadata={
'link': link
}
)
def main(path: Path):
# TODO: Replace deleting of current with checking if there's been changes
# and then doing a more surgical replace
delete_current()
ingest_latest(path)
print('Done')
# doc_paths = Path('../air/src/air').glob('**/*.md')
if __name__ == '__main__':
typer.run(main)