Skip to content

Commit ff07708

Browse files
committed
优化stream,不额外添加停顿时间,另外,就是在verbose时显示FCFR的时间
Fixes #269
1 parent 35e1d83 commit ff07708

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

code365scripts.openai/Public/New-ChatGPTConversation.ps1

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,13 +534,21 @@ function New-ChatGPTConversation {
534534

535535
if ($stream) {
536536
Write-Verbose ($resources.verbose_chat_stream_mode)
537+
538+
# new stopwatch
539+
$stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
537540
$callapi = Invoke-StreamWebRequest -uri $params.Uri -body $params.Body -header $header
538541
# if the status of callapi is not ok, then write the error message to host and continue
539542
if ($callapi.status -ne "ok") {
540543
Write-Host "`r[$current] $($callapi.message)" -NoNewline -ForegroundColor Red
541544
Write-Host ""
542545
continue
543546
}
547+
548+
# print the verbose message include the stopwatch time
549+
Write-Verbose ("FCFR - {0} ms " -f ($stopwatch.ElapsedMilliseconds))
550+
$stopwatch.Stop()
551+
544552

545553
# otherwise, get the read of the result
546554
$reader = $callapi.reader
@@ -633,7 +641,6 @@ function New-ChatGPTConversation {
633641
$chunk = ($line -replace "data: ", "" | ConvertFrom-Json).choices.delta.content
634642
Write-Host $chunk -NoNewline -ForegroundColor Green
635643
$result += $chunk
636-
Start-Sleep -Milliseconds 5
637644
}
638645

639646
Write-Host ""
@@ -642,6 +649,8 @@ function New-ChatGPTConversation {
642649
content = $result
643650
}
644651

652+
653+
645654
Write-Verbose ($resources.verbose_chat_message_combined -f ($messages | ConvertTo-Json -Depth 10))
646655

647656
}

0 commit comments

Comments
 (0)