MCPcopy Create free account
hub / github.com/aiprodcoder/MIXAPI / ResponseOpenAI2Claude

Function ResponseOpenAI2Claude

service/convert.go:381–417  ·  view source on GitHub ↗
(openAIResponse *dto.OpenAITextResponse, info *relaycommon.RelayInfo)

Source from the content-addressed store, hash-verified

379}
380
381func 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
419func stopReasonOpenAI2Claude(reason string) string {
420 switch reason {

Callers 1

OpenaiHandlerFunction · 0.92

Calls 4

SetTextMethod · 0.95
stopReasonOpenAI2ClaudeFunction · 0.85
ParseToolCallsMethod · 0.80
StringContentMethod · 0.80

Tested by

no test coverage detected