(difyResponse DifyChunkChatCompletionResponse)
| 175 | } |
| 176 | |
| 177 | func streamResponseDify2OpenAI(difyResponse DifyChunkChatCompletionResponse) *dto.ChatCompletionsStreamResponse { |
| 178 | response := dto.ChatCompletionsStreamResponse{ |
| 179 | Object: "chat.completion.chunk", |
| 180 | Created: common.GetTimestamp(), |
| 181 | Model: "dify", |
| 182 | } |
| 183 | var choice dto.ChatCompletionsStreamResponseChoice |
| 184 | if strings.HasPrefix(difyResponse.Event, "workflow_") { |
| 185 | if constant.DifyDebug { |
| 186 | text := "Workflow: " + difyResponse.Data.WorkflowId |
| 187 | if difyResponse.Event == "workflow_finished" { |
| 188 | text += " " + difyResponse.Data.Status |
| 189 | } |
| 190 | choice.Delta.SetReasoningContent(text + "\n") |
| 191 | } |
| 192 | } else if strings.HasPrefix(difyResponse.Event, "node_") { |
| 193 | if constant.DifyDebug { |
| 194 | text := "Node: " + difyResponse.Data.NodeType |
| 195 | if difyResponse.Event == "node_finished" { |
| 196 | text += " " + difyResponse.Data.Status |
| 197 | } |
| 198 | choice.Delta.SetReasoningContent(text + "\n") |
| 199 | } |
| 200 | } else if difyResponse.Event == "message" || difyResponse.Event == "agent_message" { |
| 201 | if difyResponse.Answer == "<details style=\"color:gray;background-color: #f8f8f8;padding: 8px;border-radius: 4px;\" open> <summary> Thinking... </summary>\n" { |
| 202 | difyResponse.Answer = "<think>" |
| 203 | } else if difyResponse.Answer == "</details>" { |
| 204 | difyResponse.Answer = "</think>" |
| 205 | } |
| 206 | |
| 207 | choice.Delta.SetContentString(difyResponse.Answer) |
| 208 | } |
| 209 | response.Choices = append(response.Choices, choice) |
| 210 | return &response |
| 211 | } |
| 212 | |
| 213 | func difyStreamHandler(c *gin.Context, info *relaycommon.RelayInfo, resp *http.Response) (*dto.Usage, *types.NewAPIError) { |
| 214 | var responseText string |
no test coverage detected