Merge pull request #1344 from trheyi/main
Enhance stream data structures in Assistant for improved context and …
This commit is contained in:
commit
02105da82b
2 changed files with 20 additions and 12 deletions
|
|
@ -710,6 +710,7 @@ func (ast *Assistant) sendAgentStreamStart(ctx *context.Context, handler context
|
||||||
RequestID: ctx.RequestID(),
|
RequestID: ctx.RequestID(),
|
||||||
Timestamp: startTime.UnixMilli(),
|
Timestamp: startTime.UnixMilli(),
|
||||||
Assistant: ast.Info(ctx.Locale),
|
Assistant: ast.Info(ctx.Locale),
|
||||||
|
Metadata: ctx.Metadata,
|
||||||
}
|
}
|
||||||
|
|
||||||
if startJSON, err := jsoniter.Marshal(startData); err == nil {
|
if startJSON, err := jsoniter.Marshal(startData); err == nil {
|
||||||
|
|
@ -731,9 +732,12 @@ func (ast *Assistant) sendAgentStreamEnd(ctx *context.Context, handler context.S
|
||||||
|
|
||||||
endData := &context.StreamEndData{
|
endData := &context.StreamEndData{
|
||||||
RequestID: ctx.RequestID(),
|
RequestID: ctx.RequestID(),
|
||||||
|
ContextID: ctx.ID,
|
||||||
Timestamp: time.Now().UnixMilli(),
|
Timestamp: time.Now().UnixMilli(),
|
||||||
DurationMs: time.Since(startTime).Milliseconds(),
|
DurationMs: time.Since(startTime).Milliseconds(),
|
||||||
Status: status,
|
Status: status,
|
||||||
|
TraceID: ctx.TraceID(),
|
||||||
|
Metadata: ctx.Metadata,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -221,23 +221,27 @@ type JSONSchema struct {
|
||||||
// StreamStartData represents the data for stream_start event
|
// StreamStartData represents the data for stream_start event
|
||||||
// Sent when a streaming request begins
|
// Sent when a streaming request begins
|
||||||
type StreamStartData struct {
|
type StreamStartData struct {
|
||||||
ContextID string `json:"context_id"` // Context ID for the response
|
ContextID string `json:"context_id"` // Context ID for the response
|
||||||
RequestID string `json:"request_id"` // Unique identifier for this request
|
RequestID string `json:"request_id"` // Unique identifier for this request
|
||||||
Timestamp int64 `json:"timestamp"` // Unix timestamp when stream started
|
Timestamp int64 `json:"timestamp"` // Unix timestamp when stream started
|
||||||
ChatID string `json:"chat_id"` // Chat ID being used (e.g., "chat-123")
|
ChatID string `json:"chat_id"` // Chat ID being used (e.g., "chat-123")
|
||||||
TraceID string `json:"trace_id"` // Trace ID being used (e.g., "trace-123")
|
TraceID string `json:"trace_id"` // Trace ID being used (e.g., "trace-123")
|
||||||
Assistant *AssistantInfo `json:"assistant,omitempty"` // Assistant information
|
Assistant *AssistantInfo `json:"assistant,omitempty"` // Assistant information
|
||||||
|
Metadata map[string]interface{} `json:"metadata,omitempty"` // Metadata to pass to the page for CUI context
|
||||||
}
|
}
|
||||||
|
|
||||||
// StreamEndData represents the data for stream_end event
|
// StreamEndData represents the data for stream_end event
|
||||||
// Sent when a streaming request completes (successfully or with error)
|
// Sent when a streaming request completes (successfully or with error)
|
||||||
type StreamEndData struct {
|
type StreamEndData struct {
|
||||||
RequestID string `json:"request_id"` // Corresponding request ID
|
RequestID string `json:"request_id"` // Corresponding request ID
|
||||||
Timestamp int64 `json:"timestamp"` // Unix timestamp when stream ended
|
ContextID string `json:"context_id"` // Context ID for the response
|
||||||
DurationMs int64 `json:"duration_ms"` // Total duration in milliseconds
|
TraceID string `json:"trace_id"` // Trace ID being used (e.g., "trace-123")
|
||||||
Status string `json:"status"` // "completed" | "error" | "cancelled"
|
Timestamp int64 `json:"timestamp"` // Unix timestamp when stream ended
|
||||||
Error string `json:"error,omitempty"` // Error message if status is "error"
|
DurationMs int64 `json:"duration_ms"` // Total duration in milliseconds
|
||||||
Usage *UsageInfo `json:"usage,omitempty"` // Token usage statistics
|
Status string `json:"status"` // "completed" | "error" | "cancelled"
|
||||||
|
Error string `json:"error,omitempty"` // Error message if status is "error"
|
||||||
|
Usage *UsageInfo `json:"usage,omitempty"` // Token usage statistics
|
||||||
|
Metadata map[string]interface{} `json:"metadata,omitempty"` // Metadata to pass to the page for CUI context
|
||||||
}
|
}
|
||||||
|
|
||||||
// GroupStartData represents the data for group_start event
|
// GroupStartData represents the data for group_start event
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue