95 lines
3.5 KiB
C++
95 lines
3.5 KiB
C++
#pragma once
|
|
|
|
// Discussions (and pull request threads), Collections and Webhooks on the Hub.
|
|
// Reads are public where the Hub makes them public; every write needs a token
|
|
// and is an explicit method. Deletes have no defaults and are named remove_*.
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "vendors/huggingface/hf_service.h"
|
|
|
|
namespace molo::huggingface {
|
|
|
|
struct DiscussionFilter {
|
|
int page = 0; // p
|
|
std::string kind; // all, discussion, pull_request
|
|
std::string status; // all, open, closed
|
|
std::string author;
|
|
std::string search;
|
|
std::string sort; // recently-created, trending, reactions
|
|
};
|
|
|
|
class Discussions : public HfService {
|
|
public:
|
|
explicit Discussions(Access access) : HfService(std::move(access), Surface::kHub) {}
|
|
Json list(RepoType type, const RepoRef& repo, const DiscussionFilter& filter = {});
|
|
Json get(RepoType type, const RepoRef& repo, long num);
|
|
|
|
// Writes (token required).
|
|
Json create(RepoType type, const RepoRef& repo, const std::string& title, const std::string& description,
|
|
bool pull_request);
|
|
Json comment(RepoType type, const RepoRef& repo, long num, const std::string& text);
|
|
Json change_status(RepoType type, const RepoRef& repo, long num, const std::string& status,
|
|
const std::string& comment = "");
|
|
Json rename(RepoType type, const RepoRef& repo, long num, const std::string& title);
|
|
Json remove_discussion(RepoType type, const RepoRef& repo, long num);
|
|
};
|
|
|
|
struct CollectionItem {
|
|
std::string type; // paper, collection, space, model, dataset, bucket
|
|
std::string id;
|
|
Json to_json() const; // validates
|
|
};
|
|
|
|
struct CollectionListParams {
|
|
std::string owner;
|
|
std::string q;
|
|
std::string sort;
|
|
int limit = 0;
|
|
CollectionItem item; // optional filter: collections containing this item (id empty: none)
|
|
Query to_query() const;
|
|
};
|
|
|
|
class Collections : public HfService {
|
|
public:
|
|
explicit Collections(Access access) : HfService(std::move(access), Surface::kHub) {}
|
|
Page list(const CollectionListParams& params, std::size_t max_items = 100, std::size_t max_pages = 5);
|
|
// slug is "name-<24 hex id>" exactly as the Hub prints it after the owner.
|
|
Json get(const std::string& owner, const std::string& slug);
|
|
|
|
Json create(const std::string& owner, const std::string& title, const std::string& description,
|
|
bool is_private);
|
|
Json update(const std::string& owner, const std::string& slug, const Json& fields);
|
|
Json add_item(const std::string& owner, const std::string& slug, const CollectionItem& item,
|
|
const std::string& note = "");
|
|
Json remove_collection(const std::string& owner, const std::string& slug);
|
|
};
|
|
|
|
struct WebhookSpec {
|
|
struct Watched {
|
|
std::string type; // dataset, model, space, bucket, kernel, container, user, org
|
|
std::string name;
|
|
};
|
|
std::string url;
|
|
std::vector<Watched> watched;
|
|
std::vector<std::string> domains; // repo, discussion
|
|
std::string secret; // printable ASCII, optional
|
|
Json to_json() const; // validates
|
|
};
|
|
|
|
class Webhooks : public HfService {
|
|
public:
|
|
explicit Webhooks(Access access) : HfService(std::move(access), Surface::kHub) {}
|
|
Json list();
|
|
Json get(const std::string& id);
|
|
Json create(const WebhookSpec& spec);
|
|
Json update(const std::string& id, const WebhookSpec& spec);
|
|
Json enable(const std::string& id);
|
|
Json disable(const std::string& id);
|
|
Json replay(const std::string& id, const std::string& log_id);
|
|
Json remove_webhook(const std::string& id);
|
|
};
|
|
|
|
} // namespace molo::huggingface
|