Skip to content

Commit

Permalink
initial sources
Browse files Browse the repository at this point in the history
  • Loading branch information
cdemers committed Oct 19, 2023
1 parent e7eb406 commit 861b0c8
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/release.yaml
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 }}

58 changes: 58 additions & 0 deletions question
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.")

0 comments on commit 861b0c8

Please sign in to comment.