-
Notifications
You must be signed in to change notification settings - Fork 171
Closed
Labels
Description
Given:
@SpringBootTest
@ActiveProfiles("integration-test")
class SoraStrategyTest {
val path = Path("/my/path/bear.jpeg")
@Autowired
lateinit var openAiClient: OpenAIClient
@Test
fun testIt() {
val prompt = "bear is cooking a fish"
openAiClient.videos().create(
VideoCreateParams.builder()
.model(VideoModel.SORA_2)
.prompt(prompt)
.seconds(VideoSeconds.of("4"))
.let { builder ->
path.let {
builder
.inputReference(MultipartField.builder<InputStream>()
.value(it.inputStream())
.contentType("image/jpeg")
.build())
}
}
.size(VideoSize._720X1280)
.build()
)
}
}It fails with
com.openai.errors.BadRequestException: 400: Invalid type for 'input_reference': expected a file, but got a string instead.
I tried many options... need a clue please
It works like this in raw
@Test
fun testRaw() {
val prompt = "bear is cooking a fish"
val r = generateVideo(prompt, path.inputStream())
println(r.code)
println(r.body?.string())
}
fun generateVideo(prompt: String, imageStream: InputStream): Response {
val client = OkHttpClient()
val body = MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("prompt", prompt)
.addFormDataPart("model", "sora-2")
.addFormDataPart("size", "720x1280")
.addFormDataPart(
"input_reference",
"image.jpg",
RequestBody.create("image/jpeg".toMediaTypeOrNull()!!, imageStream.readBytes())
)
.build()
val request = Request.Builder()
.url("https://api.openai.com/v1/videos")
.post(body)
.addHeader("Authorization", "Bearer ...")
.build()
return client.newCall(request).execute()
}