#NoEnv ; (MW:2023) (MW:2023) TxtClient_GPT ; I use 144dpi this may be the only DPI working as intended/ This is untested. #NoTrayicon ListLines,Off SetBatchLines,-1 SetWinDelay,-1 #Persistent #Singleinstance,Force Setworkingdir,% (splitpath(A_AhkPath)).dir DetectHiddenWindows,On DetectHiddenText, On SetTitleMatchMode,2 SetTitleMatchMode,Slow coordMode,ToolTip,Screen coordmode,Mouse, Screen InitialQuestion:= A_args[1]? A_args[1] : "" ; "Marius is " ; test* loop,parse,% "VarZ,Menus,Hookinit,Optionz,Dimz,RegRead,OnMessages,Main,StatusBarInit,ShowMainGui",`, gosub,% a_loopfield return, Optionz: Opt_DebugPayload:= False MattTheme:= False ;set to false if you are not Matt , Opt_Appear_TransitionN := " slide vpos " , Opt_Appear_TransitionS := " slide vneg " , Opt_Appear_TransitionDurMs:= 200 , Opt_Hide_TransitionN := " Slide VNeg " , Opt_Hide_TransitionS := " Slide Vpos " , Opt_Hide_TransitionDurMs := 150 , Opt_GuiBlur := False ; works with AeroGlass , Opt_GuiTrans := False ; works with AeroGlass , Opt_SpawnOnMouse := True , Opt_MultiLang := False , Opt_SeeResultJson := False ; Gpt options in json payload ; , Opt_Tokens:= False , Opt_MaxTokens:= 3999 , Opt_Temperature:= 0.001 ; 0-Strict / 1-Creative ; return, Dimz: opt_guicolor:= 070011 , opt_gui_fontcol:= "c7488D8" , Const_OtherGuiMargin:= MattTheme? 10 : 18 ; other system metrics for window frame dimension approximation , Opt_GuiQuestionLines:= "r2" , Opt_GuiTabMarginSz := 18 , opt_GuiTabTopMargin := 20 , Opt_Gui_Main_W := 450 , Opt_Gui_Question_W := Opt_Gui_Main_W -100 , Opt_Gui_Main_H := 320 , Opt_GUI_Answer_W := Opt_Gui_Main_W - Const_OtherGuiMargin -Opt_GuiTabMarginSz -24 , Opt_GUI_Answer_H := 80 ; Opt_Gui_Main_h - opt_GuiTabTopMargin*4 , Opt_Guitab_W := Opt_Gui_Main_W -( 2*opt_GuiTabMarginSz ) -Const_OtherGuiMargin return, ^+v:: ; paste multiline test string:="," if(instr(clipboard,chr(10))) { Loop,Parse,clipboard,`n string.= a_loopfield ",`n" , count++ GuiControl,,% InputQuestionhwnd,% string GuiControl,Choose,r1,ahk_id %InputQuestionhwnd% } return, OnMessages: onexit,exit onmessage(0x201,"WM_LBUTTDOWNUP") ;onmessage(0x202,"WM_LBUTTDOWNUP") OnMessage(0x6,"onActiv8") OnMessage(0x404,"AHK_NOTIFYICON") return, ShowMainGui: mousegetpos,x_,y_ ( x_> (a_screenwidth -Opt_Gui_Main_W-80))? x_ -= Opt_Gui_Main_W-120 : ( x_<64 ? x_:= 120) ( y_> (a_screenheight -Opt_Gui_Main_h-80))? x_-= Opt_Gui_Main_W-120 : ( y_<64 ? y_:= 120) winmove(hGuiA,x_ -(Opt_Gui_Main_W/2),y_ -(Opt_Gui_Main_H/5)) Gui,Show,% (Opt_SpawnOnMouse? ("x" . x_ -(Opt_Gui_Main_W/2) . " y" . y_ -(Opt_Gui_Main_H/5)):()) " w" . Opt_Gui_Main_W . " h" . Opt_Gui_Main_H . " NA HIDE",% a_scriptname " - GuiHWND: " hGuiA settimer,Trans_Enact_OrNot,-10 if(!api_key) gosub,DataEntryWindow ;msgbox,% "please enter api key in the settings tab." Gui,PleaseWait:Show,Na Hide (wingetpos(hguia).y > (a_screenwidth/2))? Opt_Appear_Transition:= Opt_Appear_TransitionS : Opt_Appear_Transition:= Opt_Appear_TransitionN (Opt_GuiBlur? dBlur(hguia)) WinAnimate(hGuiA,"activate " Opt_Appear_Transition,Opt_Appear_TransitionDurMs) winset,style,+0x40000,ahk_id %hGuiA% settimer,Trans_Enact_OrNot,-1000 GuiControl,hide,AnswerEdit ;GuiControl,hide,ToggleListView ;GuiControl,Move,Answer, % "w" Opt_Gui_Main_H if(Opt_MultiLang) GuiControl,,Answer,% "ChatGPT Response translated with Google Translate:" ;GuiControl,Move,AnswerEdit2, % "y+140 h" 500 ;GuiControl, hide, AnswerEdit2 GuiControl,hide,TextTranslate ; https://ahkde.github.io/docs/v1/lib/GuiControl.htm EM_SETCUEBANNER(InputQuestionhwnd, a_space "to ChatGPT3.5") if(InitialQuestion) { GuiControl,Text,%InputQuestionhwnd%,% InitialQuestion gosub,ButtonClick } GuiControl,Focus,% InputQuestionhwnd Return, onActiv8(wparam="",lparam="",msg="",hwnd="") { local static smicon:= b64_2_hicon(icoB64["smicon64"]) , lgicon:= b64_2_hicon(icoB64["lgicon64"]) ,large:=1, small:=0, m:= 0x80 SendMessage,m,small,smicon,,ahk_id %hWnd% ;WM_SETICON,ICON_SMALL SendMessage,m,large,lgicon,,ahk_id %hWnd% ;WM_SETICON,ICON_LARGE Return,ErrorLevel } WM_LBUTTDOWNUP(wparam,lparam,umsg,hwnd) { static xs, ys, closedeye (!closedeye? closedeye:=b64_2_hicon(icoB64["EyeClose48"])) global SbarhWnd,answer,AnswerEdithwnd,copiedthis if(hwnd=AnswerEdithwnd)||(hwnd=AnswerEdithwnd2) return, xCs:= lParam &0xffff, yCs:= lParam>>16 coordmode,Mouse,Screen ControlGetText,copiedthis , , ahk_id %SbarhWnd% mousegetpos,,,hwndmouse,ctrlhwndmouse,2 switch,ctrlhwndmouse { case,hGuiA,tabcontrolhwnd: PostMessage,0xA1,2 ; WM_NCLBUTTONDOWN - Same as dragging window by its tittlebar. case,SbarhWnd: if(xcs<55) { gui,Submit,NoHide ss:= wingetpos(SbarhWnd) tooltip,% "Hiding double click tray to show...",ss.x-100,ss.y-35.1 SendMessage,0x40F,0,% closedeye,,ahk_id %SbarhWnd% settimer,SBIconReset,-480 settimer,ttStop,-1180 settimer,HideMainGui,-1600 return, } PostMessage,0xA1,2 case,AnswerEdithwnd2,AnswerEdithwnd: msgbox,% "sdaads " clipboard:= answer default:PostMessage,0xA1,2 } return, ; switch,umsg { ; case,513 : mousegetpos,xs,ys ; sleep 200, mousegetpos,xn,yn ; if(xn!=xs||yn!=Ys) { ; PostMessage,0xA1,2 ; WM_NCLBUTTONDOWN ; return,1 ; } else,return, ; case,514 : mousegetpos,xf,yf ; return, ; } ;tooltip % wparam "`n " lparam "`n" umsg } Main: (MattTheme? Aero_StartUp()) menu,tray,icon,% "HICON: " b64_2_HICON(icoB64["tray24"]) ;24x24 @144 dpi (SM_CXSMICON,SM_CYSMICON) menu,tray,icon ; api_key := "thisApikey" ; https://platform.openai.com/account/api-keys ; optionally Your OpenAI API-key. ; The endpoint URL for the GPT-3 API. Gui,PleaseWait: -dpiscale +LastFound +AlwaysOnTop +Disabled -resize -Caption +ToolWindow +hwndhGUIPleaseWait +0x40000 Gui,PleaseWait: Color,%opt_guicolor% Gui,PleaseWait: Add,Text,xm vTextA w120 Center,% "Please wait..." Gui,PleaseWait: Add,Text,xs vTextB w99 Center,% "Loading..." Gui,PleaseWait: Show,% "x300 y" (A_ScreenHeight/2),% hGUIPleaseWait Gui,New,-dpiscale +hwndhGuiA +MaxSize%Opt_Gui_Main_W%x%Opt_Gui_Main_H% +MinSize%Opt_Gui_Main_W%x%Opt_Gui_Main_H% +ToolWindow -caption +AlwaysOnTop +LastFound -0x40000 -DPIScale,% hGuiA ;+e0x80000 gui,color,% opt_guicolor,% opt_guicolor if(Opt_fontlarge) Gui,Font,s12 HeaderTitles:= "Main" (Opt_MultiLang? HeaderTitles.= "|TranslateJson") (opt_seejson? HeaderTitles.= "|ResultJson") HeaderTitles.= "|Settings" Gui,Add,Tab3 ,% "c" opt_guicolor " hwndtabcontrolhwnd x" opt_GuiTabMarginSz " y" opt_GuiTabTopMargin " w" Opt_Guitab_W " h" Opt_Gui_Main_H-38,% HeaderTitles Gui,Tab,% "Main" ;Gui,Add,Text,,Question to ChatGPT: if(opt_richtext_question) { hModuleME := DllCall("kernel32.dll\LoadLibrary", Str,"msftedit.dll", Ptr) vPos := (!vShowBuiltIn1 && !vShowBuiltIn2) ? "y30" : "" ;make room for toolbar if needed Gui,Add,Custom,% vPos " ClassRICHEDIT50W vInputQuestion hwndInputQuestionhwnd x" opt_GuiTabMarginSz + 4 " y41 h28 w" Opt_Gui_Question_W "c" opt_guicolor ControlSetText,RICHEDIT50W1,% "RICH 1",% "ahk_id " hGui } else { Gui,Add,Edit,% " vInputQuestion hwndInputQuestionhwnd x20 y" opt_GuiTabTopMargin +31 " h32 w" Opt_Gui_Question_W " " Opt_GuiQuestionLines " " opt_gui_fontcol GuiControl, Choose, r4,ahk_id %InputQuestion% Gui,Font,c7488D8 ; GuiControl,% InputQuestionhwnd, , , , , 0xFFFFFF ControlSetText,% InputQuestionhwnd, , , , , 0xFFFFFF } SetExplorerTheme(tabcontrolhwnd) winset,style,-0x2000,ahk_id %tabcontrolhwnd% if(Opt_fontlarge) Gui,Font,s12 %opt_gui_fontcol% Gui,Font,% opt_gui_fontcol if(Opt_MultiLang) { Gui,Add,Text,Section,% "Source Language:" Gui,Add,Radio,ys Group gRadioGroupSelection Checked1 vMyRadioA,% "German" Gui,Add,Radio,ys gRadioGroupSelection vMyRadioB,% "English" Gui,Add,Radio,ys gRadioGroupSelection vMyRadioC,% "Mix" } Gui,Add,CheckBox,ys gToggleListView checked vToggleListView,% "ListView History" Gui,Tab,% "Settings" if(Opt_fontlarge) Gui,Font,s12 Gui,Add,Text,x38 y63 Section,% "API Key:" if(Opt_Tokens) { Gui,Add,Text,ys x+110,% "total_tokens:" Gui,Add,Edit,ys w220 vTextApiKey,% "Counter" } if(Opt_fontlarge) Gui,Font,s11 Gui,Add,Edit,% opt_gui_fontcol " x112 y60 vApi_key w" Opt_Gui_Main_W-165 " h25 center Password",% api_key if(Opt_fontlarge) Gui,Font,s12 Gui,Tab,% "Main" Gui,Add,Button,% "gButtonClick x" 19 + Opt_Gui_Question_W " y50 w49 h50 default Section",% "Ask" if(Opt_MultiLang) Gui,Add,Button,ys gTranslateBeforeAsk w200 h30,% "Translate before Ask" Gui,Add,Button,ys gReloadApp +hwndreloadbutthwnd w68 h30, % "Reload" guicontrol,hide,% reloadbutthwnd Gui,Add,Text,x24 y80 vAnswer +hwndAnswerHeadingHwnd,% "Answer..." guicontrol,Hide,% AnswerHeadingHwnd if(opt_richtext_answer) { hModuleME := DllCall("kernel32.dll\LoadLibrary", Str,"msftedit.dll", Ptr) vPos := (!vShowBuiltIn1 && !vShowBuiltIn2) ? "y30" : "" ;make room for toolbar if needed Gui,Add,Custom,% vPos " ClassRICHEDIT50W vAnswerEdit hwndAnswerEdithwnd x20 y80 r10 w%Opt_GUI_Answer_W%" Opt_GUI_Answer_W " h" Opt_GUI_Answer_H ControlSetText,RICHEDIT50W1,% "RICH 1", % "ahk_id " hGui } else,Gui,Add,Edit,% "vAnswerEdit +hwndanswerEdithwnd x20 y96 r9 w" Opt_GUI_Answer_W " " Opt_GuiQuestionLines " h" Opt_GUI_Answer_H " c" opt_guicolor ;Gui,Add,Edit,vAnswerEdit +hwndAnswerEdithwnd x20 y80 r10 w%Opt_GUI_Answer_W% Gui,Add,Text,vTextTranslate,% "Translate" Gui,Add,Edit,% "vAnswerEdit2 +hwndAnswerEdithwnd2 x20 y" opt_GuiTabTopMargin +79 " r8 w" Opt_GUI_Answer_W " h" Opt_GUI_Answer_H " " opt_gui_fontcol if(opt_seejson) { Gui,Tab,% "TranslateJson" Gui,Add,Text,,Json Gui,Add,Edit,vJsonEdit r30 w%Opt_GUI_Answer_W%, } if(Opt_SeeResultJson) { Gui,Tab,% "ResultJson" Gui,Add,Text,,Result Gui,Add,Edit,vResultEdit x100 r30 w%Opt_GUI_Answer_W% ;Gui,Show,% "x100 y" (A_ScreenHeight/10), % a_scriptname " - GuiHWND: " hGuiA } return, Trans_Enact_OrNot: ; (Opt_GuiTrans? VarSetCapacity(rect0,16,0xff) , DllCall("dwmapi\DwmExtendFrameIntoClientArea","uint",hGuiA,"uint",&rect0)) if(Opt_GuiTrans) { VarSetCapacity(rect0,16,0xff) DllCall("dwmapi\DwmExtendFrameIntoClientArea","uint",hGuiA,"uint",&rect0) } return, ;~+4:: DataEntryWindow: gui_W:=300, gui_H:=138 WS_POPUP := 0x80000000, WS_CHILD := 0x40000000 Gui,1:+LastFound +hWndhGui1 +Owner +AlwaysOnTop +hwndghwnd +0x40000 -0x400000 Gui,1:Color,181535 ;Gui, 1: Add, Picture, w300 h165 x0 y0 AltSubmit BackgroundTrans, %A_ScriptDir%\Ressources\grey.png Gui,1:Font,s11 bold,Segoe UI Parent_ID := WinExist() Gui,2:Font,s11 bold,Segoe UI ;Gui, 2:margin,1,1 Gui,2:-Caption +hWndhGui2 +%WS_CHILD% -%WS_POPUP% gui,2:Color,000000,000000 Gui,2:Font,s11 bold, Segoe UI Gui,2:Add,Edit,x15 y+50 r1 w270 Limit51 +hwndAPIEntryEdithWnd Password vPassword gui,1:Add,Picture,X0 Y0 BackgroundTrans,% a_scriptdir "\glass.png" Gui,2:Add,Button, y+15 x205 w80 h30 gapiSubmitKey Default,Submit Gui,2:+LastFound Child_ID := WinExist() DllCall("SetParent","uint",Child_ID,"uint",Parent_ID) Gui,2:Add,Text,vtext1 %opt_gui_fontcol% w270 x17 y17 AltSubmit,% "Please enter API Key:" OnMessage(0x6,"col") Gui,1:Show,x-300 y-200 w%gui_W% h%gui_H%,% "no_glass" ;Gui, 1: Add, Text, vtext2 w270 x15 y15 AltSubmit, Please enter the Password: Gui,2: Show, x0 y0 w300 h135,no_glass Gui,1: hide dBlur(ghwnd) win_move(ghwnd,A_screenwidth*.5-gui_W,A_screenheight*.5-gui_H,"","","") Win_Animate(ghwnd,"hneg slide",200) winactivate,ahk_id %ghwnd% GuiControl,Focus,% APIEntryEdithWnd return, apiSubmitKey: Gui,2:Submit,NoHide Gui,1:Submit,NoHide ;try,api_key:= Password result:= strlen(Password)=51? "Good" : "Bad" Gui,2:Destroy Gui,1:Destroy if(result="Bad") { msgbox,262145,error,% "api-key length missmatch (51 chars), try again.",60 ifmsgbox,ok gosub,DataEntryWindow }return, col() { static go:= !false go:= winactive(ghwnd)? true : false (go? (col:=181535,col2:="c220040", col3:="c99aafe") : (col:= 050513, col2:= "c200570", col3:="c6688aff")) Gui, 1: Color,%col% Gui, 1: Font,%col2% Gui, 2: Font,%col3% guicontrol,Font,text1 guicontrol,Font,text2 } ;-===================================================================================================================================== StatusBarInit: init:= 0, inc:= Opt_Gui_Main_W -38 (init=0? Eye48_hIcon:= b64_2_hicon(icoB64["Eye48"])) Gui,Add,StatusBar,% "+hWndSbarhWnd +e0x2000000 " SB_SetParts(inc,100) SendMessage,0x40F,0,% Eye48_hIcon,,ahk_id %SbarhWnd% return, EM_SETCUEBANNER(HWND, Text) { ;EM_SETCUEBANNER-0x1501: msdn.microsoft.com/en-us/library/bb761639(v=vs.85).aspx Return,DllCall("SendMessage","Ptr",HWND,"UInt",0x1501,"Ptr",True,"WStr",Text,"Ptr") } RadioGroupSelection: return, ToggleListView: return, HideMainGui: (wingetpos(hguia).y > (a_screenwidth/2))? Opt_Hide_Transition:= Opt_Hide_TransitionS :Opt_Hide_Transition:= Opt_Hide_TransitionN (isWindowVisible(hGuiA)? WinAnimate(hGuiA,"hide " . Opt_Hide_Transition,Opt_Hide_TransitionDurMs)) return, TranslateBeforeAsk: Gui,Submit,NoHide GuiControl,,InputQuestion,% InputQuestionOLD return, ButtonClick: Gui,Submit,NoHide GuiControl,% AnswerHeadingHwnd,show Gui,PleaseWait:Show,% "x300 y" (A_ScreenHeight/2), % AttemptNo AttemptNo:= 1 api_url:= "https://api.openai.com/v1/engines/text-davinci-003/completions" ; Set up whttpr session. try,{ whttpr:= ComObjCreate("WinHttp.WinHttpRequest.5.1") whttpr.Open("POST", api_url) whttpr.SetRequestHeader("Content-Type","application/json") whttpr.SetRequestHeader("Authorization","Bearer " api_key) ; Prepare JSON payload. jsonY = } jsonY:= thisJson(InputQuestion) if(Opt_DebugPayload) msgbox,% jsonY ; for debug purposes ; Send the request and get the response whttpr.Send(jsonY) result := whttpr.ResponseText test := result ;msgbox,, % "A_LineNumber. " A_LineNumber " - isObject", % isObject(result) ;msgbox,, % "A_LineNumber. " A_LineNumber " - result", % result If test contains error { AttemptNo++ GuiControl,,AnswerEdit2,% "error" fileappend,% error "`n",% a_scriptdir "\chatGPT UI - mini - error A.txt" msgbox,,% "A_LineNumber. " A_LineNumber " - error A", % test,62 ;exitapp sleep,1000 ; GuiControl,PleaseWait:,TextB,% AttemptNo ;GoTo,ButtonClick } If test = { AttemptNo++ GuiControl,,AnswerEdit2, error fileappend,% error "`n", % a_scriptdir "\chatGPT UI - mini - error B.txt" msgbox,,% "A_LineNumber. " A_LineNumber " - error B", % test,5 ;sleep,1000 ;GuiControl, PleaseWait:, TextB, % AttemptNo ;GoTo, ButtonClick } Array:= [] ;Array := JSON.Load(result) Array:= JsonToAHK(result) ;msgbox,, % "A_LineNumber. " A_LineNumber " - isObject", % isObject[Array) i:= 1 While(i< 100) { ; ToolTip,% i ; setTimer,ttStop,-3000 Answer:= Array["choices"][i]["text"] If(Answer!="") Break, i++ } Result:= RegExReplace(Result,"^[\s\r\n]+|[\s\r\n]+$","") ; remove leading and trailing whitespaces Answer:= RegExReplace(Answer,"^[\s\r\n]+|[\s\r\n]+$","") ; remove leading and trailing whitespaces ;Answer := RegExReplace(Answer, "(?:\r\n|\r|\n)", " ") ; replaces line breaks with space Answer:= StrReplace(Answer,"ß", "ß") Answer:= StrReplace(Answer,"Ü", "Ä") Answer:= StrReplace(Answer,"ä", "ä") Answer:= StrReplace(Answer,"ܖ", "Ö") Answer:= StrReplace(Answer,"ö", "ö") Answer:= StrReplace(Answer,"Ã", "Ü") Answer:= StrReplace(Answer,"ü", "ü") Answer:= StrReplace(Answer,"ܼ", "ü") Answer:= StrReplace(Answer,"â", "-") Answer:= StrReplace(Answer,"°", "°") ; 100°C 100 Degrees ; Gemeinschaftsgefܼhl. allmächtige, ° = ; https://www.autohotkey.com/boards/viewtopic.php?style=19&p=384889#p384889 arr := {"ä": "ä" ,"ü" : "ü" ,"�": "ü" ,"ö" : "ö" ,"ß" : "ß" ,"Ü" : "Ü" ,"„" : "„" ,"“" : "“"} for,key,val in arr StrReplace(Answer, key, val) GuiControl,,AnswerEdit,% Answer? Answer : Result ; GuiControl,-Redraw,PleaseWait GuiControl,, AnswerEdit2,% Answer try,thisBeautifyJson:= BeautifyJson(Result) GuiControl,,ResultEdit,% thisBeautifyJson ;GuiControl,, ResultEdit, % Result% ; Gui, PleaseWait: Destroy Gui,PleaseWait:show,Hide result = thisAPI_completion_tokens := Array["usage", "completion_tokens"] thisAPI_prompt_tokens := Array["usage", "prompt_tokens"] thisAPI_total_tokens := Array["usage", "total_tokens"] thisAPI_created := Array["created"] ; "`t" time := 1970 ,time += thisAPI_created, s , diff -= A_NowUTC, h , time += diff, h FormatTime,TimeStamp,%time%,dd.MM.yyyy HH-mm-ss tt ; 24.März.2018 05-20-37 GuiControl,,TextApiKey,% "[ " thisAPI_total_tokens " ] " TimeStamp thisLV_ADD:= InputQuestion "`t" . Answer "`t" . Answer2 "`t" fileappend, % thisLV_ADD "`n", % a_scriptdir "\chatGPT UI - mini - history.txt" this_ADD := InputQuestion "`t" . Answer "`t" . Answer2 "`t" . Array["choices", 1, "finish_reason"] "`t" . Array["choices", 1, "index"] "`t" . Array["choices", 1, "logprobs"] "`t" . Array["choices", 1, "text"] "`t" . Array["created"] "`t" . Array["id"] "`t" . Array["model"] "`t" . Array["object"] "`t" . Array["usage", "completion_tokens"] "`t" . Array["usage", "prompt_tokens"] "`t" . Array["usage", "total_tokens"] "`n" fileappend,% thisLV_ADD "`n",% a_scriptdir "\chatGPT UI - mini - history-FULL.txt" this_LV_Line:= InputQuestion "`t" . Answer "`t" . Answer2 "`n" fileappend,% this_LV_Line "`n", % a_scriptdir "\chatGPT UI - mini - this_LV_Line.txt" return, ReloadApp: Gui,Submit,NoHide menu,tray,noicon reload, return ttStop: toolTip, return GuiClose: ExitApp, GuiEscape: settimer,HideMainGui,-10 return, ; json = {"ItemN": 625, "Digital": ["", "", {"key": "value"}], "LocalDel": "Check"} ; ahkObj := JsonToAHK(json) ;MsgBox, % ahkObj["Digital", 3, "key"] JsonToAHK(json, rec:= False) { static doc:= ComObjCreate("htmlfile") , __:= doc.write("") , JS:= doc.parentWindow if(!rec) obj:= %A_ThisFunc%(JS.eval("(" . json . ")"), True) else,if(!IsObject(json)) obj:= json else,if JS.Object.prototype.toString.call(json) == "[object Array]" { obj := [] Loop % json.length obj.Push( %A_ThisFunc%(json[A_Index - 1], True) ) } else { obj:= {} keys:= JS.Object.keys(json) Loop,% keys.length { k:= keys[A_Index -1] obj[k]:= %A_ThisFunc%(json[k], True) } } Return,obj } thisJson(ByRef Search_Input:= "Hello") { ; Build the JSON payload (instr(Search_Input,"\")? Search_Input:= strreplace(Search_Input,"\","\\")) ;backslash escape char in JSON (instr(Search_Input,"/")? Search_Input:= strreplace(Search_Input,"/","//")) ;fwdslash escape char in JSON (instr(Search_Input,chr(9))? Search_Input:= strreplace(Search_Input,chr(9)," ")) ;fwdslash escape char in JSON Search_Input:= RegExReplace(Search_Input,"`n","\n") ; newline chars Search_Input:= RegExReplace(Search_Input,"`" chr(34),"\" chr(34)) ;doublequote mark Search_Input:= RegExReplace(Search_Input, chr(126),"\" chr(126)) ;tilde MaxTokens:= round((Opt_MaxTokens/2)-(len:= strlen(Search_Input))) if(Opt_DebugPayload) msgbox % Search_Input jsonY:= " (LTrim { ""prompt"": " chr(34) Search_Input chr(34) ", ""max_tokens"": " MaxTokens ", ""temperature"": " Opt_Temperature " } )" Return,byref jsonY }While(i< 100) { ; ToolTip,% i ; setTimer,ttStop,-3000 Answer:= Array["choices"][i]["text"] If(Answer!="") Break, i++ } BeautifyJson(json, indent := " ") { static Doc, JS if(!Doc) { Doc:= ComObjCreate("htmlfile") Doc.write("") JS:= Doc.parentWindow } Return JS.eval("JSON.stringify(" . json . ",'','" . indent . "')") } ;################################################################################################################ ;MsgBox, % GoogleTranslate("今日の天気はとても良いです") ;MsgBox, % GoogleTranslate("Hello, World!", "en", "ru") GoogleTranslate(str,from:= "auto", to:= "de") { static JS:= CreateScriptObj(), _:= JS.( GetJScript() ):= JS.("delete ActiveXObject; delete GetObject;") json:= SendRequest(JS,str,to,from,proxy:= "") oJSON:= JS.("(" . json . ")") ATickCount:= A_TickCount try,thisBeautifyJson:= BeautifyJson(json) GuiControl,,JsonEdit,% thisBeautifyJson ;try fileappend,% thisBeautifyJson,% a_ScriptDir "\" ATickCount "-Google Translate json_History ChatGTP.json.txt" ;try run,% a_ScriptDir "\" ATickCount "-Google Translate json_History ChatGTP.json.txt" if(!IsObject(oJSON[1])) { Loop,% oJSON[0].length trans .= oJSON[0][A_Index -1][0] } else { MainTransText:= oJSON[0][0][0] Loop,% oJSON[1].length { trans .= "`n+" obj:= oJSON[1][A_Index-1][1] Loop,% obj.length { txt:= obj[A_Index - 1] trans .= (MainTransText = txt ? "" : "`n" txt) } } } if(!IsObject(oJSON[1])) MainTransText:= trans:= Trim(trans, ",+`n ") else,trans:= MainTransText . "`n+`n" . Trim(trans, ",+`n ") from:= oJSON[2] Return,trans:= Trim(trans, ",+`n ") } SendRequest(JS,str,tl,sl,proxy) { static http ComObjError(False) if(!http) { http:= ComObjCreate("WinHttp.WinHttpRequest.5.1") ( proxy && http.SetProxy(2, proxy) ) http.open("GET", "https://translate.google.com", True) http.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0") http.send() http.WaitForResponse(-1) } http.open("POST", "https://translate.googleapis.com/translate_a/single?client=gtx" ; or "https://clients5.google.com/translate_a/t?client=dict-chrome-ex" . "&sl=" . sl . "&tl=" . tl . "&hl=" . tl . "&dt=at&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&ie=UTF-8&oe=UTF-8&otf=0&ssel=0&tsel=0&pc=1&kc=1" . "&tk=" . JS.("tk").(str), True) http.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8") http.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0") http.send("q=" . URIEncode(str)) http.WaitForResponse(-1) Return,http.responsetext } URIEncode(str,encoding:= "UTF-8") { VarSetCapacity(var,StrPut(str,encoding)) StrPut(str,&var,encoding) while(code:= NumGet(Var, A_Index - 1, "UChar")) { bool:= (code > 0x7F || code < 0x30 || code = 0x3D) UrlStr.=bool? "%" . Format("{:02X}", code) : Chr(code) } Return,UrlStr } GetJScript() { script = ( var TKK = ((function() { var a = 561666268; var b = 1526272306; return 406398 + '.' + (a + b); })()); function b(a, b) { for (var d = 0; d < b.length - 2; d += 3) { var c = b.charAt(d + 2), c = "a" <= c ? c.charCodeAt(0) - 87 : Number(c), c = "+" == b.charAt(d + 1) ? a >>> c : a << c; a = "+" == b.charAt(d) ? a + c & 4294967295 : a ^ c } return a } function tk(a) { for (var e = TKK.split("."), h = Number(e[0]) || 0, g = [], d = 0, f = 0; f < a.length; f++) { var c = a.charCodeAt(f); 128 > c ? g[d++] = c : (2048 > c ? g[d++] = c >> 6 | 192 : (55296 == (c & 64512) && f + 1 < a.length && 56320 == (a.charCodeAt(f + 1) & 64512) ? (c = 65536 + ((c & 1023) << 10) + (a.charCodeAt(++f) & 1023), g[d++] = c >> 18 | 240, g[d++] = c >> 12 & 63 | 128) : g[d++] = c >> 12 | 224, g[d++] = c >> 6 & 63 | 128), g[d++] = c & 63 | 128) } a = h; for (d = 0; d < g.length; d++) a += g[d], a = b(a, "+-a^+6"); a = b(a, "+-3^+b+-f"); a ^= Number(e[1]) || 0; 0 > a && (a = (a & 2147483647) + 2147483648); a `%= 1E6; return a.toString() + "." + (a ^ h) } ) Return,script } CreateScriptObj() { static doc, JS, _JS if(!doc) { doc:= ComObjCreate("htmlfile") doc.write("") JS:= doc.parentWindow if(doc.documentMode < 9) JS.execScript() _JS:= ObjBindMethod(JS, "eval") } Return,_JS } WinAnimate(Hwnd,Type="",Time=100) { static AW_ACTIVATE=0x20000, AW_BLEND=0x80000, AW_CENTER=0x10, AW_HIDE=0x10000 , AW_HNEG=0x2,AW_HPOS=0x1, AW_SLIDE=0x40000, AW_VNEG=0x8, AW_VPOS=0x4 loop,parse,Type,%A_Tab%%A_Space%,%A_Tab%%A_Space% ifEqual,A_LoopField,,Continue, else,(!hFlags? (hFlags:= 0, hFlags|=AW_%A_LoopField%):hFlags|=AW_%A_LoopField%) ifEqual,hFlags,% "",return,"Err: Some of the types are invalid" return,dllcall("AnimateWindow","uint",Hwnd,"uint",Time,"uint",hFlags) } onMsgbox(HookCr,eventcr,hWnd,idObject,idChild,dwEventThread) { winget,pid,pid,ahk_id %hwnd% if(pid!=r_pid) return, ;if its our mbox change icon onActiv8(wparam="",lparam="",msg="",hwnd) } Hookinit: HookMb:= dllcall("SetWinEventHook","Uint",0x0010,"Uint",0x0010,"Ptr",0,"Ptr" , ProcMb_:= RegisterCallback("onMsgbox",""),"Uint",0,"Uint",0,"Uint",0x0000) ;WINEVENT_OUTOFCONTEXT:= 0x0000 , hOOkz:= "HookMb,ProcMb_" return, Time4mat(time="",pattern="") { FormatTime,out,% (time=""? A_now : time),% (pattern=""? "H:m:s" : pattern) return,out } SetExplorerTheme(hWnd) { return,DllCall("UxTheme.dll\SetWindowTheme","Ptr",hWnd,"Str","explorer","Ptr",0) } RegRead: RegRead,api_key,% RegBase,api_key return, RegWrite: if(api_key) RegWrite,REG_SZ,% RegBase,api_key,% api_key return, exit: menu,tray,noicon gosub,RegWrite gosub,unhook ExitApp, reload() { reload, exitapp, } unHook: if(FileExist(TEMP_FILE)) FileDelete,%TEMP_FILE% else,sleep,300 loop,Parse,% hOOkz,`, { dllcall("UnhookWinEvent","Ptr",a_loopfield) sleep,20 dllcall("GlobalFree", "Ptr",a_loopfield,"Ptr") (%a_loopfield%) := "" } return, dBlur(hWnd) { static WCA_ACCENT_POLICY := 19 , ACCENT_DISABLED := 0 ;AccentState , ACCENT_ENABLE_GRADIENT := 1 , ACCENT_ENABLE_TRANSPARENTGRADIENT := 2 , ACCENT_ENABLE_BLURBEHIND := 3 , ACCENT_INVALID_STATE := 4 , accentStructSize := VarSetCapacity(AccentPolicy, 4*4, 0) NumPut(ACCENT_ENABLE_BLURBEHIND, AccentPolicy, 0, "UInt") padding:= A_PtrSize=8? 4 : 0 VarSetCapacity(WindowCompositionAttributeData, 4 + padding + A_PtrSize + 4 + padding) NumPut(WCA_ACCENT_POLICY, WindowCompositionAttributeData, 0, "UInt") NumPut(&AccentPolicy, WindowCompositionAttributeData, 4 + padding, "Ptr") NumPut(accentStructSize, WindowCompositionAttributeData, 4 + padding + A_PtrSize, "UInt") return,DllCall("SetWindowCompositionAttribute","Ptr",hWnd,"Ptr",&WindowCompositionAttributeData) } Aero_StartUp(){ global MODULEID3:=DllCall("LoadLibrary", "str", "dwmapi") MODULEID2:=DllCall("LoadLibrary", "str", "uxtheme") ;zwar noch nicht gebraucht aber egal MODULEID:=MODULEID3 . "|" . MODULEID2 Return,MODULEID } WinMove(hWnd="",X="",Y="",W="",H="",byref flags="") { static local dts:=0 ,uint:="uint", int:="int" ,msg_:="SetWindowPos" listlines,off ((dts=0)? (dts:= ((Flags="") ? (optM2dAutoActiv8? 0x4:0x015):dts:=flags))) return,DllCall(msg_,uint,hWnd,uint,0,int,x,int,y,int,w,int,h,uint,dts) } B64_2_hicon(B64in,NewHandle:= False) { Static hBitmap:= 0 (NewHandle? hBitmap:= 0) If(hBitmap) Return,hBitmap VarSetCapacity(B64,3864 <