Enhance response structure and stream start data in Assistant for improved context handling
- Updated the Response struct to include ContextID, RequestID, ChatID, and AssistantID for better traceability and context management. - Modified the Stream method to return the new fields in the response, enhancing the output for client interactions. - Added ContextID and ChatID to the StreamStartData struct to improve event tracking during streaming requests.
This commit is contained in:
parent
21c0ec5034
commit
ea167b35a7
3 changed files with 19 additions and 8 deletions
|
|
@ -249,7 +249,12 @@ func (ast *Assistant) Stream(ctx *context.Context, inputMessages []context.Messa
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return &context.Response{Create: createResponse, Done: doneResponse, Completion: completionResponse}, nil
|
return &context.Response{
|
||||||
|
ContextID: ctx.ID,
|
||||||
|
RequestID: ctx.RequestID(),
|
||||||
|
ChatID: ctx.ChatID,
|
||||||
|
AssistantID: ast.ID,
|
||||||
|
Create: createResponse, Done: doneResponse, Completion: completionResponse}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetConnector get the connector object, capabilities, and error with priority: createResponse > ctx > ast
|
// GetConnector get the connector object, capabilities, and error with priority: createResponse > ctx > ast
|
||||||
|
|
@ -676,11 +681,12 @@ func (ast *Assistant) sendAgentStreamStart(ctx *context.Context, handler context
|
||||||
|
|
||||||
// Build the start data
|
// Build the start data
|
||||||
startData := context.StreamStartData{
|
startData := context.StreamStartData{
|
||||||
|
ContextID: ctx.ID,
|
||||||
|
ChatID: ctx.ChatID,
|
||||||
|
TraceID: ctx.TraceID(),
|
||||||
RequestID: ctx.RequestID(),
|
RequestID: ctx.RequestID(),
|
||||||
Timestamp: startTime.UnixMilli(),
|
Timestamp: startTime.UnixMilli(),
|
||||||
Assistant: ast.Info(ctx.Locale),
|
Assistant: ast.Info(ctx.Locale),
|
||||||
ChatID: ctx.ChatID,
|
|
||||||
TraceID: ctx.TraceID(),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if startJSON, err := jsoniter.Marshal(startData); err == nil {
|
if startJSON, err := jsoniter.Marshal(startData); err == nil {
|
||||||
|
|
|
||||||
|
|
@ -263,11 +263,15 @@ type Stack struct {
|
||||||
// Response the response
|
// Response the response
|
||||||
// 100% compatible with the OpenAI API
|
// 100% compatible with the OpenAI API
|
||||||
type Response struct {
|
type Response struct {
|
||||||
Create *HookCreateResponse `json:"create,omitempty"`
|
RequestID string `json:"request_id"` // Request ID for the response
|
||||||
MCP *ResponseHookMCP `json:"mcp,omitempty"`
|
ContextID string `json:"context_id"` // Context ID for the response
|
||||||
Done *ResponseHookDone `json:"done,omitempty"`
|
ChatID string `json:"chat_id"` // Chat ID for the response
|
||||||
Failback *ResponseHookFailback `json:"failback,omitempty"`
|
AssistantID string `json:"assistant_id"` // Assistant ID for the response
|
||||||
Completion *CompletionResponse `json:"completion,omitempty"`
|
Create *HookCreateResponse `json:"create,omitempty"`
|
||||||
|
MCP *ResponseHookMCP `json:"mcp,omitempty"`
|
||||||
|
Done *ResponseHookDone `json:"done,omitempty"`
|
||||||
|
Failback *ResponseHookFailback `json:"failback,omitempty"`
|
||||||
|
Completion *CompletionResponse `json:"completion,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// HookCreateResponse the response of the create hook
|
// HookCreateResponse the response of the create hook
|
||||||
|
|
|
||||||
|
|
@ -221,6 +221,7 @@ 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
|
||||||
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")
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue