mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-09-08 10:14:35 +08:00
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:
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user