Skip to content

Commit

Permalink
timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
ecornell committed Apr 5, 2023
1 parent 72138df commit ebccbca
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
13 changes: 7 additions & 6 deletions AI-Tools.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -284,7 +285,7 @@ HandleResponse(data, mode, promptName, input) {
Sleep 500
A_Clipboard := _oldClipboard

} finally {
} finally {
global _running := false
RestoreCursor()
}
Expand All @@ -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)
Expand Down
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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

1 change: 1 addition & 0 deletions _Cursor.ahk
Original file line number Diff line number Diff line change
@@ -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) {

Expand Down
10 changes: 6 additions & 4 deletions settings.ini.default
Original file line number Diff line number Diff line change
Expand Up @@ -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

;------------------------------------------------------------------------------
Expand Down Expand Up @@ -150,7 +152,7 @@ temperature=0
[prompt_continue]
prompt=""
replace_selected=False
menu_text="& Space - Continue writting"
menu_text="Space& - Continue writting"
response_start=" "

;------------------------------------------------------------------------------
Expand Down

0 comments on commit ebccbca

Please sign in to comment.