Skip to content

Commit

Permalink
Added -Lines to Send-PowershaiChat
Browse files Browse the repository at this point in the history
  • Loading branch information
rrg92 committed Sep 16, 2024
1 parent 24f5d7e commit f4f61b8
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion powershai/powershai.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -2266,6 +2266,10 @@ function Send-PowershaiChat {
# event - O evento. Indica o evento que originou. São os mesmos eventos documentaados em Invoke-AiChatTools
# interaction - O objeto interaction gerado por Invoke-AiChatTools
[switch]$PassThru

,#Retorna um array de linhas
#Se o modo stream estiver ativado, retornará uma linha por vez!
[switch]$Lines
)


Expand Down Expand Up @@ -2364,7 +2368,20 @@ function Send-PowershaiChat {

$prompt = @($prompt) -join "`n";

function WriteModelAnswer($interaction, $evt){
$WriteData = @{
BufferedText = ""
LinesBuffer = @()
}
function WriteModelAnswer {
param(
$interaction
,$evt
)

if($interaction -eq "FlushLine" -and $WriteData.BufferedText){
$MainCmdlet.WriteObject($WriteData.BufferedText)
return;
}

if($Object){
write-verbose "ObjectMode enabled. No writes...";
Expand Down Expand Up @@ -2433,6 +2450,22 @@ function Send-PowershaiChat {
return;
}

if($Lines){
$WriteData.BufferedText += $text;

$Lines = $WriteData.BufferedText -split '\r?\n'
$LastLine = $Lines.count - 1;

if($LastLine -gt 0){
$LastDelivery = $LastLine - 1
$DeliveryLines = $Lines[0..$LastDelivery];
$DeliveryLines | %{ $MainCmdlet.WriteObject($_) }
$WriteData.BufferedText = $Lines[-1];
}

return;
}

if($str){
write-host @WriteParams $Str;
}
Expand Down Expand Up @@ -2663,6 +2696,10 @@ function Send-PowershaiChat {
$Ret = Invoke-AiChatTools @ChatParams;
$End = Get-Date;
$Total = $End-$Start;

if($lines){
WriteModelAnswer "FlushLine";
}

foreach($interaction in $Ret.interactions){

Expand Down

0 comments on commit f4f61b8

Please sign in to comment.