-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
428 changed files
with
78,712 additions
and
2,749 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
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,16 @@ | ||
#!/bin/bash | ||
|
||
# Exit on any error | ||
set -e | ||
|
||
python .github/scripts/workspace/workspace_classify.py | ||
|
||
echo "Workspace classified successfully!" | ||
|
||
python .github/scripts/workspace/seperate_classify.py | ||
|
||
echo "Workspace separated successfully!" | ||
|
||
python .github/scripts/workspace/workspace_merge.py | ||
|
||
echo "Workspace merged successfully!" |
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,7 @@ | ||
node_modules | ||
res.md | ||
res.html | ||
output.md | ||
monolithic.html | ||
original.html | ||
original_clean.html |
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,112 @@ | ||
import yaml | ||
import json | ||
import tempfile | ||
import subprocess | ||
import os | ||
from pathlib import Path | ||
|
||
def load_template(template_path): | ||
"""Load the template file""" | ||
with open(template_path, 'r', encoding='utf-8') as f: | ||
return f.read() | ||
|
||
def get_ai_classification(title, link, snippet, gen_struct_path, template): | ||
"""Ask AI to classify if the content is related""" | ||
# Define the JSON schema for classification | ||
schema = { | ||
"type": "object", | ||
"properties": { | ||
"is_related": { | ||
"type": "string", | ||
"enum": ["True", "False", "NotSure"], | ||
"description": "Whether the content is related to transgender/LGBTQ+ topics" | ||
} | ||
}, | ||
"required": ["is_related"], | ||
"additionalProperties": False | ||
} | ||
|
||
# Create temporary files | ||
with tempfile.NamedTemporaryFile(mode='w+', delete=False, suffix='.txt') as temp_input: | ||
# Fill in the template | ||
prompt = template.format( | ||
title=title or "Untitled", | ||
link=link, | ||
snippet=snippet or "" | ||
) | ||
temp_input.write(prompt) | ||
print(f"Prompt: {prompt}") | ||
temp_input_path = temp_input.name | ||
|
||
with tempfile.NamedTemporaryFile(mode='w+', delete=False, suffix='.json') as temp_schema: | ||
json.dump(schema, temp_schema) | ||
schema_file = temp_schema.name | ||
|
||
with tempfile.NamedTemporaryFile(mode='w+', delete=False, suffix='.json') as temp_output: | ||
temp_output_path = temp_output.name | ||
|
||
try: | ||
# Run gen_struct.py | ||
subprocess.run([ | ||
'python', gen_struct_path, | ||
temp_input_path, temp_output_path, schema_file | ||
], check=True) | ||
|
||
# Read the result | ||
with open(temp_output_path, 'r', encoding='utf-8') as f: | ||
result = json.load(f) | ||
print(f"Result: {result}") | ||
return result["is_related"].lower() # Convert to lowercase to match YAML | ||
except Exception as e: | ||
print(f"Error during AI classification: {e}") | ||
return "unknown" | ||
finally: | ||
# Cleanup temporary files | ||
os.unlink(temp_input_path) | ||
os.unlink(temp_output_path) | ||
os.unlink(schema_file) | ||
|
||
def main(): | ||
# File paths | ||
links_path = Path('.github/links.yml') | ||
template_path = Path('.github/prompts/check_related.md.template') | ||
gen_struct_path = Path('.github/scripts/ai/gen_struct.py') | ||
|
||
# Load files | ||
with open(links_path, 'r', encoding='utf-8') as f: | ||
links_data = yaml.safe_load(f) | ||
|
||
template = load_template(template_path) | ||
|
||
# Process each unknown entry | ||
modified = False | ||
for url, data in links_data.items(): | ||
if not data.get('is_related') or data.get('is_related') == 'unknown': | ||
print(f"Processing: {url}") | ||
result = get_ai_classification( | ||
data.get('title'), | ||
data.get('link'), | ||
data.get('snippet'), | ||
gen_struct_path, | ||
template | ||
) | ||
|
||
if result != 'unknown': | ||
data['is_related'] = result | ||
modified = True | ||
print(f"Updated {url} to {result}") | ||
# Write changes immediately | ||
with open(links_path, 'w', encoding='utf-8') as f: | ||
yaml.dump(links_data, f, allow_unicode=True) | ||
print("Changes saved to links.yml") | ||
else: | ||
print(f"Skipping {url} because the result is unknown") | ||
else: | ||
print(f"Skipping {url} because the result is already known") | ||
|
||
# Remove final save since we're saving after each update | ||
if not modified: | ||
print("No changes were necessary") | ||
|
||
if __name__ == "__main__": | ||
main() |
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,66 @@ | ||
import os | ||
import openai | ||
import argparse | ||
from openai import OpenAI | ||
from dotenv import load_dotenv | ||
|
||
load_dotenv() | ||
openai.api_key = os.getenv('OPENAI_API_KEY') | ||
model_name = os.getenv('OPENAI_MODEL_NAME') | ||
if not model_name: | ||
model_name = "gpt-4o" | ||
temperature = os.getenv('OPENAI_TEMPERATURE') | ||
if not temperature: | ||
temperature = 0.7 | ||
client = OpenAI() | ||
|
||
def read_file(file_path): | ||
"""Read the content of the input file.""" | ||
with open(file_path, 'r', encoding='utf-8') as file: | ||
return file.read() | ||
|
||
def write_file(file_path, content): | ||
"""Write the content to the output file.""" | ||
with open(file_path, 'w', encoding='utf-8') as file: | ||
file.write(content) | ||
|
||
def generate_cleanup_content(content): | ||
"""Send the prompt and content to OpenAI's API and get the cleaned content.""" | ||
|
||
completion = client.chat.completions.create( | ||
model=model_name, | ||
messages=[ | ||
{"role": "user", "content": content} | ||
] | ||
) | ||
|
||
return str(completion.choices[0].message.content) | ||
|
||
def main(): | ||
# Set up command-line argument parsing | ||
parser = argparse.ArgumentParser( | ||
description="Generate a cleaned-up version of a text file using OpenAI's GPT-4." | ||
) | ||
parser.add_argument('input_file', help='Path to the input .txt file') | ||
parser.add_argument('output_file', help='Path to save the cleaned output file') | ||
|
||
args = parser.parse_args() | ||
|
||
try: | ||
|
||
# Read input file | ||
input_content = read_file(args.input_file) | ||
|
||
# Generate cleaned content | ||
cleaned_content = generate_cleanup_content(input_content) | ||
|
||
# Write to output file | ||
write_file(args.output_file, cleaned_content) | ||
|
||
print(f"Successfully processed '{args.input_file}' and saved to '{args.output_file}'.") | ||
|
||
except Exception as e: | ||
print(f"An error occurred: {e}") | ||
|
||
if __name__ == "__main__": | ||
main() |
Oops, something went wrong.