Reject empty and truncated answers and expose complete tool calls
This commit is contained in:
1 parent
019a38f111
commit
3ca0994437
14 files changed
+278
-7
No files matched your search
@@ -119,6 +119,7 @@ func (s *Summarizer) callOnce(ctx context.Context, transcript, additionalInstruc
|
||||
}
|
||||
|
||||
var sb strings.Builder
|
||||
var terminalReason string
|
||||
for ev := range stream {
|
||||
switch ev.Type {
|
||||
case llm.EventTextDelta:
|
||||
@@ -126,6 +127,8 @@ func (s *Summarizer) callOnce(ctx context.Context, transcript, additionalInstruc
|
||||
return "", errors.New("summariser response exceeds 256 KiB")
|
||||
}
|
||||
sb.WriteString(ev.Text)
|
||||
case llm.EventDone:
|
||||
terminalReason = ev.StopReason
|
||||
case llm.EventError:
|
||||
return "", fmt.Errorf("compaction: stream error: %w", ev.Error)
|
||||
}
|
||||
@@ -133,6 +136,9 @@ func (s *Summarizer) callOnce(ctx context.Context, transcript, additionalInstruc
|
||||
if err := callCtx.Err(); err != nil {
|
||||
return "", err
|
||||
}
|
||||
if terminalReason == "length" || terminalReason == "max_tokens" {
|
||||
return "", errors.New("summariser reached its output limit; original history retained")
|
||||
}
|
||||
out := strings.TrimSpace(sb.String())
|
||||
if out == "" {
|
||||
return "", ErrEmptySummary
|
||||
|
||||
Reference in new issue
Block a user