Skip to content

Commit

Permalink
chore: fix license genarator
Browse files Browse the repository at this point in the history
  • Loading branch information
Minh141120 committed Jan 23, 2025
1 parent 30a9771 commit c6f99bc
Showing 1 changed file with 32 additions and 35 deletions.
67 changes: 32 additions & 35 deletions .github/workflows/convert-model-all-quant.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,50 +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()
model_dir = f"/mnt/models/{model_name}/hf"
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.md template
readme_template = f"""\
---
readme_content = f"""---
license: mit
---
# {model_name.capitalize()} ({model_variant.upper()})
## Overview
{overview}
Expand All @@ -152,7 +145,7 @@ jobs:
| No | Variant | Cortex CLI command |
| --- | --- | --- |
| 1 | [gguf](https://huggingface.co/{user_name}/{model_name}/tree/main) | cortex run {model_name} |
| 1 | [gguf](https://huggingface.co/{user_name}/{model_name}/tree/main) | `cortex run {model_name}` |
## Use it with Jan (UI)
Expand All @@ -177,9 +170,13 @@ 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.strip())
print("Successfully created README.md")
except Exception as e:
print(f"Error occurred: {str(e)}")
raise e
EOF
- name: Upload README.md to HuggingFace Repository
Expand Down

0 comments on commit c6f99bc

Please sign in to comment.