streaming p0 fix: preserve upstream 400 body and cap stream edit length

This commit is contained in:
DBT
2026-02-26 13:28:31 +00:00
parent 7e32d9cd58
commit 0515a1247f
2 changed files with 9 additions and 2 deletions

View File

@@ -394,7 +394,7 @@ func (p *HTTPProvider) callChatCompletionsStream(ctx context.Context, messages [
requestBody["temperature"] = temperature
}
var fullText strings.Builder
_, status, ctype, err := p.postJSONStream(ctx, endpointFor(p.apiBase, "/chat/completions"), requestBody, func(event string) {
rawBody, status, ctype, err := p.postJSONStream(ctx, endpointFor(p.apiBase, "/chat/completions"), requestBody, func(event string) {
var chunk struct {
Choices []struct {
Delta struct {
@@ -416,6 +416,9 @@ func (p *HTTPProvider) callChatCompletionsStream(ctx context.Context, messages [
if err != nil {
return nil, status, ctype, err
}
if status != http.StatusOK || !strings.Contains(strings.ToLower(ctype), "text/event-stream") {
return rawBody, status, ctype, nil
}
body, _ := json.Marshal(map[string]interface{}{
"choices": []map[string]interface{}{{
"message": map[string]interface{}{"content": fullText.String()},