feat(clients): meta: Meta Model API module, Muse Code protocol client, demo and tests
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
#pragma once
|
||||
|
||||
// POST /responses and its lifecycle calls (retrieve, delete, cancel, count
|
||||
// input tokens). The Responses API is the endpoint that carries reasoning
|
||||
// across turns (stateless encrypted replay or previous_response_id), serves
|
||||
// tools, search grounding, files, SAM and Muse Image, and runs background
|
||||
// responses.
|
||||
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
#include "llm/api_client.h"
|
||||
#include "meta/calls.h"
|
||||
#include "meta/response_events.h"
|
||||
#include "meta/response_request.h"
|
||||
#include "meta/usage.h"
|
||||
|
||||
namespace molo::meta {
|
||||
|
||||
struct ResponseResult {
|
||||
Json body;
|
||||
RateLimits limits; // x-ratelimit-* headers when the server sent them
|
||||
std::string id() const { return JsonX::str(body, "id"); }
|
||||
std::string status() const { return JsonX::str(body, "status"); }
|
||||
// Concatenated output_text of every assistant message item.
|
||||
std::string output_text() const;
|
||||
MetaUsage usage() const;
|
||||
};
|
||||
|
||||
class ResponsesService : public llm::Service {
|
||||
public:
|
||||
using EventSink = std::function<bool(const ResponseEvent&)>; // false: stop
|
||||
|
||||
explicit ResponsesService(std::shared_ptr<llm::ApiClient> client)
|
||||
: llm::Service(std::move(client)) {}
|
||||
|
||||
ResponseResult create(const ResponseRequest& request);
|
||||
// Streams events; returns the folded accumulator. A stream that ends before a
|
||||
// terminal event leaves completed()/failed() false (the caller decides).
|
||||
ResponseAccumulator stream(const ResponseRequest& request, const EventSink& sink = nullptr);
|
||||
|
||||
ResponseResult retrieve(const std::string& response_id);
|
||||
// Streaming retrieval of a background response (lifecycle events only). The
|
||||
// client has no GET-SSE transport, so the body is read whole, then decoded.
|
||||
ResponseAccumulator retrieve_stream(const std::string& response_id, long starting_after = -1,
|
||||
const EventSink& sink = nullptr);
|
||||
// Destructive: soft-deletes the stored response. No default, no retry.
|
||||
Json remove(const std::string& response_id);
|
||||
// Cancels a background response; a finished response comes back unchanged.
|
||||
Json cancel(const std::string& response_id);
|
||||
// Tokenizes only: no generation, no storage, no usage record.
|
||||
long count_input_tokens(const ResponseRequest& request);
|
||||
};
|
||||
|
||||
} // namespace molo::meta
|
||||
Reference in New Issue
Block a user