Created
October 10, 2024 15:23
-
-
Save eugrus/9ea2e954872e9bbd0b07ea3a02f98c1a to your computer and use it in GitHub Desktop.
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
param ( | |
[string]$Prompt | |
) | |
if (-not $Prompt) { | |
$Prompt = "" | |
while ($true) { | |
$line = Read-Host ">" | |
if (-not $line) { break } | |
$Prompt += $line + "`n" | |
} | |
} | |
$uri = "http://localhost:11434/api/generate" | |
$body = @{ | |
model = "llama3.2" | |
prompt = $Prompt | |
stream = $true | |
} | ConvertTo-Json | |
$webRequest = [System.Net.HttpWebRequest]::Create($uri) | |
$webRequest.Method = "POST" | |
$webRequest.ContentType = "application/json" | |
$webRequest.KeepAlive = $true | |
$streamWriter = New-Object IO.StreamWriter($webRequest.GetRequestStream()) | |
$streamWriter.Write($body) | |
$streamWriter.Flush() | |
$streamWriter.Close() | |
$response = $webRequest.GetResponse() | |
$streamReader = New-Object IO.StreamReader($response.GetResponseStream()) | |
while (($L = $streamReader.ReadLine()) -ne $null) { | |
if ($L -match '"response"') { | |
$L = ($L | ConvertFrom-Json).response | |
Write-Host -NoNewLine $L | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment