Skip to content

Instantly share code, notes, and snippets.

@TeamDman
Created March 12, 2025 20:51
Show Gist options
  • Select an option

  • Save TeamDman/595ac6f4d4597f2974f8360de349258a to your computer and use it in GitHub Desktop.

Select an option

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?"`
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