-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: GPT assistant knowledge generation script
- Loading branch information
Showing
2 changed files
with
54 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
""" | ||
This is a script to create knowledge files for OpenAI GPT assistants. | ||
They currently have a pretty strict file count limit, so we need to merge all files in each section into one file. | ||
""" | ||
|
||
import os | ||
import shutil | ||
|
||
DOCS_PATH = "docs" | ||
GENERATED_PATH = "assistant" | ||
|
||
|
||
def generate(root_path): | ||
os.makedirs(GENERATED_PATH, exist_ok=True) | ||
|
||
for root, dirs, files in os.walk(root_path): | ||
if root == root_path: | ||
# Root directory is a special case, handled below | ||
continue | ||
|
||
content_lang_map = {} | ||
|
||
for file in files: | ||
if file.endswith(".md"): | ||
# Determine the language variant | ||
parts = file.split(".") | ||
language = parts[-2] if len(parts) > 2 else "en" | ||
|
||
with open(os.path.join(root, file), "r", encoding="utf-8") as f: | ||
content = f.read() | ||
|
||
if language not in content_lang_map: | ||
content_lang_map[language] = [] | ||
content_lang_map[language].append(f"== {file} ==\n\n{content}") | ||
|
||
# Write the combined content to new files | ||
for language, contents in content_lang_map.items(): | ||
combined_filename = f"{os.path.basename(root)}.{language}.md" | ||
with open( | ||
os.path.join(GENERATED_PATH, combined_filename), "w", encoding="utf-8" | ||
) as f: | ||
f.write("\n\n".join(contents)) | ||
|
||
# Handle files in the root directory | ||
for file in os.listdir(root_path): | ||
file_path = os.path.join(root_path, file) | ||
if os.path.isfile(file_path) and file.endswith(".md"): | ||
shutil.copy(file_path, GENERATED_PATH) | ||
|
||
|
||
if __name__ == "__main__": | ||
generate(DOCS_PATH) |