Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Key 'usageBytes' not found #100

Open
caloon opened this issue Nov 16, 2024 · 4 comments
Open

Key 'usageBytes' not found #100

caloon opened this issue Nov 16, 2024 · 4 comments

Comments

@caloon
Copy link

caloon commented Nov 16, 2024

I am trying to upload a document to a vector store and receive the following error message:

dataCouldNotBeReadMissingData(description: "Key \'usageBytes\' not found: No value associated with key CodingKeys(stringValue: \"usageBytes\", intValue: nil) (\"usageBytes\").codingPath: []")

The vector store was newly created and usage bytes does not seem to get set. The files are correctly uploaded to the OpenAI platform and can be found in the storage.

@jamesrochabrun
Copy link
Owner

Can you please share:

  • your request as curl.
  • Which API are you using.

The more details the fastest I can solve this, thanks.

@caloon
Copy link
Author

caloon commented Nov 17, 2024

  1. I am using the regular OpenAI API.
  2. Unfortunately, I do not know how to get the cURL, but I can share my code.
class OpenAIService {

  func createVectorStore(named name: String) async throws -> VectorStoreObject {
        let service = OpenAIServiceFactory.service(apiKey: apiKey)
        let storeParameters = VectorStoreParameter(name: name)
        return try await service.createVectorStore(parameters: storeParameters)
    }
    
    func retrieveVectorStore(id: String) async throws -> VectorStoreObject {
        let service = OpenAIServiceFactory.service(apiKey: apiKey)
        return try await service.retrieveVectorStore(id: id)
    }
    
    func uploadFile(_ file: Data, named name: String, toVectorStore vectorStoreID: String) async throws -> VectorStoreFileObject {
        let service = OpenAIServiceFactory.service(apiKey: apiKey)
        let fileParameters = FileParameters(fileName: name, file: file, purpose: "assistants")
        let uploadedFile = try await service.uploadFile(parameters: fileParameters)
        let storeFileParameters = VectorStoreFileParameter(fileID: uploadedFile.id)
        return try await service.createVectorStoreFile(vectorStoreID: vectorStoreID, parameters: storeFileParameters)
    }
}
let vectorStore = try await openAI.createVectorStore(named: "test")
var files: [VectorStoreFileObject] = []
for document in documents {
    if let name = document.key, let data = document.value {
      let file = try await openAI.uploadFile(data, named: name, toVectorStore: vectorStore.id)
      files.append(file)
    }
}

@jamesrochabrun
Copy link
Owner

I apologize for very delayed response, the uploadFile API seems to be working for me, when I upload document of type txt which document type are you trying to upload?

@caloon
Copy link
Author

caloon commented Jan 10, 2025

I am using a .pdf file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants