Search the Community
Showing results for tags 'ollama'.
-
I divide the project into parts for easier management. The project is in early beta stage, for research and development. 🚀 AI_Assistant.au3 which is included in SciTE_AI_Assistant.au3, but can also be used as a standalone UDF in which I #include "StringSize.au3" ; "https://www.autoitscript.com/forum/topic/114034-stringsize-m23-bugfix-version-27-dec-23" by Melba23 - thanks for that So that it folds the console output, and is visible within its boundaries (especially when it is on the side and is slim) for more comfortable reading works directly with the ollama. I use a small models qwen2.5-coder:3b as default, llama3.2:3b , phi4-mini:3.8b so that I don't have to wait too long for a response. However, I have set as a parameter which model it calls, so that it changes the model per job if necessary AI_Assistant.au3 #include-once ; #INDEX# ======================================================================================================================= ; Title .........: AI_Assistant.au3 ; AutoIt Version : v3.3.16.1 or higher ; Language ......: English ; Description ...: AI assistant - Need Ollama installed (https://ollama.com/download) ; Remarks .......: Recommended small models: llama3.2:3b , qwen2.5-coder:3b (https://ollama.com/library) ; Note ..........: Script Version: 0.1 Testet in Win10 22H2 ; Author(s) .....: ioa747 ; Link ..........: https://www.autoitscript.com/forum/topic/212888-scite-ai-assistant ; =============================================================================================================================== ;~ #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ; #INCLUDES# ==================================================================================================================== #include "StringSize.au3" ;"https://www.autoitscript.com/forum/topic/114034-stringsize-m23-bugfix-version-27-dec-23" ; #GLOBAL VARIABLES# ============================================================================================================ Global $g__AI_DebugInfo = False ; True = debug info * <-- _AI_DebugInfo(True\False) ; #FUNCTION# ==================================================================================================================== ; Name...........: _AI_Call ; Description....: Call the AI model with given prompt, assistant, system, endpoint, temperature, and seed. ; Syntax.........: _AI_Call( $sPrompt [, $sAssistant = "llama3.2:3b" [, $sSystem = "You are a helpful assistant" [, $iEndpoint = 1 [, $fTemperature = 0.3 [, $iSeed = 0]]]] ) ; Parameters.....: $sPrompt - The prompt to be sent to the AI model. ; $sAssistant - [optional] The name of the AI model. (Default is "llama3.2:3b") ; $sSystem - [optional] The system instruction provided by the user. (Default is "You are a helpful assistant.") ; $iEndpoint - [optional] The API endpoint to use. (1 for /api/chat, 2 for /api/generate) ; $fTemperature - [optional] The temperature value for the AI model's output. (Default is 0.3) ; $iSeed - [optional] The seed value for the AI model's response. (Default is 0) ; Return values .: Success: Returns the output from the AI model. ; Failure: Sets @error and returns an empty string with a custom message. ; @error = 13: Invalid endpoint specified. Must be 1 or 2. ; Author ........: ioa747 ; Modified ......: ; Remarks .......: This function sends a request to the AI model API using WinHttp. ; Related .......: None ; Link ..........: ; Example .......: _AI_Call("What is your name?", "llama3.2:3b", "You are an AI assistant.") ; =============================================================================================================================== Func _AI_Call($sPrompt, $sAssistant = "llama3.2:3b", $sSystem = "You are a helpful assistant", $iEndpoint = 1, $fTemperature = 0.3, $iSeed = 0) If $sAssistant = "" Or $sAssistant = -1 Or $sAssistant = Default Then $sAssistant = "llama3.2:3b" If $sSystem = "" Or $sSystem = -1 Or $sSystem = Default Then $sSystem = "You are a helpful assistant" If $fTemperature = "" Or $fTemperature = -1 Or $fTemperature = Default Then $fTemperature = 0.3 If $iSeed = "" Or $iSeed = -1 Or $iSeed = Default Then $iSeed = 0 ToolTip("AI Processing...", @DesktopWidth - 90, @DesktopHeight - 60) Local $sOut Local $hTimer = TimerInit() If $iEndpoint = 1 Then ; Endpoint to /api/chat $sOut = __AI_ToChat($sPrompt, $sAssistant, $sSystem, $fTemperature, $iSeed) ElseIf $iEndpoint = 2 Then ; Endpoint to /api/generate $sOut = __AI_ToGenerate($sPrompt, $sAssistant, $sSystem, $fTemperature, $iSeed) Else $sOut = "! @error: _AI_Call() => $iEndpoint out of range (1=chat, 2=Generate)" SetError(13) EndIf ToolTip("") If @error Then Return SetError(@error, 0, $sOut) Else If $g__AI_DebugInfo Then Return "> " & $sAssistant & " processed in: " & Round(TimerDiff($hTimer) / 1000, 3) & " seconds " & @CRLF & $sOut Else Return $sOut EndIf EndIf EndFunc ;==>_AI_Call ; #FUNCTION# ==================================================================================================================== ; Name ..........: _AI_CW ; Description ...: Adjusts the text size in a SciTE console window to fit within its boundaries. ; Syntax ........: _AI_CW($sText) ; Parameters ....: $sText - The text to ConsoleWrite ; Return values .: Success: None (Write the adjustsed $sText to the SciTE Console). ; Failure: None (bypass adjusts the text size). ; @error = 1: An error occurred during font sizing, but processing continues. ; Author ........: ioa747 ; Modified ......: ; Remarks .......: Skip adjusts the text size, between triple backticks (```) block. ; Related .......: using the StringSize.au3 UDF from Melba23 ; Link ..........: https://www.autoitscript.com/forum/topic/114034-stringsize-m23-bugfix-version-27-dec-23 ; Example .......: _AI_CW("Adjusts the text size in a SciTE console window to fit within its boundaries.") ; =============================================================================================================================== Func _AI_CW($sText) Local $aPos = ControlGetPos("[CLASS:SciTEWindow]", "", "Scintilla2") Local $sNewText, $aStrSZ Local $aText = StringSplit($sText, '```', 1) ; _StringSize fit only no code part For $i = 1 To $aText[0] If Mod($i, 2) = 0 Then $sNewText &= "```" & $aText[$i] & "```" Else $aStrSZ = _StringSize($aText[$i], 11, Default, Default, "Cascadia Code", $aPos[2]) If @error Then $sNewText &= $aText[$i] Else $sNewText &= $aStrSZ[0] EndIf EndIf Next ConsoleWrite($sNewText) EndFunc ;==>_AI_CW ; #FUNCTION# ==================================================================================================================== ; Name...........: _AI_DebugInfo ; Description....: Enables or disables debug information output. ; Syntax.........: _AI_DebugInfo( [$bEnable] ) ; Parameters.....: $bEnable - [optional] True to enable debugging, False to disable (Default is True). ; Return values .: Success: None. ; Failure: None. ; Author ........: ioa747 ; Modified ......: ; Remarks .......: This function controls whether debug information is displayed in the console or not. ; Related .......: ; Link ..........: ; Example .......: _AI_DebugInfo(True) to enable debugging. ; =============================================================================================================================== Func _AI_DebugInfo($bEnable = True) $g__AI_DebugInfo = $bEnable EndFunc ;==>_AI_DebugInfo #Region ; === Internal use Functions === Func __AI_ToChat($sPrompt, $sAssistant = -1, $sSystem = -1, $fTemperature = -1, $iSeed = -1) ; Sets default values If $sSystem = "" Or $sSystem = -1 Or $sSystem = Default Then $sSystem = "You are a helpful assistant" If $sAssistant = "" Or $sAssistant = -1 Or $sAssistant = Default Then $sAssistant = "llama3.2:3b" If $fTemperature = "" Or $fTemperature = -1 Or $fTemperature = Default Then $fTemperature = 0.3 If $iSeed = "" Or $iSeed = -1 Or $iSeed = Default Then $iSeed = 0 ; Avoiding problems with special characters in JSON __AI_Json_EscapeString($sAssistant) __AI_Json_EscapeString($sSystem) __AI_Json_EscapeString($sPrompt) ; Creating the JSON request payload /api/chat Local $sRequest = '{' $sRequest &= '"model": "' & $sAssistant & '", ' $sRequest &= '"messages": [' $sRequest &= '{"role": "system", "content": "' & $sSystem & '"},' $sRequest &= '{"role": "user", "content": "' & $sPrompt & '"}' $sRequest &= '], ' $sRequest &= '"stream": false, ' $sRequest &= '"temperature": ' & $fTemperature & ', ' $sRequest &= '"seed": ' & $iSeed $sRequest &= '}' __AI_DW("$sRequest=>" & $sRequest & @CRLF) ; _FileWriteLog(@ScriptDir & "\SciTE_AI_Assistant.log", $sRequest) ; debugging ; Create HTTP Request object Local $oHttp = ObjCreate("WinHttp.WinHttpRequest.5.1") ; ResolveTimeout: 5 sec ; ConnectTimeout: 10 sec ; SendTimeout: 60 sec ; ReceiveTimeout: 120 sec $oHttp.SetTimeouts(5000, 10000, 60000, 120000) ; Endpoint to /api/chat $oHttp.Open("POST", "http://localhost:11434/api/chat", False) $oHttp.SetRequestHeader("Content-Type", "application/json") $oHttp.Send($sRequest) ; Check if request was successful If $oHttp.Status <> 200 Then Local $aErr = __AI_HTTP_STATUS_CODES($oHttp.Status, $oHttp.ResponseText) MsgBox(16, " ( " & $aErr[0] & " ) " & $aErr[1], $aErr[2]) Return SetError(1, 0, $oHttp.ResponseText) EndIf ; Get the answer Local $sResponse = $oHttp.ResponseText __AI_DW("$sResponse=>" & $sResponse & @CRLF) ; Parse response => suporting value: .model, .created_at, .role, .content, .done_reason Local $mJson = __AI_Json_Map($sResponse) ; Access the content of the response ($mJson.content) If Not MapExists($mJson, "content") Then MsgBox(16, "AskToAI() l: " & @ScriptLineNumber, "_JsonMap() fail to find 'content' in response") Return SetError(2, 0, "_JsonMap() fail to find 'content' in response") EndIf $sResponse = $mJson.content Return $sResponse EndFunc ;==>__AI_ToChat ;-------------------------------------------------------------------------------------------------------------------------------- Func __AI_ToGenerate($sPrompt, $sAssistant = -1, $sSystem = -1, $fTemperature = -1, $iSeed = -1) ; Sets default values If $sSystem = "" Or $sSystem = -1 Or $sSystem = Default Then $sSystem = "You are a helpful assistant" If $sAssistant = "" Or $sAssistant = -1 Or $sAssistant = Default Then $sAssistant = "llama3.2:3b" If $fTemperature = "" Or $fTemperature = -1 Or $fTemperature = Default Then $fTemperature = 0.3 If $iSeed = "" Or $iSeed = -1 Or $iSeed = Default Then $iSeed = 0 __AI_Json_EscapeString($sAssistant) __AI_Json_EscapeString($sSystem) __AI_Json_EscapeString($sPrompt) Local $sRequest = '{' $sRequest &= '"model": "' & $sAssistant & '", ' $sRequest &= '"system": "' & $sSystem & '", ' $sRequest &= '"prompt": "' & $sPrompt & '", ' $sRequest &= '"stream": false, ' $sRequest &= '"temperature": ' & $fTemperature & ', ' $sRequest &= '"seed": ' & $iSeed $sRequest &= '}' __AI_DW("$sRequest=>" & $sRequest & @CRLF) ;_FileWriteLog(@ScriptDir & "\SciTE_AI_Assistant.log", $sRequest) ; Endpoint to /api/generate Local $oHttp = ObjCreate("WinHttp.WinHttpRequest.5.1") ; ResolveTimeout: 5 sec ; ConnectTimeout: 10 sec ; SendTimeout: 30 sec ; ReceiveTimeout: 120 sec $oHttp.SetTimeouts(5000, 10000, 30000, 120000) $oHttp.Open("POST", "http://localhost:11434/api/generate", False) $oHttp.SetRequestHeader("Content-Type", "application/json") $oHttp.Send($sRequest) ; Check if request was successful If $oHttp.Status <> 200 Then Local $aErr = __AI_HTTP_STATUS_CODES($oHttp.Status, $oHttp.ResponseText) MsgBox(16, " ( " & $aErr[0] & " ) " & $aErr[1], $aErr[2]) Return SetError(1, 0, $oHttp.ResponseText) EndIf Local $sResponse = $oHttp.ResponseText __AI_DW("$sResponse=>" & $sResponse & @CRLF) ; Parse response => suporting value: .model ; .created_at ; .response ; .done_reason Local $mJson = __AI_Json_Map($sResponse) ; __AI_DW("$mJson.response=" & $mJson.response & @CRLF) ; For /api/generate, the response is usually in .response If Not MapExists($mJson, "response") Then MsgBox(16, "AskToAI_FIM() l: " & @ScriptLineNumber, "_JsonMap() fail to find 'response'") Return SetError(2, 0, "_JsonMap() fail to find 'response'") EndIf $sResponse = $mJson.response Return $sResponse EndFunc ;==>__AI_ToGenerate ;-------------------------------------------------------------------------------------------------------------------------------- Func __AI_HTTP_STATUS_CODES($iStatus, $sResponseText = "") Local $aResult[3] = [$iStatus, "Unknown Status", "An unknown HTTP status code was returned."] Local $HTTP_STATUS_CODES[41][3] = [[40, "HTTP status", "description"] _ , [100, "HTTP_STATUS_CONTINUE", "The request can be continued."] _ , [101, "HTTP_STATUS_SWITCH_PROTOCOLS", "The server has switched protocols in an upgrade header."] _ , [200, "HTTP_STATUS_OK", "The request completed successfully."] _ , [201, "HTTP_STATUS_CREATED", "The request has been fulfilled and resulted in the creation of a new resource."] _ , [202, "HTTP_STATUS_ACCEPTED", "The request has been accepted for processing, but the processing has not been completed."] _ , [203, "HTTP_STATUS_PARTIAL", "The returned meta information in the entity-header is not the definitive set available from the originating server."] _ , [204, "HTTP_STATUS_NO_CONTENT", "The server has fulfilled the request, but there is no new information to send back."] _ , [205, "HTTP_STATUS_RESET_CONTENT", "The request has been completed, and the client program should reset the document view that caused the request to be sent to allow the user to easily initiate another input action."] _ , [206, "HTTP_STATUS_PARTIAL_CONTENT", "The server has fulfilled the partial GET request for the resource."] _ , [207, "HTTP_STATUS_WEBDAV_MULTI_STATUS", "During a World Wide Web Distributed Authoring and Versioning (WebDAV) operation, this indicates multiple status codes for a single response. The response body contains Extensible Markup Language (XML) that describes the status codes."] _ , [300, "HTTP_STATUS_AMBIGUOUS", "The requested resource is available at one or more locations."] _ , [301, "HTTP_STATUS_MOVED", "The requested resource has been assigned to a new permanent Uniform Resource Identifier (URI), and any future references to this resource should be done using one of the returned URIs."] _ , [302, "HTTP_STATUS_REDIRECT", "The requested resource resides temporarily under a different URI."] _ , [303, "HTTP_STATUS_REDIRECT_METHOD", "The response to the request can be found under a different URI and should be retrieved using a GET HTTP verb on that resource."] _ , [304, "HTTP_STATUS_NOT_MODIFIED", "The requested resource has not been modified."] _ , [305, "HTTP_STATUS_USE_PROXY", "The requested resource must be accessed through the proxy given by the location field."] _ , [307, "HTTP_STATUS_REDIRECT_KEEP_VERB", "The redirected request keeps the same HTTP verb. HTTP/1.1 behavior."] _ , [400, "HTTP_STATUS_BAD_REQUEST", "The request could not be processed by the server due to invalid syntax."] _ , [401, "HTTP_STATUS_DENIED", "The requested resource requires user authentication."] _ , [402, "HTTP_STATUS_PAYMENT_REQ", "Not implemented in the HTTP protocol."] _ , [403, "HTTP_STATUS_FORBIDDEN", "The server understood the request, but cannot fulfill it."] _ , [404, "HTTP_STATUS_NOT_FOUND", "The server has not found anything that matches the requested URI."] _ , [405, "HTTP_STATUS_BAD_METHOD", "The HTTP verb used is not allowed."] _ , [406, "HTTP_STATUS_NONE_ACCEPTABLE", "No responses acceptable to the client were found."] _ , [407, "HTTP_STATUS_PROXY_AUTH_REQ", "Proxy authentication required."] _ , [408, "HTTP_STATUS_REQUEST_TIMEOUT", "The server timed out waiting for the request."] _ , [409, "HTTP_STATUS_CONFLICT", "The request could not be completed due to a conflict with the current state of the resource. The user should resubmit with more information."] _ , [410, "HTTP_STATUS_GONE", "The requested resource is no longer available at the server, and no forwarding address is known."] _ , [411, "HTTP_STATUS_LENGTH_REQUIRED", "The server cannot accept the request without a defined content length."] _ , [412, "HTTP_STATUS_PRECOND_FAILED", "The precondition given in one or more of the request header fields evaluated to false when it was tested on the server."] _ , [413, "HTTP_STATUS_REQUEST_TOO_LARGE", "The server cannot process the request because the request entity is larger than the server is able to process."] _ , [414, "HTTP_STATUS_URI_TOO_LONG", "The server cannot service the request because the request URI is longer than the server can interpret."] _ , [415, "HTTP_STATUS_UNSUPPORTED_MEDIA", "The server cannot service the request because the entity of the request is in a format not supported by the requested resource for the requested method."] _ , [449, "HTTP_STATUS_RETRY_WITH", "The request should be retried after doing the appropriate action."] _ , [500, "HTTP_STATUS_SERVER_ERROR", "The server encountered an unexpected condition that prevented it from fulfilling the request."] _ , [501, "HTTP_STATUS_NOT_SUPPORTED", "The server does not support the functionality required to fulfill the request."] _ , [502, "HTTP_STATUS_BAD_GATEWAY", "The server, while acting as a gateway or proxy, received an invalid response from the upstream server it accessed in attempting to fulfill the request."] _ , [503, "HTTP_STATUS_SERVICE_UNAVAIL", "The service is temporarily overloaded."] _ , [504, "HTTP_STATUS_GATEWAY_TIMEOUT", "The request was timed out waiting for a gateway."] _ , [505, "HTTP_STATUS_VERSION_NOT_SUP", "The server does not support the HTTP protocol version that was used in the request message."]] For $i = 1 To $HTTP_STATUS_CODES[0][0] If $HTTP_STATUS_CODES[$i][0] = $iStatus Then ;$aResult[0] = $HTTP_STATUS_CODES[$i][0] $aResult[1] = $HTTP_STATUS_CODES[$i][1] $aResult[2] = $HTTP_STATUS_CODES[$i][2] ExitLoop EndIf Next ConsoleWrite("! $aResult[0]=" & $aResult[0] & ", [1]=" & $aResult[1] & ", [2]=" & $aResult[2] & @TAB & "( " & $sResponseText & " )" & @CRLF) $aResult[2] &= @CRLF & @CRLF & "Details: " & $sResponseText Return $aResult EndFunc ;==>__AI_HTTP_STATUS_CODES ;-------------------------------------------------------------------------------------------------------------------------------- Func __AI_Json_EscapeString(ByRef $sString) ;=== Converts normal string to a JSON-safe string === ; Escape backslashes first to avoid double-processing $sString = StringReplace($sString, '\', '\\', 0, 1) ; Escape known JSON control characters $sString = StringReplace($sString, Chr(8), '\b', 0, 1) ; Backspace $sString = StringReplace($sString, Chr(12), '\f', 0, 1) ; Formfeed $sString = StringReplace($sString, @CRLF, '\n', 0, 1) ; CRLF → \n $sString = StringReplace($sString, @LF, '\n', 0, 1) ; LF → \n $sString = StringReplace($sString, @CR, '\r', 0, 1) ; CR → \r $sString = StringReplace($sString, @TAB, '\t', 0, 1) ; Tab → \t ; Escape double quotes $sString = StringReplace($sString, '"', '\"', 0, 1) ; Escape \u00XX characters ; nothing yet ; Strip_ControlChars (< 32) For $i = 0 To 31 Switch $i Case 8, 9, 10, 12, 13 ; Already handled above Case Else $sString = StringReplace($sString, Chr($i), "") EndSwitch Next Return $sString EndFunc ;==>__AI_Json_EscapeString ;-------------------------------------------------------------------------------------------------------------------------------- Func __AI_Json_UnEscapeString(ByRef $sString) ;=== Converts a JSON-escaped string back into normal string === If StringInStr($sString, '\') = 0 Then Return $sString ; Unescape quotes and backslashes first $sString = StringReplace($sString, '\"', '"', 0, 1) $sString = StringReplace($sString, '\\', '\', 0, 1) ; Unescape standard control characters $sString = StringReplace($sString, '\b', Chr(8), 0, 1) $sString = StringReplace($sString, '\f', Chr(12), 0, 1) $sString = StringReplace($sString, '\n', @LF, 0, 1) $sString = StringReplace($sString, '\r', @CR, 0, 1) $sString = StringReplace($sString, '\t', @TAB, 0, 1) ; Unescape \u00XX characters $sString = StringReplace($sString, '\u003c', '<', 0, 1) $sString = StringReplace($sString, '\u003e', '>', 0, 1) $sString = StringReplace($sString, '\u0026', '&', 0, 1) Return $sString EndFunc ;==>__AI_Json_UnEscapeString ;-------------------------------------------------------------------------------------------------------------------------------- Func __AI_Json_Map($sJson) ;=== It not support numbers, booleans, arrays or nested objects. === Local $mJson[] ; Remove curly braces and trim $sJson = StringStripWS(StringTrimLeft(StringTrimRight($sJson, 1), 1), 3) ; Match all "key": "value" pairs Local $aPairs = StringRegExp($sJson, '"([^"]+)"\s*:\s*"((?:\\.|[^"\\])*)"', 3) If @error Then Return SetError(2, 0, 0) For $i = 0 To UBound($aPairs) - 1 Step 2 Local $sKey = $aPairs[$i] Local $sVal = $aPairs[$i + 1] __AI_Json_UnEscapeString($sVal) $mJson[$sKey] = $sVal ; ConsoleWrite("$sKey=" & $sKey & @CRLF) Next Return $mJson EndFunc ;==>__AI_Json_Map ;-------------------------------------------------------------------------------------------------------------------------------- Func __AI_Json_GetModels() Local $oHttp = ObjCreate("WinHttp.WinHttpRequest.5.1") $oHttp.Open("GET", "http://localhost:11434/api/tags", False) $oHttp.Send() If $oHttp.Status <> 200 Then SetError(1) Return "" EndIf Return $oHttp.ResponseText EndFunc ;==>__AI_Json_GetModels ;-------------------------------------------------------------------------------------------------------------------------------- Func __AI_DW($sString, $iNoErrorNoLine = 0, $iLine = @ScriptLineNumber, $iError = @error, $iExtended = @extended) If Not $g__AI_DebugInfo Then Return SetError($iError, $iExtended, 0) ; Return Value: The amount of data written. Local $iReturn, $sLine = "@@(" & $iLine & ") :: " If $iNoErrorNoLine And Not $iError Then $sLine = "" If $iError Then $iReturn = ConsoleWrite("@@(" & $iLine & ") :: @error:" & $iError & ", @extended:" & $iExtended & ", " & $sString) Else $iReturn = ConsoleWrite($sLine & $sString) EndIf ; Remarks: The @error and @extended are not set on return leaving them as they were before calling. Return SetError($iError, $iExtended, $iReturn) EndFunc ;==>__AI_DW ;-------------------------------------------------------------------------------------------------------------------------------- #EndRegion ; === Internal use Functions === AI_Assistant_Example.au3 #include "AI_Assistant.au3" _Example1() Func _Example1() ; Example WordGenerator Local $sKeyword = "WORD GENERATOR" Local $iCount = 6, $iMin = 4 Local $aLetter = StringSplit($sKeyword, "") Local $sSystemPrompt = _ "You are a word generator AI. For each given letter, respond with exactly " & $iCount & " common English words " & _ "that start with that letter. Words must be at least " & $iMin & " letters long. " & _ "No duplicates allowed. Only return words separated by commas—no explanations, no extra text." Local $sRaw, $sAnswer = "" For $i = 1 To $aLetter[0] If StringRegExp($aLetter[$i], "^[A-Za-z]$") Then $sRaw = _AI_Call($aLetter[$i], "llama3.2:3b", $sSystemPrompt, 1) $sAnswer &= $aLetter[$i] & " - " & $sRaw & @LF Else $sAnswer &= $aLetter[$i] & @LF EndIf Next ConsoleWrite($sAnswer & @CRLF) EndFunc ;==>_Example1 #CS output: W - Wager, Wallet, Waves, Wishes, Winds, Winter O - Ocean, Owner, Oxygen, Orange, Open, Option R - Racket, Razor, Ruler, Rainbow, Rhythm, Router D - Dance, Digger, Doctor, Dog, Donor, Dragon G - Ghost, Glide, Glass, Goat, Glow, Graph E - Eagle, Elastic, Energetic, Elegant, Emerald, Escape N - Nest, Night, Noise, Normal, North, Notify E - Eagle, Earthy, Elegant, Earnest, Embark, Energize R - Ranch, Razor, Ruler, Rock, Rocket, River A - Amaze, Alert, Amber, Arise, Aspect, Angel T - Tiger, Tank, Taste, Topic, Total, Trouble O - Ocean, Owner, Open, Operation, Origin, Overshare R - Racket, Radar, Ranges, Raven, Reaction, Radius #CE SciTE_AI_Assistant.au3 I changed the approach, and made it as SciTE tool. This way, the selection process, and console writing, is handled internally by SciTE. To do this you need to add the following to SciTEUser.properties (Adding_utilities_to_the_SciTE_Tools_menu) #------------------------------------------------------------------------------ # 41 SciTE_AI_Assistant command.41.$(au3)="$(SciteDefaultHome)\..\AutoIt3.exe" "D:\i\Pro\.AutoIT\SciTE_AI_Assistant\SciTE_AI_Assistant.au3" command.subsystem.41.$(au3)=0 command.name.41.$(au3)=SciTE AI Assistant command.shortcut.41.*.au3=F10 command.save.before.41.$(au3)=2 # command.replace.selection.41.$(au3)=1 # command.quiet.41.$(au3)=0 # command.input.41.$(au3)=$(CurrentSelection) #------------------------------------------------------------------------------ #---------------------- Contex Menu ------------------------------------------- user.context.menu=\ ||\ >>> SciTE AI Assistant <<< |1141|\ ||\ Execute Selected Path|IDM_OPENSELECTED|\ #------------------------------------------------------------------------------ and make the necessary adjustments e.g. in command.41.$(au3)="$(SciteDefaultHome)\..\AutoIt3.exe" "D:\i\Pro\.AutoIT\SciTE_AI_Assistant\SciTE_AI_Assistant.au3" your path for the d:\your\location\SciTE_AI_Assistant\SciTE_AI_Assistant.au3 You may need to adjust the 41 to the first tool number available to you. in this case, change the >>> SciTE AI Assistant <<< |1141|\ as well in the Context Menu After that, select the text in the SciTE, right-click and select 'instruction' from the context menu '>>> SciTE AI Assistant <<<' Prompt Builder GUI The script described is an advanced AI prompt builder tool The tool provides a user-friendly interface that allows users to create, manage, and execute AI prompts based on predefined templates or customizable settings from .ini file. macros in the Prompt Builder GUI @Selection@ = the Selection of SciTE @ScriptName@ = the Script Name (useful as title) @ScriptFullPath@ = all the content of Script @ClipGet@ = the content of Clipboard @FileRead(FilePath)@ = the content of FilePath FIM (Fill-in-the-Middle <??> ) when it comes to FIM (Fill-in-the-Middle <??> ), the '<??>' tag is to specify the-Middle e.g. as in the example below, highlight the text , right click , and select, >>> SciTE AI Assistant <<< , FIM (Fill-in-the-Middle <??> ) Func SumNumbers($aNumbers) Local $iTotal = 0 For $i = 0 To UBound($aNumbers) - 1 <??> Next Return $iTotal EndFunc I will update the thread as soon as anything new comes up. SciTE_AI_Assistant.zip Please, every comment is appreciated! leave your comments and experiences here! Thank you very much