case schema.ChatMessagePartTypeAudioURL:
if part.Audio == nil {
return comMessage, errors.New("the 'audio' field is required for parts of type 'audio_url'")
}
if part.Audio.Base64Data != nil {
format, ok := mimeType2AudioFormat[part.Audio.MIMEType]
if !ok {
return comMessage, fmt.Errorf("the 'format' field is required when type is audio_url, use SetMessageInputAudioFormat to set it")
}
comMessage.MultiContent = append(comMessage.MultiContent, openai.ChatMessagePart{
Type: openai.ChatMessagePartTypeInputAudio,
InputAudio: &openai.ChatMessageInputAudio{
Data: *part.Audio.Base64Data,
Format: format,
},
})
} else if part.Audio.URL != nil {
format, ok := mimeType2AudioFormat[part.Audio.MIMEType]
if !ok {
return comMessage, fmt.Errorf("the 'format' field is required when type is audio_url, use SetMessageInputAudioFormat to set it")
}
//TODO:源码改动,这是已经改动的。
comMessage.MultiContent = append(comMessage.MultiContent, openai.ChatMessagePart{
Type: openai.ChatMessagePartTypeInputAudio,
InputAudio: &openai.ChatMessageInputAudio{
Data: *part.Audio.URL,
Format: format,
},
})
//以下注释的地方就是原代码,这里我们按照格式修改源代码。
//return comMessage, errors.New("for user role, audio message part does not accept URL, only base64 data is supported")
} else {
return comMessage, errors.New("audio message part must have url or base64 data")
}
简化版 Debug & 代码修改流程
从业务代码 model.Stream(ctx, messages) 点进 Stream 方法;
在 Stream 方法里找到 cm.cli.Stream(ctx, in, opts...),继续点进该底层实现;