Skip to content

Commit cca439c

Browse files
hiibolt64bit
andauthored
fix: Update vector store file chunking strategy to use StaticChunkingStrategy (64bit#230)
* fix: Update vector store file chunking strategy to use StaticChunkingStrategy This targets the changes mentioned in 64bit#229, because OpenAI requires a non-null name when creating a vector store. This also fixes attaching a file to a vector store, where it would fail to deserialize. Also adds a test for both errors to catch them during development in the future! 64bit#229 * bugfix: Made optional name field consistent to OpenAI spec Reverted according to recent comments on 64bit#229, reasoning can be found on thread. * chore: Modified redudant code in test Related details can be found in PR 64bit#230 * test: Update tests to double check for a failure in add file to vector store Related PR: 64bit#230 Co-authored-by: Himanshu Neema <himanshun.iitkgp@gmail.com> --------- Co-authored-by: Himanshu Neema <himanshun.iitkgp@gmail.com>
1 parent f5a0ea0 commit cca439c

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

async-openai/src/types/vector_store.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub struct VectorStoreObject {
6363
/// The Unix timestamp (in seconds) for when the vector store was created.
6464
pub created_at: u32,
6565
/// The name of the vector store.
66-
pub name: String,
66+
pub name: Option<String>,
6767
/// The total number of bytes used by the files in the vector store.
6868
pub usage_bytes: u64,
6969
pub file_counts: VectorStoreFileCounts,
@@ -192,7 +192,7 @@ pub enum VectorStoreFileErrorCode {
192192
pub enum VectorStoreFileObjectChunkingStrategy {
193193
/// This is returned when the chunking strategy is unknown. Typically, this is because the file was indexed before the `chunking_strategy` concept was introduced in the API.
194194
Other,
195-
Static(StaticChunkingStrategy),
195+
Static{ r#static: StaticChunkingStrategy },
196196
}
197197

198198
#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)]

async-openai/src/vector_store_files.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,55 @@ impl<'c, C: Config> VectorStoreFiles<'c, C> {
7575
.await
7676
}
7777
}
78+
79+
#[cfg(test)]
80+
mod tests {
81+
use crate::Client;
82+
use crate::types::{CreateFileRequest, CreateVectorStoreFileRequest, CreateVectorStoreRequest, FileInput, FilePurpose};
83+
84+
#[tokio::test]
85+
async fn vector_store_file_creation_and_deletion() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
86+
let client = Client::new();
87+
88+
// Create a file
89+
let file_handle = client
90+
.files()
91+
.create( CreateFileRequest {
92+
file: FileInput::from_vec_u8(
93+
String::from("meow.txt"),
94+
String::from(":3").into_bytes()
95+
),
96+
purpose: FilePurpose::Assistants
97+
}).await?;
98+
99+
// Create a vector store
100+
let vector_store_handle = client
101+
.vector_stores()
102+
.create( CreateVectorStoreRequest {
103+
file_ids: Some(vec![file_handle.id.clone()]),
104+
name: None,
105+
expires_after: None,
106+
chunking_strategy: None,
107+
metadata: None
108+
})
109+
.await?;
110+
let vector_store_file = client
111+
.vector_stores()
112+
.files(&vector_store_handle.id)
113+
.retrieve(&file_handle.id)
114+
.await?;
115+
116+
assert_eq!(vector_store_file.id, file_handle.id);
117+
// Delete the vector store
118+
client
119+
.vector_stores()
120+
.delete(&vector_store_handle.id).await?;
121+
122+
// Delete the file
123+
client
124+
.files()
125+
.delete(&file_handle.id).await?;
126+
127+
Ok(())
128+
}
129+
}

0 commit comments

Comments
 (0)