Files
moloapp/src/vendors/compat/registry.h
T

73 lines
3.2 KiB
C++

#pragma once
// The ONE provider table of this module. Adding a provider is one row in
// registry.cpp (plus its line in SPEC.md section 4, which tools/check_spec.py
// enforces). Everything else (clients, routes, demo, tests) iterates this
// table.
#include <cstddef>
#include <string>
namespace molo::compat {
// Endpoints a row claims. Claims come from the provider's own docs or a
// probe; SPEC.md says which. A call outside the mask is refused before any
// network traffic.
struct Feature {
static constexpr unsigned kChat = 1u << 0;
static constexpr unsigned kEmbeddings = 1u << 1;
static constexpr unsigned kModels = 1u << 2;
static constexpr unsigned kImages = 1u << 3;
static constexpr unsigned kTranscribe = 1u << 4;
static constexpr unsigned kSpeech = 1u << 5;
};
// Documented behavior that differs from OpenAI and that the module enforces
// loudly (reject) instead of letting the provider answer 400.
struct Quirk {
static constexpr unsigned kNone = 0;
static constexpr unsigned kRejectMessageName = 1u << 0; // messages[].name answers 400
static constexpr unsigned kRejectLogprobs = 1u << 1; // logprobs, top_logprobs, logit_bias answer 400
static constexpr unsigned kSingleChoice = 1u << 2; // n must be 1
static constexpr unsigned kNoToolsWithFormat = 1u << 3; // tools + response_format not combinable
};
// How the row was verified (see SPEC.md section 5).
enum class Evidence {
kDocsAndProbe, // docs text names the base URL; unauthenticated probe answered like an API
kProbeOnly, // docs text did not name it (or not readable); probe answered like an API
kDocsOnly, // docs name it; not probeable (local server, or needs an account id)
};
struct ProviderRow {
const char* id; // slug, [a-z0-9]+, used in routes and ids
const char* name; // display name
const char* base_url; // no trailing slash; "{account_id}" is replaced from extra_env
const char* key_env; // credential env var (via llm::Config); local rows: optional key
const char* base_env; // env var overriding base_url; for local rows also the "configured" switch
const char* extra_env; // second required env var (account id) or ""
const char* models_path; // "" when the row has no list endpoint
unsigned features; // Feature mask
unsigned quirks; // Quirk mask
Evidence evidence;
bool local; // self-hosted server, no vendor credential
const char* doc_url; // documentation page cited for the base URL
const char* note; // documented quirks and probe results, one line
};
class Registry {
public:
static std::size_t count();
static const ProviderRow& at(std::size_t index);
// nullptr when unknown.
static const ProviderRow* find(const std::string& id);
// Throws llm::ApiError::invalid for an unknown id.
static const ProviderRow& get(const std::string& id);
static bool has(const ProviderRow& row, unsigned feature) { return (row.features & feature) != 0; }
static const char* evidence_name(Evidence e);
// Comma list of the feature names a row claims ("chat,embeddings,models").
static std::string feature_names(const ProviderRow& row);
};
} // namespace molo::compat