fix: support message content (#16980)

### Summary

As Title
<img width="3241" height="1934" alt="image"
src="https://github.com/user-attachments/assets/cb22031c-f200-462a-b871-b4a739e7a66a"
/>
This commit is contained in:
Haruko386
2026-07-16 19:08:36 +08:00
committed by GitHub
parent 5307ecd520
commit 101155bdc7
16 changed files with 831 additions and 288 deletions
+13 -5
View File
@@ -287,15 +287,23 @@ func (m *EinoChatModel) Stream(ctx context.Context, msgs []*schema.Message, opts
sr, sw := schema.Pipe[*schema.Message](1)
var sendMu sync.Mutex
sender := func(content *string, _ *string) error {
sender := func(content *string, reasoning *string) error {
sendMu.Lock()
defer sendMu.Unlock()
if content == nil {
if content == nil && reasoning == nil {
return nil
}
// Copy the string — the underlying buffer may be reused.
chunk := *content
if closed := sw.Send(&schema.Message{Role: schema.Assistant, Content: chunk}, nil); closed {
msg := &schema.Message{Role: schema.Assistant}
if content != nil {
msg.Content = *content
}
if reasoning != nil {
msg.ReasoningContent = *reasoning
}
if m.chatCfg != nil && m.chatCfg.StreamCallback != nil {
m.chatCfg.StreamCallback(msg.Content, msg.ReasoningContent)
}
if closed := sw.Send(msg, nil); closed {
return fmt.Errorf("models: stream closed before send completed")
}
return nil
+3
View File
@@ -172,6 +172,9 @@ type ChatConfig struct {
// non-nil) after the stream completes; callers read it the same
// way they read ToolCallsResult.
UsageResult *ChatUsage `json:"-"`
// StreamCallback receives raw content/reasoning deltas as soon as
// the model driver streams them.
StreamCallback func(contentDelta, reasoningDelta string) `json:"-"`
}
type APIConfig struct {