Skip to content

Commit

Permalink
Switch to Msxml2.ServerXMLHTTP - fix unicode issue
Browse files Browse the repository at this point in the history
  • Loading branch information
ecornell committed Mar 21, 2023
1 parent e35ea8f commit 72138df
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions AI-Tools.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -201,22 +201,24 @@ GetBody(mode, promptName, prompt, input, promptEnd) {
CallAPI(mode, promptName, prompt, input, promptEnd) {

body := GetBody(mode, promptName, prompt, input, promptEnd)
bodyJson := Jxon_dump(body, 4)
LogDebug "bodyJson ->`n" bodyJson

endpoint := GetSetting(mode, "endpoint")
apiKey := GetSetting(mode, "api_key", GetSetting("settings", "default_api_key"))

req := ComObject("WinHttp.WinHttpRequest.5.1")
req := ComObject("Msxml2.ServerXMLHTTP")

req.open("POST", endpoint, true)
req.SetTimeouts(10000, 30000, 30000, 60000) ; resolve, connect, send, receive
req.SetRequestHeader("Content-Type", "application/json")
req.SetRequestHeader("Authorization", "Bearer " apiKey) ; openai
req.SetRequestHeader("api-key", apiKey) ; azure

bodyJson := Jxon_dump(body, 4)
LogDebug "bodyJson ->`n" bodyJson

req.SetRequestHeader('Content-Length', StrLen(bodyJson))
req.SetRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT")

req.send(bodyJson)
req.WaitForResponse()

req.WaitForResponse(GetSetting("settings", "timeout", 60))
if (req.status == 200) { ; OK.
data := req.responseText
HandleResponse(data, mode, promptName, input)
Expand Down Expand Up @@ -305,7 +307,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

0 comments on commit 72138df

Please sign in to comment.