Added autokey setup, updated readme

This commit is contained in:
Max Gialanella 2023-11-02 13:48:23 -07:00
parent f254fcf1cc
commit 43ce8f1541
5 changed files with 70 additions and 3 deletions

View File

@ -3,3 +3,20 @@
Scripts and tools to make chat gpt write code for you.
Lets all be honest here, this is just the beginning of the end for software engineers.
Might as well make your coding super efficient in the mean time.
### How to run
First Setup your API keys with OpenAI
### Autohotkey Setup - Windows
* Install AutoHotKey
* Download the AutoHotKey directory
* Add your secret API key to the script and save
* Double Click the .ahk file to run it
* Type in what you want chat GPT to generate in a text editor or VS code
* Press ~ to run script
### Autokey Setup - Linux
* Install Autokey
* Copy the contents of the Autokey directory to your local autokey config folder (or just create a new script and then paste in the contents)
* Assign a "hotkey"
* Press your hotkey to run the script, script output will be pasted into whatever is open

View File

@ -0,0 +1,50 @@
# importing the requests library
import requests
import json
retCode, userPrompt = dialog.input_dialog('Gpt Snippet','Enter a prompt')
# exit if no input or user hits cancel
if userPrompt == '' or retCode == 1:
exit(0)
# use prompt as comment
cleanOutput = "// " + userPrompt + "\n"
# post to openai
API_Key = "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"
URL = "https://api.openai.com/v1/chat/completions"
prompt = 'Use the following input to create a code snippet. Only output ES6 Javascript no additional details or explanations, only code. No other output, only JS code. Create a clear, concise output with readable camel case variable names. Make sure the code is clear, understandable and maintainable. If its necessary use existing variable names with the output. Use 4 spaces per tab. The input is:'
HEADERS = {
"Content-Type": "application/json",
"Authorization": "Bearer "+API_Key
}
PARAMS = {
"model": "gpt-4",
"messages": [
{
"role": "user",
"content": prompt + userPrompt
}
]
}
response = requests.post(URL, data = json.dumps(PARAMS), headers = HEADERS)
data = response.json()
# Clean up chat GPT response
gptResponse = str(data['choices'][0]['message']['content'])
gptResponse = gptResponse.replace("```Javascript","")
gptResponse = gptResponse.replace("```javascript","")
gptResponse = gptResponse.replace("```","")
cleanOutput += gptResponse.strip()
#cleanOutput = cleanOutput.replace(" ","\t")
exitCode, userInput = dialog.info_dialog('Gpt Snippet Review',"Generated: \n\n" + cleanOutput + "\n\npress ESC to cancel")
# Dont paste output if user hit escape
if exitCode == 0:
keyboard.send_keys(cleanOutput)

View File

Before

Width:  |  Height:  |  Size: 112 KiB

After

Width:  |  Height:  |  Size: 112 KiB