-
Notifications
You must be signed in to change notification settings - Fork 1
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
2 changed files
with
94 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name: Create Release | ||
|
||
on: | ||
push: | ||
tags: | ||
- 'v*.*.*' # Trigger the workflow on push to tags matching the semantic versioning format | ||
|
||
jobs: | ||
release: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Create GitHub Release | ||
id: create_release | ||
uses: actions/create-release@v1 | ||
with: | ||
tag_name: ${{ github.ref }} | ||
release_name: Release ${{ github.ref }} | ||
draft: false | ||
prerelease: false | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Upload 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 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
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,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.") | ||
|