Skip to content

Commit

Permalink
chore: modify create-readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Minh141120 committed Jan 23, 2025
1 parent 943dee2 commit ceef533
Showing 1 changed file with 37 additions and 44 deletions.
81 changes: 37 additions & 44 deletions .github/workflows/convert-model-all-quant.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,53 +100,43 @@ jobs:
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
run: |
python3 - << EOF
python3 - << 'EOF'
import os
from openai import OpenAI
# Initialize the OpenAI client
client = OpenAI(api_key=os.environ['OPENAI_API_KEY'])
# Inputs
source_model_id = os.environ['SOURCE_MODEL_ID']
model_name = os.environ['MODEL_NAME']
model_variant = os.environ['SOURCE_MODEL_SIZE']
target_model_id = os.environ['TARGET_MODEL_ID']
user_name = os.environ['USER_NAME']
# Extract author from source model ID
author = source_model_id.split('/')[0]
# Call OpenAI API to generate overview
completion = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{
"role": "user",
"content": f"Write a concise overview for an ai model named '{target_model_id}' derived from '{source_model_id}', highlighting its purpose, use cases, and performance. You DO NOT generate title (# heading 1) and summary sections. For the overview section, make it concise and in a paragraph of 5 sentences"
}
]
)
overview = completion.choices[0].message.content.strip()
# Find LICENSE files
licenses = []
model_dir = f"/mnt/models/{model_name}/hf"
for filename in os.listdir(model_dir):
if filename.startswith('LICENSE'):
license_url = f"https://huggingface.co/{source_model_id}/blob/main/{filename}"
licenses.append(f"[{filename}]({license_url})")
license_links = " | ".join(licenses) if licenses else "[License](#)"
# README.md template
readme_template = f"""\
---
try:
client = OpenAI(api_key=os.environ['OPENAI_API_KEY'])
source_model_id = os.environ['SOURCE_MODEL_ID']
model_name = os.environ['MODEL_NAME']
model_variant = os.environ['SOURCE_MODEL_SIZE']
target_model_id = os.environ['TARGET_MODEL_ID']
user_name = os.environ['USER_NAME']
author = source_model_id.split('/')[0]
completion = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": f"Write a concise overview for an ai model named '{target_model_id}' derived from '{source_model_id}', highlighting its purpose, use cases, and performance. You DO NOT generate title (# heading 1) and summary sections. For the overview section, make it concise and in a paragraph of 5 sentences"}
]
)
overview = completion.choices[0].message.content.strip()
model_dir = f"/mnt/models/{model_name}/hf"
licenses = []
for filename in os.listdir(model_dir):
if filename.startswith('LICENSE'):
license_url = f"https://huggingface.co/{source_model_id}/blob/main/{filename}"
licenses.append(f"[{filename}]({license_url})")
license_links = " | ".join(licenses) if licenses else "[License](#)"
readme_content = f"""---
license: mit
---
# {model_name.capitalize()} ({model_variant.upper()})
## Overview
{overview}
Expand Down Expand Up @@ -180,9 +170,12 @@ jobs:
- **Original License:** {license_links}
"""
# Write the README.md file
with open('README.md', 'w') as f:
f.write(readme_template)
with open('README.md', 'w') as f:
f.write(readme_content)
print("Successfully created README.md")
except Exception as e:
print(f"Error occurred: {str(e)}")
EOF
- name: Upload README.md to HuggingFace Repository
Expand Down

0 comments on commit ceef533

Please sign in to comment.