From 43ce8f15414d5f25920c01e78c4f801db5383b4d Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 2 Nov 2023 13:48:23 -0700 Subject: [PATCH] Added autokey setup, updated readme --- README.md | 23 ++++++-- .../ChatGPT AutoHotkey Utility.ahk | 0 autohotkey/GptAutocomplete.py | 50 ++++++++++++++++++ Icon.ico => autohotkey/Icon.ico | Bin _jxon.ahk => autohotkey/_jxon.ahk | 0 5 files changed, 70 insertions(+), 3 deletions(-) rename ChatGPT AutoHotkey Utility.ahk => autohotkey/ChatGPT AutoHotkey Utility.ahk (100%) create mode 100644 autohotkey/GptAutocomplete.py rename Icon.ico => autohotkey/Icon.ico (100%) rename _jxon.ahk => autohotkey/_jxon.ahk (100%) diff --git a/README.md b/README.md index 8dea8c6..e97f4d3 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,22 @@ # ChatGPTAutocomplete -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. \ No newline at end of file +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 diff --git a/ChatGPT AutoHotkey Utility.ahk b/autohotkey/ChatGPT AutoHotkey Utility.ahk similarity index 100% rename from ChatGPT AutoHotkey Utility.ahk rename to autohotkey/ChatGPT AutoHotkey Utility.ahk diff --git a/autohotkey/GptAutocomplete.py b/autohotkey/GptAutocomplete.py new file mode 100644 index 0000000..007342b --- /dev/null +++ b/autohotkey/GptAutocomplete.py @@ -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) + + diff --git a/Icon.ico b/autohotkey/Icon.ico similarity index 100% rename from Icon.ico rename to autohotkey/Icon.ico diff --git a/_jxon.ahk b/autohotkey/_jxon.ahk similarity index 100% rename from _jxon.ahk rename to autohotkey/_jxon.ahk