From e7c6c49f44147f39f6b188d033b506b2b728807c Mon Sep 17 00:00:00 2001 From: Charle Demers Date: Thu, 19 Oct 2023 16:44:46 -0400 Subject: [PATCH] ameliorate the release action --- .github/workflows/release.yaml | 18 +++++++---- question | 58 --------------------------------- question.py | 59 +++++++++++++++++++++++++++++++++- 3 files changed, 70 insertions(+), 65 deletions(-) delete mode 100755 question mode change 120000 => 100755 question.py diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 8c37dcd..0853a7d 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,9 +1,9 @@ -name: Create Release +name: Create Release and Brew Formula on: push: tags: - - 'v*.*.*' # Trigger the workflow on push to tags matching the semantic versioning format + - '[0-9]+.[0-9]+.[0-9]+' # Semantic versioning tags match trigger only jobs: release: @@ -12,6 +12,12 @@ jobs: - name: Checkout code uses: actions/checkout@v2 + - name: Prepare Brew Formula + run: | + mkdir brew-formula + cp question.py brew-formula/question + tar czf question.tgz -C brew-formula question + - name: Create GitHub Release id: create_release uses: actions/create-release@v1 @@ -23,14 +29,14 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Upload Release Asset + - name: Upload Brew Formula as Release Asset id: upload-release-asset uses: actions/upload-release-asset@v1 with: upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./question.py - asset_name: question.py - asset_content_type: text/x-python + asset_path: ./question.tgz + asset_name: question.tgz + asset_content_type: application/gzip env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/question b/question deleted file mode 100755 index 11c7b7d..0000000 --- a/question +++ /dev/null @@ -1,58 +0,0 @@ -#!/usr/bin/env python3 - -import os -import sys -import openai -import logging -from rich.markdown import Markdown -from rich import print as rprint -from halo import Halo - -# Setup logging based on environment variable -log_level = os.environ.get("LOG_LEVEL", "WARNING").upper() -logging.basicConfig(level=getattr(logging, log_level)) - -# Read OpenAI API key from environment variable -api_key = os.environ.get("OPENAI_API_KEY") -if not api_key: - logging.error("OPENAI_API_KEY environment variable not set.") - exit(1) - -openai.api_key = api_key - -def call_openai_api(question): - try: - MODEL = "gpt-4-0613" - messages = [{"role": "user", "content": question}] - - # Make API call - with Halo(text='Waiting for response...', spinner='dots'): - response = openai.ChatCompletion.create( - model=MODEL, - messages=messages, - temperature=0, - ) - return response['choices'][0]['message']['content'] - except Exception as e: - logging.error(f"API call failed: {e}") - return None - -if __name__ == "__main__": - if len(sys.argv) < 2: - logging.error("No query string provided.") - exit(1) - - # Get user input from command line argument - question = sys.argv[1] - logging.info(f"Received input: {question}") - - # Call OpenAI API - response = call_openai_api(question) - - # Output response or failure message - if response: - markdown_response = Markdown(response) - rprint("Assistant says:", markdown_response) - else: - print("Failed to get a response.") - diff --git a/question.py b/question.py deleted file mode 120000 index 705c06e..0000000 --- a/question.py +++ /dev/null @@ -1 +0,0 @@ -question \ No newline at end of file diff --git a/question.py b/question.py new file mode 100755 index 0000000..11c7b7d --- /dev/null +++ b/question.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python3 + +import os +import sys +import openai +import logging +from rich.markdown import Markdown +from rich import print as rprint +from halo import Halo + +# Setup logging based on environment variable +log_level = os.environ.get("LOG_LEVEL", "WARNING").upper() +logging.basicConfig(level=getattr(logging, log_level)) + +# Read OpenAI API key from environment variable +api_key = os.environ.get("OPENAI_API_KEY") +if not api_key: + logging.error("OPENAI_API_KEY environment variable not set.") + exit(1) + +openai.api_key = api_key + +def call_openai_api(question): + try: + MODEL = "gpt-4-0613" + messages = [{"role": "user", "content": question}] + + # Make API call + with Halo(text='Waiting for response...', spinner='dots'): + response = openai.ChatCompletion.create( + model=MODEL, + messages=messages, + temperature=0, + ) + return response['choices'][0]['message']['content'] + except Exception as e: + logging.error(f"API call failed: {e}") + return None + +if __name__ == "__main__": + if len(sys.argv) < 2: + logging.error("No query string provided.") + exit(1) + + # Get user input from command line argument + question = sys.argv[1] + logging.info(f"Received input: {question}") + + # Call OpenAI API + response = call_openai_api(question) + + # Output response or failure message + if response: + markdown_response = Markdown(response) + rprint("Assistant says:", markdown_response) + else: + print("Failed to get a response.") +