feat(clients): meta: Meta Model API module, Muse Code protocol client, demo and tests
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
#pragma once
|
||||
|
||||
// Files API: upload once (up to 1 GiB by the docs, 512 MiB by llm::Caps), then
|
||||
// reference a `file-...` id from input_file / input_image / input_video parts.
|
||||
// Uploaded files do not expire unless expires_after is set (3600..2592000 s);
|
||||
// the team storage limit is 100 GiB. The list endpoint answers a plain-text 400
|
||||
// for a bad `order` (docs: error-handling), so order is validated locally.
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "llm/api_client.h"
|
||||
#include "meta/jsonx.h"
|
||||
|
||||
namespace molo::meta {
|
||||
|
||||
struct FileObject {
|
||||
std::string id;
|
||||
long bytes = 0;
|
||||
long created_at = 0;
|
||||
long expires_at = 0; // 0 = never
|
||||
std::string filename;
|
||||
std::string purpose;
|
||||
std::string status; // uploaded | processed | error
|
||||
std::string status_details;
|
||||
static FileObject from_json(const Json& j);
|
||||
};
|
||||
|
||||
struct FileUpload {
|
||||
std::string filename;
|
||||
std::string mime; // documented media type
|
||||
std::string bytes;
|
||||
std::string purpose = "user_data"; // user_data | batch
|
||||
long expires_after_seconds = 0; // 0 = no expiry; else 3600..2592000
|
||||
|
||||
void validate() const;
|
||||
};
|
||||
|
||||
struct FileList {
|
||||
std::vector<FileObject> files;
|
||||
bool has_more = false; // true when the server has more than we returned
|
||||
bool truncated = false; // true when our page cap stopped the walk
|
||||
std::size_t pages = 0;
|
||||
};
|
||||
|
||||
class FilesService : public llm::Service {
|
||||
public:
|
||||
explicit FilesService(std::shared_ptr<llm::ApiClient> client)
|
||||
: llm::Service(std::move(client)) {}
|
||||
|
||||
static bool supported_mime(const std::string& mime);
|
||||
|
||||
FileObject upload(const FileUpload& file);
|
||||
// One page. order: "" | asc | desc. after: a file id cursor.
|
||||
Json list_page(const std::string& purpose = "", int limit = 100, const std::string& order = "",
|
||||
const std::string& after = "");
|
||||
// Walks pages up to MetaCaps::kMaxListPages and reports truncation loudly.
|
||||
FileList list_all(const std::string& purpose = "", int page_size = 100,
|
||||
const std::string& order = "");
|
||||
FileObject retrieve(const std::string& file_id);
|
||||
// Raw bytes of an uploaded file.
|
||||
std::string content(const std::string& file_id);
|
||||
// Destructive: frees team storage. No default, no retry.
|
||||
Json remove(const std::string& file_id);
|
||||
};
|
||||
|
||||
} // namespace molo::meta
|
||||
Reference in New Issue
Block a user