#include "vendors/azure/vector_stores.h" #include "vendors/azure/check.h" namespace molo::azure { using clients::body::Json; namespace { Query page(const ListParams& p, const std::string& filter = "") { p.validate(); Query q; p.apply(q); if (!filter.empty()) { Check::in_set("filter", filter, {"in_progress", "completed", "failed", "cancelled"}); q.add("filter", filter); } return q; } } // namespace Json VectorStoresService::create(const Json& body) { return call(Op::kCreateVectorStore, {}, &body); } Json VectorStoresService::get(const std::string& s) { Check::id("vector store", s); return call(Op::kGetVectorStore, {"", {s}}); } Json VectorStoresService::modify(const std::string& s, const Json& body) { Check::id("vector store", s); return call(Op::kModifyVectorStore, {"", {s}}, &body); } Json VectorStoresService::list(const ListParams& params) { Query q = page(params); return call(Op::kListVectorStores, {}, nullptr, &q); } Listing VectorStoresService::list_all(const ListParams& params, std::size_t max_pages) { return walk(Op::kListVectorStores, {}, params, Query(), max_pages); } Json VectorStoresService::remove(const std::string& s) { Check::id("vector store", s); return call(Op::kDeleteVectorStore, {"", {s}}); } Json VectorStoresService::search(const std::string& s, const Json& body) { Check::id("vector store", s); Check::has_field(body, "query"); return call(Op::kSearchVectorStore, {"", {s}}, &body); } Json VectorStoresService::add_file(const std::string& s, const Json& body) { Check::id("vector store", s); Check::has_string(body, "file_id"); return call(Op::kCreateVectorStoreFile, {"", {s}}, &body); } Json VectorStoresService::get_file(const std::string& s, const std::string& f) { Check::id("vector store", s); Check::id("file", f); return call(Op::kGetVectorStoreFile, {"", {s, f}}); } Json VectorStoresService::list_files(const std::string& s, const ListParams& params, const std::string& filter) { Check::id("vector store", s); Query q = page(params, filter); return call(Op::kListVectorStoreFiles, {"", {s}}, nullptr, &q); } Json VectorStoresService::update_file_attributes(const std::string& s, const std::string& f, const Json& attributes) { Check::id("vector store", s); Check::id("file", f); Check::object("attributes", attributes); Json body = Json::object(); body.set("attributes", attributes); return call(Op::kUpdateVectorStoreFileAttributes, {"", {s, f}}, &body); } Json VectorStoresService::file_content(const std::string& s, const std::string& f) { Check::id("vector store", s); Check::id("file", f); return call(Op::kRetrieveVectorStoreFileContent, {"", {s, f}}); } Json VectorStoresService::remove_file(const std::string& s, const std::string& f) { Check::id("vector store", s); Check::id("file", f); return call(Op::kDeleteVectorStoreFile, {"", {s, f}}); } Json VectorStoresService::create_file_batch(const std::string& s, const Json& body) { Check::id("vector store", s); Check::require(body.find("file_ids") || body.find("files"), "file_ids (or files) is required"); return call(Op::kCreateVectorStoreFileBatch, {"", {s}}, &body); } Json VectorStoresService::get_file_batch(const std::string& s, const std::string& b) { Check::id("vector store", s); Check::id("batch", b); return call(Op::kGetVectorStoreFileBatch, {"", {s, b}}); } Json VectorStoresService::cancel_file_batch(const std::string& s, const std::string& b) { Check::id("vector store", s); Check::id("batch", b); return call(Op::kCancelVectorStoreFileBatch, {"", {s, b}}); } Json VectorStoresService::list_batch_files(const std::string& s, const std::string& b, const ListParams& params, const std::string& filter) { Check::id("vector store", s); Check::id("batch", b); Query q = page(params, filter); return call(Op::kListFilesInVectorStoreBatch, {"", {s, b}}, nullptr, &q); } } // namespace molo::azure