Jump to content

writes various characters to my Console


Go to solution Solved by Andreik,

Recommended Posts

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 ?

#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

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 by Gianni

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

  • Solution
Posted (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 by Andreik
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...