Skip to content

Commit

Permalink
Merge pull request #9 from Rod-Gomes/Rod-Gomes-patch-1
Browse files Browse the repository at this point in the history
Ensuring Accurate Text Selection
  • Loading branch information
ecornell authored Aug 9, 2024
2 parents d8f170a + eea60f6 commit ff76fae
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions AI-Tools.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ PromptHandler(promptName, append := false) {
;###

SelectText() {
A_Clipboard := ""
Send "^c"
ClipWait(2)
text := A_Clipboard
Expand Down Expand Up @@ -201,6 +202,10 @@ GetBody(mode, promptName, prompt, input, promptEnd) {
}

CallAPI(mode, promptName, prompt, input, promptEnd) {
if (StrLen(input) < 1) {
; Input is too short. No request will be made to the API.
return
}

body := GetBody(mode, promptName, prompt, input, promptEnd)
bodyJson := Jxon_dump(body, 4)
Expand All @@ -219,16 +224,30 @@ CallAPI(mode, promptName, prompt, input, promptEnd) {
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)
try {
req.send(bodyJson)
req.WaitForResponse()

req.WaitForResponse()
if (req.status == 200) { ; OK.
data := req.responseText
HandleResponse(data, mode, promptName, input)
} else {
MsgBox "Status " req.status " " req.responseText, , 16
if (req.status == 0) {
RestoreCursor()
global _running := false
MsgBox "Error: Unable to connect to the API. Please check your internet connection and try again.", , 16
return
} else if (req.status == 200) { ; OK.
data := req.responseText
HandleResponse(data, mode, promptName, input)
} else {
RestoreCursor()
global _running := false
MsgBox "Error: Status " req.status " - " req.responseText, , 16
return
}
} catch {
RestoreCursor()
global _running := false
MsgBox "Error: Unable to connect to the API. Please check your internet connection and try again.", , 16
return
}

}

HandleResponse(data, mode, promptName, input) {
Expand Down

0 comments on commit ff76fae

Please sign in to comment.