feat(clients): llm vendor foundation: api client, SSE, errors, neutral chat types, ai.mk, example stubs
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
#pragma once
|
||||
|
||||
// One error type for every vendor call. Carries the HTTP status, the
|
||||
// vendor's own error type/code and message, and the request id when the
|
||||
// server sent one. Never the credential.
|
||||
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
#include "clients/response.h"
|
||||
|
||||
namespace molo::llm {
|
||||
|
||||
class ApiError : public std::runtime_error {
|
||||
public:
|
||||
ApiError(std::string vendor, int http_status, std::string type,
|
||||
const std::string& message, std::string request_id = "");
|
||||
|
||||
const std::string& vendor() const noexcept { return vendor_; }
|
||||
int http_status() const noexcept { return http_status_; }
|
||||
// Vendor error type or code ("authentication_error", "invalid_request_error",
|
||||
// "rate_limit_exceeded", ...), or a framework code (NOT_CONFIGURED, ...).
|
||||
const std::string& type() const noexcept { return type_; }
|
||||
const std::string& message() const noexcept { return message_; }
|
||||
const std::string& request_id() const noexcept { return request_id_; }
|
||||
|
||||
static ApiError invalid(const std::string& vendor, const std::string& message);
|
||||
|
||||
private:
|
||||
std::string vendor_;
|
||||
int http_status_;
|
||||
std::string type_;
|
||||
std::string message_;
|
||||
std::string request_id_;
|
||||
};
|
||||
|
||||
class NotConfiguredError : public ApiError {
|
||||
public:
|
||||
NotConfiguredError(const std::string& vendor, const std::string& env_var);
|
||||
};
|
||||
|
||||
// Parses the common error envelopes: {"error":{"type"|"code","message"}},
|
||||
// {"type":"error","error":{...}}, {"error":"text"}, {"message":"text"}.
|
||||
ApiError error_from_response(const std::string& vendor,
|
||||
const clients::ClientResponse& response);
|
||||
|
||||
} // namespace molo::llm
|
||||
Reference in New Issue
Block a user