Files
moloapp/src/vendors/azure/operations.h
T

54 lines
2.1 KiB
C++

#pragma once
// OperationsService: every operation of the call table by name, for the ones
// that have no typed class (containers, conversations, evals, graders,
// videos, checkpoint tools) and for the demo's generic route. Same gateway as
// the typed services: ids validated, fields and query names checked against
// the spec, api side and api-version chosen from the settings.
#include <map>
#include <string>
#include "vendors/azure/service.h"
namespace molo::azure {
class OperationsService {
public:
explicit OperationsService(std::shared_ptr<AzureClient> azure);
// JSON in, JSON out. `body` may be null. `query` values are strings.
// Throws ApiError::invalid for an unknown name, wrong ids, unknown fields or
// query names, or an operation that needs multipart / streams / answers bytes
// (use the typed service for those).
clients::body::Json invoke(const std::string& name, const Target& target,
const clients::body::Json* body = nullptr,
const std::map<std::string, std::string>& query = {});
// Route and body exactly as invoke() would send them; no traffic.
struct Plan {
std::string method;
std::string path; // with query and api-version
clients::body::Json body;
bool has_body = false;
bool destructive = false;
std::string side; // "v1" or "dated"
};
Plan plan(const std::string& name, const Target& target, const clients::body::Json* body = nullptr,
const std::map<std::string, std::string>& query = {}) const;
// DELETE, cancel, reject, hangup, pause, remove: the demo asks for confirm.
static bool destructive(const CallSpec& spec);
// Calls the generic JSON path can make (not multipart-only, not binary).
static bool generic(const CallSpec& spec);
private:
AzureService& gate(Surface s) const;
const CallSpec& lookup(const std::string& name) const;
Query to_query(const std::map<std::string, std::string>& query) const;
std::shared_ptr<AzureClient> azure_;
mutable AzureService openai_, foundry_, safety_;
};
} // namespace molo::azure