Created
March 12, 2025 20:51
-
-
Save TeamDman/595ac6f4d4597f2974f8360de349258a to your computer and use it in GitHub Desktop.
A PowerShell function that lets you use Ollama with piped content `echo "25*25" | ask "What numbers are present in the expression?"`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function ask { | |
| [CmdletBinding()] | |
| param( | |
| # We expect pipeline input to be strings (lines) | |
| [Parameter(ValueFromPipeline)] | |
| [string] | |
| $StdinContent, | |
| [Parameter(Mandatory, Position=0)] | |
| [string] | |
| $Query, | |
| [Parameter(Position=1)] | |
| [string] | |
| $Model = "deepseek-r1:32b" | |
| # $Model = "deepseek-r1:14b" | |
| ) | |
| begin { | |
| # Create a list to store all lines piped in | |
| $allInput = [System.Collections.Generic.List[string]]::new() | |
| } | |
| process { | |
| # Add each line from pipeline to the list | |
| $allInput.Add($StdinContent) | |
| } | |
| end { | |
| # Join everything into a single multi-line string | |
| $combinedInput = $allInput -join "`n" | |
| # Now do a single ollama run call | |
| Write-Output "<stdin>$combinedInput</stdin> <query>$Query</query>" | ollama run "$Model" | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment