(openAIResponse *dto.OpenAITextResponse, info *relaycommon.RelayInfo)
| 379 | } |
| 380 | |
| 381 | func ResponseOpenAI2Claude(openAIResponse *dto.OpenAITextResponse, info *relaycommon.RelayInfo) *dto.ClaudeResponse { |
| 382 | var stopReason string |
| 383 | contents := make([]dto.ClaudeMediaMessage, 0) |
| 384 | claudeResponse := &dto.ClaudeResponse{ |
| 385 | Id: openAIResponse.Id, |
| 386 | Type: "message", |
| 387 | Role: "assistant", |
| 388 | Model: openAIResponse.Model, |
| 389 | } |
| 390 | for _, choice := range openAIResponse.Choices { |
| 391 | stopReason = stopReasonOpenAI2Claude(choice.FinishReason) |
| 392 | claudeContent := dto.ClaudeMediaMessage{} |
| 393 | if choice.FinishReason == "tool_calls" { |
| 394 | claudeContent.Type = "tool_use" |
| 395 | claudeContent.Id = choice.Message.ToolCallId |
| 396 | claudeContent.Name = choice.Message.ParseToolCalls()[0].Function.Name |
| 397 | var mapParams map[string]interface{} |
| 398 | if err := json.Unmarshal([]byte(choice.Message.ParseToolCalls()[0].Function.Arguments), &mapParams); err == nil { |
| 399 | claudeContent.Input = mapParams |
| 400 | } else { |
| 401 | claudeContent.Input = choice.Message.ParseToolCalls()[0].Function.Arguments |
| 402 | } |
| 403 | } else { |
| 404 | claudeContent.Type = "text" |
| 405 | claudeContent.SetText(choice.Message.StringContent()) |
| 406 | } |
| 407 | contents = append(contents, claudeContent) |
| 408 | } |
| 409 | claudeResponse.Content = contents |
| 410 | claudeResponse.StopReason = stopReason |
| 411 | claudeResponse.Usage = &dto.ClaudeUsage{ |
| 412 | InputTokens: openAIResponse.PromptTokens, |
| 413 | OutputTokens: openAIResponse.CompletionTokens, |
| 414 | } |
| 415 | |
| 416 | return claudeResponse |
| 417 | } |
| 418 | |
| 419 | func stopReasonOpenAI2Claude(reason string) string { |
| 420 | switch reason { |
no test coverage detected