From c6f99bc87c55779c6a37b6306964d7ad5814f654 Mon Sep 17 00:00:00 2001 From: Minh141120 Date: Thu, 23 Jan 2025 20:04:47 +0700 Subject: [PATCH] chore: fix license genarator --- .github/workflows/convert-model-all-quant.yml | 67 +++++++++---------- 1 file changed, 32 insertions(+), 35 deletions(-) diff --git a/.github/workflows/convert-model-all-quant.yml b/.github/workflows/convert-model-all-quant.yml index eabd9c6..c638b2d 100644 --- a/.github/workflows/convert-model-all-quant.yml +++ b/.github/workflows/convert-model-all-quant.yml @@ -100,36 +100,29 @@ 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'): @@ -137,13 +130,13 @@ jobs: 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} @@ -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) @@ -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