// SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // SPDX-License-Identifier: Apache-2.0 // // Based on https://github.com/64bit/async-openai/ by Himanshu Neema // Original Copyright (c) 2022 Himanshu Neema // Licensed under MIT License (see ATTRIBUTIONS-Rust.md) // // Modifications Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. // Licensed under Apache 2.0 use std::path::Path; use reqwest::Body; use tokio::fs::File; use tokio_util::codec::{BytesCodec, FramedRead}; use crate::error::OpenAIError; use crate::types::InputSource; pub(crate) async fn file_stream_body(source: InputSource) -> Result
{ let body = match source { InputSource::Path { path } => { let file = File::open(path) .await .map_err(|e| OpenAIError::FileReadError(e.to_string()))?; let stream = FramedRead::new(file, BytesCodec::new()); Body::wrap_stream(stream) } _ => { return Err(OpenAIError::FileReadError( "Cannot create stream from non-file source".to_string(), )) } }; Ok(body) } /// Creates the part for the given file for multipart upload. pub(crate) async fn create_file_part( source: InputSource, ) -> Result