From ebccbca48ae830ce5019f5026d096b2fe832e244 Mon Sep 17 00:00:00 2001 From: Eli Cornell Date: Tue, 4 Apr 2023 19:18:07 -0500 Subject: [PATCH] timeout --- AI-Tools.ahk | 13 +++++++------ README.md | 14 +++++++++----- _Cursor.ahk | 1 + settings.ini.default | 10 ++++++---- 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/AI-Tools.ahk b/AI-Tools.ahk index 94ff1b9..db0bde2 100644 --- a/AI-Tools.ahk +++ b/AI-Tools.ahk @@ -14,7 +14,7 @@ SendMode "Input" if not (FileExist("settings.ini")) { api_key := InputBox("Enter your OpenAI API key", "AI-Tools-AHK : Setup", "W400 H100").value if (api_key == "") { - MsgBox("You must enter an OpenAI key to use this script. Please restart the script and try again.") + MsgBox("To use this script, you need to enter an OpenAI key. Please restart the script and try again.") ExitApp } FileCopy("settings.ini.default", "settings.ini") @@ -208,17 +208,18 @@ CallAPI(mode, promptName, prompt, input, promptEnd) { apiKey := GetSetting(mode, "api_key", GetSetting("settings", "default_api_key")) req := ComObject("Msxml2.ServerXMLHTTP") - + req.open("POST", endpoint, true) req.SetRequestHeader("Content-Type", "application/json") req.SetRequestHeader("Authorization", "Bearer " apiKey) ; openai req.SetRequestHeader("api-key", apiKey) ; azure req.SetRequestHeader('Content-Length', StrLen(bodyJson)) req.SetRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT") - + req.SetTimeouts(0, 0, 0, GetSetting("settings", "timeout", 120) * 1000) ; read, connect, send, receive + req.send(bodyJson) - req.WaitForResponse(GetSetting("settings", "timeout", 60)) + req.WaitForResponse() if (req.status == 200) { ; OK. data := req.responseText HandleResponse(data, mode, promptName, input) @@ -284,7 +285,7 @@ HandleResponse(data, mode, promptName, input) { Sleep 500 A_Clipboard := _oldClipboard - } finally { + } finally { global _running := false RestoreCursor() } @@ -307,7 +308,7 @@ InitPopupMenu() { _iMenu.Add ; Add a separator line. } else { menu_text := GetSetting(v_promptName, "menu_text", v_promptName) - if (RegExMatch(menu_text, "^[^&]*&[^&]*$") == 0) { + if (RegExMatch(menu_text, "^[^&]*&[^&]*$") == 0) { if (id == 10) keyboard_shortcut := "&0 - " else if (id > 10) diff --git a/README.md b/README.md index 41c145c..c8b9db5 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,8 @@ This is a Windows tool that enables running custom OpenAI prompts on text in any window using global hotkeys. +i.e. Low-friction AI text editing ("spicy autocomplete") anywhere in Windows. + **Where can it be used?** Almost anywhere in Windows where you can enter text. @@ -41,9 +43,6 @@ The default hotkeys and prompts are set to the following: `Ctrl+Alt+Shift+k` - (Manual-select text - Prompt Menu) - Opens the prompt menu to pick the prompt to run on the selected text. -### How does it work? - - ## Options @@ -56,7 +55,7 @@ To have the script start when windows boots up, select "Start With Windows" from   -## Supported APIs and Models +## Supported OpoenAI APIs and Models OpenAI /v1/chat/completions (Default) - gpt-3.5-turbo @@ -67,8 +66,13 @@ Azure /openai/deployments/***/completions - text-davinci-003 +## Compatibility +Tested on Windows 10 Pro 22H2 64-bit. ## Credits -TheArkive (JXON_ahk2) and the AHK community. +TheArkive (JXON_ahk2), iseahound (SetSystemCursor), and the AHK community. + +- https://github.com/iseahound/SetSystemCursor +- https://github.com/TheArkive/JXON_ahk2 diff --git a/_Cursor.ahk b/_Cursor.ahk index 33e340c..6fc21aa 100644 --- a/_Cursor.ahk +++ b/_Cursor.ahk @@ -1,5 +1,6 @@ ; Source: Serenity - https://autohotkey.com/board/topic/32608-changing-the-system-cursor/ ; Modified: iseahound - https://www.autohotkey.com/boards/viewtopic.php?t=75867 +; MIT - https://github.com/iseahound/SetSystemCursor SetSystemCursor(Cursor := "", cx := 0, cy := 0) { diff --git a/settings.ini.default b/settings.ini.default index 5242cc7..f97913c 100644 --- a/settings.ini.default +++ b/settings.ini.default @@ -25,10 +25,12 @@ menu_hotkey = ^!+k ; reload the settings.ini file if it is changed ; cursor_wait_file : (Optional) The mouse cursor when waiting for response ; debug : (Optional) Enable writting debug logs to ./debug.log file +; timeout : (Optional) The number of seconds to wait for a response ;------------------------------------------------------------------------------ -default_mode=mode_chat_completion -reload_on_change=false -;cursor_wait_file =wait-1.ani +default_mode = mode_chat_completion +reload_on_change = false +timeout = 120 +;cursor_wait_file = wait-1.ani ;debug=true ;------------------------------------------------------------------------------ @@ -150,7 +152,7 @@ temperature=0 [prompt_continue] prompt="" replace_selected=False -menu_text="& Space - Continue writting" +menu_text="Space& - Continue writting" response_start=" " ;------------------------------------------------------------------------------