Files
moloapp/src/vendors/bedrock/calls.h
T

66 lines
2.7 KiB
C++

#pragma once
// The ONE table of REST calls this module makes. tools/check_spec.py checks
// every row against the AWS service models (botocore service-2.json for
// bedrock, bedrock-runtime, bedrock-agent-runtime): operation name, HTTP
// method, request URI, path / query / header / body members, bearer support,
// and the response fields we read. Code builds every path from this table.
#include <cstddef>
#include <map>
#include <string>
#include "clients/request.h"
#include "vendors/bedrock/credentials.h"
namespace molo::bedrock {
enum class Call {
kConverse, kConverseStream, kInvokeModel, kInvokeModelStream, kCountTokens, kApplyGuardrail,
kInvokeAgent, kRetrieve,
kListFoundationModels, kGetFoundationModel, kListInferenceProfiles, kGetInferenceProfile,
kListGuardrails, kGetGuardrail,
kCreateBatchJob, kGetBatchJob, kListBatchJobs, kStopBatchJob,
};
struct CallSpec {
Call call;
AwsService service;
const char* op; // service model operation name
const char* http_method; // GET POST
const char* uri; // request URI template, "{name}" placeholders
const char* path_params; // comma list, same names as the placeholders
const char* query_params; // comma list of query string names we send
const char* header_params; // comma list of header names we send
const char* body_fields; // comma list of JSON body members we send ("body" = raw payload)
const char* response; // response schema name in the schema table
bool bearer_ok; // service model lists httpBearerAuth (Bedrock API keys)
bool event_stream; // the success reply is application/vnd.amazon.eventstream
bool changes_state; // creates, stops or costs money: demo needs confirm
};
struct SchemaFields {
const char* schema;
const char* service; // which service model: bedrock, bedrock-runtime, bedrock-agent-runtime
const char* fields; // comma list of members we read, dotted for nested ("usage.inputTokens")
};
using PathArgs = std::map<std::string, std::string>;
using QueryArgs = std::map<std::string, std::string>;
struct Calls {
static const CallSpec& spec_of(Call call);
static clients::Method method_of(Call call);
static std::size_t count();
static const CallSpec& at(std::size_t index);
static std::size_t schema_count();
static const SchemaFields& schema_at(std::size_t index);
// The URI with every {placeholder} replaced by the percent-encoded value;
// throws ApiError::invalid for a missing, empty, over-long or odd value.
static std::string render(Call call, const PathArgs& args);
// Allowed characters of an id placed in a path: [A-Za-z0-9._:/-], no "..".
static bool valid_path_value(const std::string& value);
};
} // namespace molo::bedrock