Update internal/monica/sse.go
Browse files- internal/monica/sse.go +44 -16
internal/monica/sse.go
CHANGED
@@ -26,8 +26,14 @@ const (
|
|
26 |
|
27 |
// SSEData 用于解析 Monica SSE json
|
28 |
type SSEData struct {
|
29 |
-
Text
|
30 |
-
Finished
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
}
|
32 |
|
33 |
var sseDataPool = sync.Pool{
|
@@ -116,22 +122,44 @@ func StreamMonicaSSEToClient(model string, w io.Writer, r io.Reader) error {
|
|
116 |
},
|
117 |
}
|
118 |
} else {
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
|
|
|
|
|
|
|
|
|
|
131 |
},
|
132 |
-
FinishReason: openai.FinishReasonNull,
|
133 |
},
|
134 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
}
|
136 |
}
|
137 |
|
|
|
26 |
|
27 |
// SSEData 用于解析 Monica SSE json
|
28 |
type SSEData struct {
|
29 |
+
Text string `json:"text"`
|
30 |
+
Finished bool `json:"finished"`
|
31 |
+
AgentStatus struct {
|
32 |
+
Type string `json:"type"`
|
33 |
+
Metadata struct {
|
34 |
+
ReasoningDetail string `json:"reasoning_detail"`
|
35 |
+
} `json:"metadata"`
|
36 |
+
} `json:"agent_status"`
|
37 |
}
|
38 |
|
39 |
var sseDataPool = sync.Pool{
|
|
|
122 |
},
|
123 |
}
|
124 |
} else {
|
125 |
+
// 检查是否是思考内容
|
126 |
+
if sseObj.AgentStatus.Type == "thinking_detail_stream" {
|
127 |
+
sseMsg = types.ChatCompletionStreamResponse{
|
128 |
+
ID: "chatcmpl-" + chatId,
|
129 |
+
Object: sseObject,
|
130 |
+
SystemFingerprint: fingerprint,
|
131 |
+
Created: now,
|
132 |
+
Model: model,
|
133 |
+
ReasoningContent: sseObj.AgentStatus.Metadata.ReasoningDetail,
|
134 |
+
Choices: []types.ChatCompletionStreamChoice{
|
135 |
+
{
|
136 |
+
Index: 0,
|
137 |
+
Delta: openai.ChatCompletionStreamChoiceDelta{
|
138 |
+
Role: openai.ChatMessageRoleAssistant,
|
139 |
+
Content: "",
|
140 |
+
},
|
141 |
+
FinishReason: openai.FinishReasonNull,
|
142 |
},
|
|
|
143 |
},
|
144 |
+
}
|
145 |
+
} else {
|
146 |
+
sseMsg = types.ChatCompletionStreamResponse{
|
147 |
+
ID: "chatcmpl-" + chatId,
|
148 |
+
Object: sseObject,
|
149 |
+
SystemFingerprint: fingerprint,
|
150 |
+
Created: now,
|
151 |
+
Model: model,
|
152 |
+
Choices: []types.ChatCompletionStreamChoice{
|
153 |
+
{
|
154 |
+
Index: 0,
|
155 |
+
Delta: openai.ChatCompletionStreamChoiceDelta{
|
156 |
+
Role: openai.ChatMessageRoleAssistant,
|
157 |
+
Content: sseObj.Text,
|
158 |
+
},
|
159 |
+
FinishReason: openai.FinishReasonNull,
|
160 |
+
},
|
161 |
+
},
|
162 |
+
}
|
163 |
}
|
164 |
}
|
165 |
|