feat(clients): huggingface: Hub, Inference Providers, Endpoints, TGI, TEI, chat model, demo

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-25 15:01:40 +01:00
co-authored by Claude Sonnet 5.5
parent 3db67fcf1f
commit 0b806eb7e3
36 changed files with 5949 additions and 3 deletions
+197
View File
@@ -0,0 +1,197 @@
#include "vendors/huggingface/calls.h"
#include <cstring>
#include "llm/error.h"
namespace molo::huggingface {
const char* surface_name(Surface surface) {
switch (surface) {
case Surface::kHub: return "hub";
case Surface::kRouter: return "router";
case Surface::kEndpoints: return "endpoints";
case Surface::kTgi: return "tgi";
case Surface::kTei: return "tei";
}
return "?";
}
// CALLS-BEGIN (parsed by tools/check_spec.py; one row per line, strings in order:
// http method, path, spec, ref, auth, flags, body fields, query params)
static const CallSpec kCalls[] = {
{Call::kWhoami, Surface::kHub, "GET", "/api/whoami-v2", "hub", "-", "token", "", "", ""},
{Call::kModelsTagsByType, Surface::kHub, "GET", "/api/models-tags-by-type", "hub", "-", "optional", "", "", "type"},
{Call::kDatasetsTagsByType, Surface::kHub, "GET", "/api/datasets-tags-by-type", "hub", "-", "optional", "", "", "type"},
{Call::kTrending, Surface::kHub, "GET", "/api/trending", "hub", "-", "optional", "", "", "limit,type"},
{Call::kQuicksearch, Surface::kHub, "GET", "/api/quicksearch", "hub", "-", "optional", "", "", "discussionCollectionName,discussionId,exclude,includeInvitees,lang,library,limit,namespace,orgsFilter,pipelines,q,repoName,repoType,reposFilter,spacesTags,type"},
{Call::kFullTextSearch, Surface::kHub, "GET", "/api/search/full-text", "hub", "-", "optional", "", "", "filter,limit,q,skip,type"},
{Call::kRepoLikers, Surface::kHub, "GET", "/api/{repoType}/{namespace}/{repo}/likers", "hub", "-", "optional", "", "", "expand"},
{Call::kRepoTree, Surface::kHub, "GET", "/api/{repoType}/{namespace}/{repo}/tree/{rev}/{path}", "hub", "-", "optional", "optpath", "", "cursor,expand,limit,recursive"},
{Call::kRepoTreeSize, Surface::kHub, "GET", "/api/{repoType}/{namespace}/{repo}/treesize/{rev}/{path}", "hub", "-", "optional", "optpath", "", ""},
{Call::kRepoRefs, Surface::kHub, "GET", "/api/{repoType}/{namespace}/{repo}/refs", "hub", "-", "optional", "", "", "include_prs"},
{Call::kRepoCommits, Surface::kHub, "GET", "/api/{repoType}/{namespace}/{repo}/commits/{rev}", "hub", "-", "optional", "", "", "expand,limit,p"},
{Call::kRepoCompare, Surface::kHub, "GET", "/api/{repoType}/{namespace}/{repo}/compare/{compare}", "hub", "-", "optional", "", "", "raw"},
{Call::kRepoPathsInfo, Surface::kHub, "POST", "/api/{repoType}/{namespace}/{repo}/paths-info/{rev}", "hub", "-", "optional", "", "expand,paths", ""},
{Call::kModelSafetensors, Surface::kHub, "GET", "/api/models/{namespace}/{repo}/safetensors-metadata/{path}", "hub", "-", "optional", "", "", ""},
{Call::kFileResolve, Surface::kHub, "GET", "{typePrefix}/{namespace}/{repo}/resolve/{rev}/{path}", "hub", "-", "optional", "raw", "", ""},
{Call::kDiscussionList, Surface::kHub, "GET", "/api/{repoType}/{namespace}/{repo}/discussions", "hub", "-", "optional", "", "", "author,p,search,sort,status,type"},
{Call::kDiscussionCreate, Surface::kHub, "POST", "/api/{repoType}/{namespace}/{repo}/discussions", "hub", "-", "token", "write", "description,pullRequest,title", ""},
{Call::kDiscussionGet, Surface::kHub, "GET", "/api/{repoType}/{namespace}/{repo}/discussions/{num}", "hub", "-", "optional", "", "", ""},
{Call::kDiscussionDelete, Surface::kHub, "DELETE", "/api/{repoType}/{namespace}/{repo}/discussions/{num}", "hub", "-", "token", "write,destructive", "", ""},
{Call::kDiscussionComment, Surface::kHub, "POST", "/api/{repoType}/{namespace}/{repo}/discussions/{num}/comment", "hub", "-", "token", "write", "comment", ""},
{Call::kDiscussionStatus, Surface::kHub, "POST", "/api/{repoType}/{namespace}/{repo}/discussions/{num}/status", "hub", "-", "token", "write", "comment,status", ""},
{Call::kDiscussionTitle, Surface::kHub, "POST", "/api/{repoType}/{namespace}/{repo}/discussions/{num}/title", "hub", "-", "token", "write", "title", ""},
{Call::kCollectionsList, Surface::kHub, "GET", "/api/collections", "hub", "-", "optional", "", "", "cursor,expand,item,limit,owner,q,sort"},
{Call::kCollectionGet, Surface::kHub, "GET", "/api/collections/{namespace}/{slug}", "hub", "-", "optional", "", "", ""},
{Call::kCollectionCreate, Surface::kHub, "POST", "/api/collections", "hub", "-", "token", "write", "description,item,namespace,private,resourceGroupId,title", ""},
{Call::kCollectionUpdate, Surface::kHub, "PATCH", "/api/collections/{namespace}/{slug}", "hub", "-", "token", "write", "description,gating,position,private,theme,title", ""},
{Call::kCollectionDelete, Surface::kHub, "DELETE", "/api/collections/{namespace}/{slug}", "hub", "-", "token", "write,destructive", "", ""},
{Call::kCollectionAddItem, Surface::kHub, "POST", "/api/collections/{namespace}/{slug}/items", "hub", "-", "token", "write", "item,note", ""},
{Call::kWebhooksList, Surface::kHub, "GET", "/api/settings/webhooks", "hub", "-", "token", "", "", ""},
{Call::kWebhookCreate, Surface::kHub, "POST", "/api/settings/webhooks", "hub", "-", "token", "write", "domains,job,jobSourceId,secret,secrets,url,watched", ""},
{Call::kWebhookGet, Surface::kHub, "GET", "/api/settings/webhooks/{webhookId}", "hub", "-", "token", "", "", ""},
{Call::kWebhookUpdate, Surface::kHub, "POST", "/api/settings/webhooks/{webhookId}", "hub", "-", "token", "write", "domains,job,jobSourceId,secret,secrets,url,watched", ""},
{Call::kWebhookDelete, Surface::kHub, "DELETE", "/api/settings/webhooks/{webhookId}", "hub", "-", "token", "write,destructive", "", ""},
{Call::kWebhookToggle, Surface::kHub, "POST", "/api/settings/webhooks/{webhookId}/{action}", "hub", "-", "token", "write", "", ""},
{Call::kWebhookReplay, Surface::kHub, "POST", "/api/settings/webhooks/{webhookId}/replay/{logId}", "hub", "-", "token", "write", "", ""},
{Call::kDailyPapers, Surface::kHub, "GET", "/api/daily_papers", "hub", "-", "optional", "", "", "date,limit,month,p,sort,submitter,week"},
{Call::kPapersList, Surface::kHub, "GET", "/api/papers", "hub", "-", "optional", "", "", "cursor,limit"},
{Call::kPapersSearch, Surface::kHub, "GET", "/api/papers/search", "hub", "-", "optional", "", "", "limit,q"},
{Call::kPaperGet, Surface::kHub, "GET", "/api/papers/{paperId}", "hub", "-", "optional", "", "", "field"},
{Call::kSpacesHardware, Surface::kHub, "GET", "/api/spaces/hardware", "hub", "-", "optional", "", "", ""},
{Call::kSpacesTemplates, Surface::kHub, "GET", "/api/spaces/templates", "hub", "-", "optional", "", "", ""},
{Call::kSpacesSemanticSearch, Surface::kHub, "GET", "/api/spaces/semantic-search", "hub", "-", "optional", "", "", "agents,category,filter,includeNonRunning,q,sdk"},
{Call::kSpacesFeatured, Surface::kHub, "GET", "/api/spaces/featured", "hub", "-", "optional", "", "", "date"},
{Call::kPartnerModels, Surface::kHub, "GET", "/api/partners/{provider}/models", "hub", "-", "optional", "", "", "status"},
{Call::kModelsList, Surface::kHub, "GET", "/api/models", "src", "{self.endpoint}/api/models\"", "optional", "", "", "filter,author,apps,gated,inference,inference_provider,pipeline_tag,num_parameters,search,sort,limit,full,config,cardData,expand,cursor,direction"},
{Call::kDatasetsList, Surface::kHub, "GET", "/api/datasets", "src", "{self.endpoint}/api/datasets\"", "optional", "", "", "filter,author,gated,search,sort,limit,full,expand,cursor,direction"},
{Call::kSpacesList, Surface::kHub, "GET", "/api/spaces", "src", "{self.endpoint}/api/spaces\"", "optional", "", "", "filter,author,search,sort,limit,full,expand,cursor,direction,datasets,models,linked"},
{Call::kModelInfo, Surface::kHub, "GET", "/api/models/{namespace}/{repo}", "src", "/api/models/{repo_id}\"", "optional", "", "", "securityStatus,blobs,expand"},
{Call::kModelRevision, Surface::kHub, "GET", "/api/models/{namespace}/{repo}/revision/{rev}", "src", "/api/models/{repo_id}/revision/", "optional", "", "", "securityStatus,blobs,expand"},
{Call::kDatasetInfo, Surface::kHub, "GET", "/api/datasets/{namespace}/{repo}", "src", "/api/datasets/{repo_id}\"", "optional", "", "", "blobs,expand"},
{Call::kDatasetRevision, Surface::kHub, "GET", "/api/datasets/{namespace}/{repo}/revision/{rev}", "src", "/api/datasets/{repo_id}/revision/", "optional", "", "", "blobs,expand"},
{Call::kSpaceInfo, Surface::kHub, "GET", "/api/spaces/{namespace}/{repo}", "src", "/api/spaces/{repo_id}\"", "optional", "", "", "expand"},
{Call::kSpaceRevision, Surface::kHub, "GET", "/api/spaces/{namespace}/{repo}/revision/{rev}", "src", "/api/spaces/{repo_id}/revision/", "optional", "", "", "expand"},
{Call::kSpaceRuntime, Surface::kHub, "GET", "/api/spaces/{namespace}/{repo}/runtime", "src", "/api/spaces/{repo_id}/runtime", "token", "", "", ""},
{Call::kTasks, Surface::kHub, "GET", "/api/tasks", "src", "{constants.ENDPOINT}/api/tasks", "optional", "", "", ""},
{Call::kRouterChat, Surface::kRouter, "POST", "/v1/chat/completions", "task", "chat-completion", "token", "", "frequency_penalty,logit_bias,logprobs,max_tokens,messages,model,n,presence_penalty,reasoning_effort,response_format,seed,stop,stream,stream_options,temperature,tool_choice,tool_prompt,tools,top_logprobs,top_p", ""},
{Call::kRouterModels, Surface::kRouter, "GET", "/v1/models", "none", "probe", "none", "", "", ""},
{Call::kHfInferenceTask, Surface::kRouter, "POST", "/hf-inference/models/{model}", "src", "models/{mapped_model}", "token", "", "inputs,parameters,stream", ""},
{Call::kHfInferencePipeline, Surface::kRouter, "POST", "/hf-inference/models/{model}/pipeline/{task}", "src", "pipeline/{self.task}", "token", "", "inputs,parameters,normalize,prompt_name,truncate,truncation_direction", ""},
{Call::kHfInferenceChat, Surface::kRouter, "POST", "/hf-inference/models/{model}/v1/chat/completions", "src", "\"/v1/chat/completions\"", "token", "", "frequency_penalty,logit_bias,logprobs,max_tokens,messages,model,n,presence_penalty,reasoning_effort,response_format,seed,stop,stream,stream_options,temperature,tool_choice,tool_prompt,tools,top_logprobs,top_p", ""},
{Call::kIeGetAuditLogs, Surface::kEndpoints, "GET", "/v2/audit-logs/{namespace}", "ie", "get_audit_logs", "token", "", "", "cursor,endpoint,limit,username"},
{Call::kIeListEndpoint, Surface::kEndpoints, "GET", "/v2/endpoint/{namespace}", "ie", "list_endpoint", "token", "", "", "cursor,direction,engine,instanceSize,instanceType,limit,search,sortBy,state,tags,task,type"},
{Call::kIeCreateEndpoint, Surface::kEndpoints, "POST", "/v2/endpoint/{namespace}", "ie", "create_endpoint", "token", "write", "cacheHttpResponses,compute,customRouter,experimentalFeatures,model,name,network,notifications,privateService,provider,route,tags,type", ""},
{Call::kIeGetEndpoint, Surface::kEndpoints, "GET", "/v2/endpoint/{namespace}/{name}", "ie", "get_endpoint", "token", "", "", ""},
{Call::kIeUpdateEndpoint, Surface::kEndpoints, "PUT", "/v2/endpoint/{namespace}/{name}", "ie", "update_endpoint", "token", "write", "compute,customRouter,experimentalFeatures,model,network,notifications,provider,route,tags,type", ""},
{Call::kIeDeleteEndpoint, Surface::kEndpoints, "DELETE", "/v2/endpoint/{namespace}/{name}", "ie", "delete_endpoint", "token", "write,destructive", "", ""},
{Call::kIeDebugAgent, Surface::kEndpoints, "POST", "/v2/endpoint/{namespace}/{name}/agent/debug", "ie", "debug_agent", "token", "write", "", ""},
{Call::kIeGetEndpointLogs, Surface::kEndpoints, "GET", "/v2/endpoint/{namespace}/{name}/logs", "ie", "get_endpoint_logs", "token", "raw", "", "follow,line_max_length,replica,tail"},
{Call::kIeGetEndpointLogsSse, Surface::kEndpoints, "GET", "/v2/endpoint/{namespace}/{name}/logs/sse", "ie", "get_endpoint_logs_sse", "token", "unsupported", "", "line_max_length,replica,tail"},
{Call::kIeGetEndpointMetrics, Surface::kEndpoints, "POST", "/v2/endpoint/{namespace}/{name}/metrics", "ie", "get_endpoint_metrics", "token", "", "replicaId,start,stop", ""},
{Call::kIeGetHardwareCpu, Surface::kEndpoints, "POST", "/v2/endpoint/{namespace}/{name}/metrics/hardware-cpu", "ie", "get_hardware_cpu", "token", "", "replicaId,start,stop", ""},
{Call::kIeGetHardwareGpu, Surface::kEndpoints, "POST", "/v2/endpoint/{namespace}/{name}/metrics/hardware-gpu", "ie", "get_hardware_gpu", "token", "", "replicaId,start,stop", ""},
{Call::kIeGetInferenceItl, Surface::kEndpoints, "POST", "/v2/endpoint/{namespace}/{name}/metrics/inference/itl", "ie", "get_inference_itl", "token", "", "replicaId,start,stop", ""},
{Call::kIeGetInferenceKvCache, Surface::kEndpoints, "POST", "/v2/endpoint/{namespace}/{name}/metrics/inference/kv-cache", "ie", "get_inference_kv_cache", "token", "", "replicaId,start,stop", ""},
{Call::kIeGetInferencePrefixCache, Surface::kEndpoints, "POST", "/v2/endpoint/{namespace}/{name}/metrics/inference/prefix-cache", "ie", "get_inference_prefix_cache", "token", "", "replicaId,start,stop", ""},
{Call::kIeGetInferenceRequests, Surface::kEndpoints, "POST", "/v2/endpoint/{namespace}/{name}/metrics/inference/requests", "ie", "get_inference_requests", "token", "", "replicaId,start,stop", ""},
{Call::kIeGetInferenceTtft, Surface::kEndpoints, "POST", "/v2/endpoint/{namespace}/{name}/metrics/inference/ttft", "ie", "get_inference_ttft", "token", "", "replicaId,start,stop", ""},
{Call::kIeGetPendingRequest, Surface::kEndpoints, "POST", "/v2/endpoint/{namespace}/{name}/metrics/pending-request", "ie", "get_pending_request", "token", "", "replicaId,start,stop", ""},
{Call::kIeGetReplicaIds, Surface::kEndpoints, "POST", "/v2/endpoint/{namespace}/{name}/metrics/replica-ids", "ie", "get_replica_ids", "token", "", "replicaId,start,stop", ""},
{Call::kIeGetReplicaRunning, Surface::kEndpoints, "POST", "/v2/endpoint/{namespace}/{name}/metrics/replica-running", "ie", "get_replica_running", "token", "", "replicaId,start,stop", ""},
{Call::kIeGetReplicaStatus, Surface::kEndpoints, "POST", "/v2/endpoint/{namespace}/{name}/metrics/replica-status", "ie", "get_replica_status", "token", "", "replicaId,start,stop", ""},
{Call::kIeGetResponseElapsed, Surface::kEndpoints, "POST", "/v2/endpoint/{namespace}/{name}/metrics/response-elapsed", "ie", "get_response_elapsed", "token", "", "replicaId,start,stop", ""},
{Call::kIeGetResponseStatusCode, Surface::kEndpoints, "POST", "/v2/endpoint/{namespace}/{name}/metrics/response-status-code", "ie", "get_response_status_code", "token", "", "replicaId,start,stop", ""},
{Call::kIeGetStatusCodeGrouped, Surface::kEndpoints, "POST", "/v2/endpoint/{namespace}/{name}/metrics/response-status-code-grouped", "ie", "get_status_code_grouped", "token", "", "replicaId,start,stop", ""},
{Call::kIeGetEndpointOpenMetrics, Surface::kEndpoints, "GET", "/v2/endpoint/{namespace}/{name}/open-metrics", "ie", "get_endpoint_open_metrics", "token", "raw", "", ""},
{Call::kIePauseEndpoint, Surface::kEndpoints, "POST", "/v2/endpoint/{namespace}/{name}/pause", "ie", "pause_endpoint", "token", "write,destructive", "", ""},
{Call::kIeGetEndpointReplica, Surface::kEndpoints, "GET", "/v2/endpoint/{namespace}/{name}/replica", "ie", "get_endpoint_replica", "token", "", "", ""},
{Call::kIeResumeEndpoint, Surface::kEndpoints, "POST", "/v2/endpoint/{namespace}/{name}/resume", "ie", "resume_endpoint", "token", "write", "", ""},
{Call::kIeScaleToZeroEndpoint, Surface::kEndpoints, "POST", "/v2/endpoint/{namespace}/{name}/scale-to-zero", "ie", "scale_to_zero_endpoint", "token", "write,destructive", "", ""},
{Call::kIeGetEndpointSse, Surface::kEndpoints, "GET", "/v2/endpoint/{namespace}/{name}/sse", "ie", "get_endpoint_sse", "token", "unsupported", "", ""},
{Call::kIeListCidrsList, Surface::kEndpoints, "GET", "/v2/network/cidr-list/{namespace}", "ie", "list_cidrs_list", "token", "", "", ""},
{Call::kIeCreateCidrList, Surface::kEndpoints, "POST", "/v2/network/cidr-list/{namespace}", "ie", "create_cidr_list", "token", "write", "cidrList,id,name", ""},
{Call::kIeUpdateCidrList, Surface::kEndpoints, "POST", "/v2/network/cidr-list/{namespace}/{cidr_id}", "ie", "update_cidr_list", "token", "write", "cidrList,id,name", ""},
{Call::kIeDeleteCidrList, Surface::kEndpoints, "DELETE", "/v2/network/cidr-list/{namespace}/{cidr_id}", "ie", "delete_cidr_list", "token", "write,destructive", "", ""},
{Call::kIeListDomains, Surface::kEndpoints, "GET", "/v2/network/domain/{namespace}", "ie", "list_domains", "token", "", "", ""},
{Call::kIeCreateDomain, Surface::kEndpoints, "POST", "/v2/network/domain/{namespace}", "ie", "create_domain", "token", "write", "domain", ""},
{Call::kIeDeleteDomain, Surface::kEndpoints, "DELETE", "/v2/network/domain/{namespace}/{domain}", "ie", "delete_domain", "token", "write,destructive", "", ""},
{Call::kIeListPrivateServices, Surface::kEndpoints, "GET", "/v2/network/private-service/{namespace}", "ie", "list_private_services", "token", "", "", "account-id,shared"},
{Call::kIeDeletePrivateService, Surface::kEndpoints, "DELETE", "/v2/network/private-service/{namespace}/{service-id}", "ie", "delete_private_service", "token", "write,destructive", "", ""},
{Call::kIeListVendors, Surface::kEndpoints, "GET", "/v2/provider", "ie", "list_vendors", "none", "", "", ""},
{Call::kIeListVendorsQuotasNamespace, Surface::kEndpoints, "GET", "/v2/provider/quotas/{namespace}", "ie", "list_vendors_quotas_namespace", "token", "", "", ""},
{Call::kIeListVendorsNamespace, Surface::kEndpoints, "GET", "/v2/provider/{namespace}", "ie", "list_vendors_namespace", "token", "", "", ""},
{Call::kIeSearchEndpoint, Surface::kEndpoints, "GET", "/v2/search/{namespace}", "ie", "search_endpoint", "token", "", "", "limit,search,tags"},
{Call::kIeCountEndpointStates, Surface::kEndpoints, "GET", "/v2/search/{namespace}/states", "ie", "count_endpoint_states", "token", "", "", ""},
{Call::kIeListEndpointTags, Surface::kEndpoints, "GET", "/v2/search/{namespace}/tags", "ie", "list_endpoint_tags", "token", "", "", "limit,prefix"},
{Call::kIeGetEndpointLogsV3, Surface::kEndpoints, "GET", "/v3/endpoint/{namespace}/{name}/logs", "ie", "get_endpoint_logs_v3", "token", "", "", "after,before,level,limit,line_max_length,order,replica,search,since,until"},
{Call::kIeDownloadEndpointLogsV3, Surface::kEndpoints, "GET", "/v3/endpoint/{namespace}/{name}/logs/download", "ie", "download_endpoint_logs_v3", "token", "raw", "", "level,line_max_length,replica,search,since,until"},
{Call::kIeGetEndpointLogsSseV3, Surface::kEndpoints, "GET", "/v3/endpoint/{namespace}/{name}/logs/sse", "ie", "get_endpoint_logs_sse_v3", "token", "unsupported", "", "after,level,line_max_length,replica,search,since,tail"},
{Call::kTgiCompatGenerate, Surface::kTgi, "POST", "/", "tgi", "compat_generate", "optional", "", "inputs,parameters,stream", ""},
{Call::kTgiGetChatTokenize, Surface::kTgi, "POST", "/chat_tokenize", "tgi", "get_chat_tokenize", "optional", "", "frequency_penalty,logit_bias,logprobs,max_tokens,messages,model,n,presence_penalty,response_format,seed,stop,stream,stream_options,temperature,tool_choice,tool_prompt,tools,top_logprobs,top_p", ""},
{Call::kTgiGenerate, Surface::kTgi, "POST", "/generate", "tgi", "generate", "optional", "", "inputs,parameters", ""},
{Call::kTgiGenerateStream, Surface::kTgi, "POST", "/generate_stream", "tgi", "generate_stream", "optional", "stream", "inputs,parameters", ""},
{Call::kTgiHealth, Surface::kTgi, "GET", "/health", "tgi", "health", "optional", "", "", ""},
{Call::kTgiGetModelInfo, Surface::kTgi, "GET", "/info", "tgi", "get_model_info", "optional", "", "", ""},
{Call::kTgiSagemakerCompatibility, Surface::kTgi, "POST", "/invocations", "tgi", "sagemaker_compatibility", "optional", "", "frequency_penalty,inputs,logit_bias,logprobs,max_tokens,messages,model,n,parameters,presence_penalty,prompt,repetition_penalty,response_format,seed,stop,stream,stream_options,suffix,temperature,tool_choice,tool_prompt,tools,top_logprobs,top_p", ""},
{Call::kTgiMetrics, Surface::kTgi, "GET", "/metrics", "tgi", "metrics", "optional", "raw", "", ""},
{Call::kTgiTokenize, Surface::kTgi, "POST", "/tokenize", "tgi", "tokenize", "optional", "", "inputs,parameters", ""},
{Call::kTgiChatCompletions, Surface::kTgi, "POST", "/v1/chat/completions", "tgi", "chat_completions", "optional", "", "frequency_penalty,logit_bias,logprobs,max_tokens,messages,model,n,presence_penalty,response_format,seed,stop,stream,stream_options,temperature,tool_choice,tool_prompt,tools,top_logprobs,top_p", ""},
{Call::kTgiCompletions, Surface::kTgi, "POST", "/v1/completions", "tgi", "completions", "optional", "", "frequency_penalty,max_tokens,model,prompt,repetition_penalty,seed,stop,stream,suffix,temperature,top_p", ""},
{Call::kTgiOpenaiGetModelInfo, Surface::kTgi, "GET", "/v1/models", "tgi", "openai_get_model_info", "optional", "", "", ""},
{Call::kTeiDecode, Surface::kTei, "POST", "/decode", "tei", "decode", "optional", "", "ids,skip_special_tokens", ""},
{Call::kTeiEmbed, Surface::kTei, "POST", "/embed", "tei", "embed", "optional", "", "dimensions,inputs,normalize,prompt_name,truncate,truncation_direction", ""},
{Call::kTeiEmbedAll, Surface::kTei, "POST", "/embed_all", "tei", "embed_all", "optional", "", "inputs,prompt_name,truncate,truncation_direction", ""},
{Call::kTeiEmbedSparse, Surface::kTei, "POST", "/embed_sparse", "tei", "embed_sparse", "optional", "", "inputs,prompt_name,truncate,truncation_direction", ""},
{Call::kTeiHealth, Surface::kTei, "GET", "/health", "tei", "health", "optional", "", "", ""},
{Call::kTeiGetModelInfo, Surface::kTei, "GET", "/info", "tei", "get_model_info", "optional", "", "", ""},
{Call::kTeiMetrics, Surface::kTei, "GET", "/metrics", "tei", "metrics", "optional", "raw", "", ""},
{Call::kTeiPredict, Surface::kTei, "POST", "/predict", "tei", "predict", "optional", "", "inputs,raw_scores,truncate,truncation_direction", ""},
{Call::kTeiRerank, Surface::kTei, "POST", "/rerank", "tei", "rerank", "optional", "", "query,raw_scores,return_text,texts,truncate,truncation_direction", ""},
{Call::kTeiSimilarity, Surface::kTei, "POST", "/similarity", "tei", "similarity", "optional", "", "inputs,parameters", ""},
{Call::kTeiTokenize, Surface::kTei, "POST", "/tokenize", "tei", "tokenize", "optional", "", "add_special_tokens,inputs,prompt_name", ""},
{Call::kTeiOpenaiEmbed, Surface::kTei, "POST", "/v1/embeddings", "tei", "openai_embed", "optional", "", "dimensions,encoding_format,input,model,user", ""},
};
// CALLS-END
bool CallSpec::has_flag(const char* flag) const { return Calls::in_list(flags, flag); }
bool Calls::in_list(const char* list, const std::string& name) {
const std::size_t n = name.size();
const char* p = list;
while (*p) {
const char* end = std::strchr(p, ',');
std::size_t len = end ? static_cast<std::size_t>(end - p) : std::strlen(p);
if (len == n && std::strncmp(p, name.c_str(), n) == 0) return true;
if (!end) break;
p = end + 1;
}
return false;
}
std::size_t Calls::count() { return sizeof(kCalls) / sizeof(kCalls[0]); }
const CallSpec& Calls::at(std::size_t index) {
if (index >= count()) throw llm::ApiError::invalid("huggingface", "call index out of range");
return kCalls[index];
}
const CallSpec& Calls::spec_of(Call call) {
const std::size_t i = static_cast<std::size_t>(call);
if (i >= count() || kCalls[i].call != call)
throw llm::ApiError::invalid("huggingface", "call table out of order");
return kCalls[i];
}
clients::Method Calls::method_of(Call call) {
const char* m = spec_of(call).http_method;
if (!std::strcmp(m, "GET")) return clients::Method::kGet;
if (!std::strcmp(m, "POST")) return clients::Method::kPost;
if (!std::strcmp(m, "PUT")) return clients::Method::kPut;
if (!std::strcmp(m, "PATCH")) return clients::Method::kPatch;
if (!std::strcmp(m, "DELETE")) return clients::Method::kDelete;
throw llm::ApiError::invalid("huggingface", "unknown http method in the call table");
}
} // namespace molo::huggingface