(openAIResponse *dto.ChatCompletionsStreamResponse, info *relaycommon.RelayInfo)
| 218 | } |
| 219 | |
| 220 | func StreamResponseOpenAI2Claude(openAIResponse *dto.ChatCompletionsStreamResponse, info *relaycommon.RelayInfo) []*dto.ClaudeResponse { |
| 221 | var claudeResponses []*dto.ClaudeResponse |
| 222 | if info.SendResponseCount == 1 { |
| 223 | msg := &dto.ClaudeMediaMessage{ |
| 224 | Id: openAIResponse.Id, |
| 225 | Model: openAIResponse.Model, |
| 226 | Type: "message", |
| 227 | Role: "assistant", |
| 228 | Usage: &dto.ClaudeUsage{ |
| 229 | InputTokens: info.PromptTokens, |
| 230 | OutputTokens: 0, |
| 231 | }, |
| 232 | } |
| 233 | msg.SetContent(make([]any, 0)) |
| 234 | claudeResponses = append(claudeResponses, &dto.ClaudeResponse{ |
| 235 | Type: "message_start", |
| 236 | Message: msg, |
| 237 | }) |
| 238 | claudeResponses = append(claudeResponses) |
| 239 | //claudeResponses = append(claudeResponses, &dto.ClaudeResponse{ |
| 240 | // Type: "ping", |
| 241 | //}) |
| 242 | if openAIResponse.IsToolCall() { |
| 243 | resp := &dto.ClaudeResponse{ |
| 244 | Type: "content_block_start", |
| 245 | ContentBlock: &dto.ClaudeMediaMessage{ |
| 246 | Id: openAIResponse.GetFirstToolCall().ID, |
| 247 | Type: "tool_use", |
| 248 | Name: openAIResponse.GetFirstToolCall().Function.Name, |
| 249 | }, |
| 250 | } |
| 251 | resp.SetIndex(0) |
| 252 | claudeResponses = append(claudeResponses, resp) |
| 253 | } else { |
| 254 | //resp := &dto.ClaudeResponse{ |
| 255 | // Type: "content_block_start", |
| 256 | // ContentBlock: &dto.ClaudeMediaMessage{ |
| 257 | // Type: "text", |
| 258 | // Text: common.GetPointer[string](""), |
| 259 | // }, |
| 260 | //} |
| 261 | //resp.SetIndex(0) |
| 262 | //claudeResponses = append(claudeResponses, resp) |
| 263 | } |
| 264 | return claudeResponses |
| 265 | } |
| 266 | |
| 267 | if len(openAIResponse.Choices) == 0 { |
| 268 | // no choices |
| 269 | // TODO: handle this case |
| 270 | return claudeResponses |
| 271 | } else { |
| 272 | chosenChoice := openAIResponse.Choices[0] |
| 273 | if chosenChoice.FinishReason != nil && *chosenChoice.FinishReason != "" { |
| 274 | // should be done |
| 275 | info.FinishReason = *chosenChoice.FinishReason |
| 276 | return claudeResponses |
| 277 | } |
no test coverage detected