ioa747 Posted March 23 Share Posted March 23 when I run this script while I don't have ConsoleWrite at all, it writes various characters to my Console like [?25l⠙ [?25h�Ӑ[?25l[2K[1G⠹ [?25h[?25l[2K[1G⠸ [?25h"[?25l[2K[1G⠼ [?25h[?25l[2K[1G⠴ [?25h[?25l[2K[1G⠦ [?25h[?25l[2K[1G⠧ [?25h ... (about 3000 characters in one line) until it is completed, while the script completes its target normally. Does this affect me in any way ? Have I done anything wrong with $STDIN_CHILD + $STDOUT_CHILD ? expandcollapse popup#include <AutoItConstants.au3> #include <MsgBoxConstants.au3> #include <WinAPIConv.au3> Local $hTimer = TimerInit() AskToAI("Why is the sky blue?") ConsoleWrite("processed in: " & Round(TimerDiff($hTimer) / 1000, 3) & " seconds " & @LF) Func AskToAI($sInput) ;https://github.com/ollama/ollama/tree/main Local $iPID = Run("ollama run llama2", @LocalAppDataDir & "\Programs\Ollama", @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD) ; Write a string to child Stdin. StdinWrite($iPID, $sInput) ; Calling StdinWrite without a second parameter closes the stream. StdinWrite($iPID) Local $sOutput = "" ; Store the output of StdoutRead to a variable. While 1 $sOutput &= StdoutRead($iPID) ; Read the Stdout stream of the PID returned by Run. If @error Then ; Exit the loop if the process closes or StdoutRead returns an error. ExitLoop EndIf WEnd ;MsgBox($MB_SYSTEMMODAL, "The Response is:", _WinAPI_OemToChar($sOutput)) ; Run Notepad Run("notepad.exe") ; Wait 5 seconds for the Notepad window to appear. Local $hWnd = WinWait("[CLASS:Notepad]", "", 5) ; Set the edit control in Notepad with some text. The handle returned by WinWait is used for the "title" parameter of ControlSetText. ControlSetText($hWnd, "", "Edit1", _WinAPI_OemToChar($sOutput)) EndFunc ;==>Example Please, every suggestion is appreciated! Thank you very much I know that I know nothing Link to comment Share on other sites More sharing options...
Gianni Posted March 24 Share Posted March 24 (edited) that output looks like a string containing ANSI escape codes where is it displayed, on the AutoIt console or on the "ollama" console? by the way, what is "ollama" and where do you download it? ... Sorry, just saw the link in the listing ... Edited March 24 by Gianni ioa747 1 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
ioa747 Posted March 24 Author Share Posted March 24 2 hours ago, Gianni said: where is it displayed, on the AutoIt console or on the "ollama" console? on the AutoIt console I know that I know nothing Link to comment Share on other sites More sharing options...
Solution Andreik Posted March 24 Solution Share Posted March 24 (edited) It's the error stream: #include <AutoItConstants.au3> #include <MsgBoxConstants.au3> #include <WinAPIConv.au3> Local $hTimer = TimerInit() AskToAI("Why is the sky blue?") ConsoleWrite("processed in: " & Round(TimerDiff($hTimer) / 1000, 3) & " seconds " & @LF) Func AskToAI($sInput) ;https://github.com/ollama/ollama/tree/main Local $iPID = Run(@ComSpec & " /c ollama run llama2", @LocalAppDataDir & "\Programs\Ollama", @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD + $STDERR_CHILD) ;~ ; Write a string to child Stdin. StdinWrite($iPID, $sInput) ;~ ; Calling StdinWrite without a second parameter closes the stream. StdinWrite($iPID) Local $sOutput = "" ; Store the output of StdoutRead to a variable. Local $sError = "" While 1 $sError &= StderrRead($iPID) $sOutput &= StdoutRead($iPID) ; Read the Stdout stream of the PID returned by Run. If @error Then ; Exit the loop if the process closes or StdoutRead returns an error. ExitLoop EndIf WEnd ConsoleWrite("The Response is: " & _WinAPI_OemToChar($sOutput) & @CRLF & @CRLF) ConsoleWrite("Error stream: " & $sError & @CRLF & @CRLF) EndFunc ;==>Example If you don't really need this data you can simply redirect the standard error stream to nul device: Local $iPID = Run(@ComSpec & " /c ollama run llama2 2> nul", @LocalAppDataDir & "\Programs\Ollama", @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD) Edited March 24 by Andreik ioa747 1 When the words fail... music speaks. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now