Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 32 additions & 21 deletions xllm/api_service/api_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,11 @@ void APIService::CompletionsHttp(::google::protobuf::RpcController* controller,
google::protobuf::Arena::CreateMessage<proto::CompletionResponse>(arena);

auto ctrl = reinterpret_cast<brpc::Controller*>(controller);
std::string attachment = std::move(ctrl->request_attachment().to_string());
std::string error;
auto st = json2pb::JsonToProtoMessage(attachment, req_pb, &error);
json2pb::Json2PbOptions options;
butil::IOBuf& buf = ctrl->request_attachment();
butil::IOBufAsZeroCopyInputStream iobuf_stream(buf);
auto st = json2pb::JsonToProtoMessage(&iobuf_stream, req_pb, options, &error);
if (!st) {
ctrl->SetFailed(error);
LOG(ERROR) << "parse json to proto failed: " << error;
Expand Down Expand Up @@ -127,16 +129,14 @@ void ChatCompletionsImpl(std::unique_ptr<Service>& service,
auto resp_pb =
google::protobuf::Arena::CreateMessage<typename ChatCall::ResType>(arena);

std::string attachment = std::move(ctrl->request_attachment().to_string());
std::string error;

google::protobuf::util::JsonParseOptions options;
options.ignore_unknown_fields = true;
auto json_status =
google::protobuf::util::JsonStringToMessage(attachment, req_pb, options);
if (!json_status.ok()) {
ctrl->SetFailed(json_status.ToString());
LOG(ERROR) << "parse json to proto failed: " << json_status.ToString();
json2pb::Json2PbOptions options;
butil::IOBuf& buf = ctrl->request_attachment();
butil::IOBufAsZeroCopyInputStream iobuf_stream(buf);
auto st = json2pb::JsonToProtoMessage(&iobuf_stream, req_pb, options, &error);
if (!st) {
ctrl->SetFailed(error);
LOG(ERROR) << "parse json to proto failed: " << buf.to_string();
return;
}

Expand Down Expand Up @@ -201,9 +201,11 @@ void APIService::EmbeddingsHttp(::google::protobuf::RpcController* controller,
google::protobuf::Arena::CreateMessage<proto::EmbeddingResponse>(arena);

auto ctrl = reinterpret_cast<brpc::Controller*>(controller);
std::string attachment = std::move(ctrl->request_attachment().to_string());
std::string error;
auto st = json2pb::JsonToProtoMessage(attachment, req_pb, &error);
json2pb::Json2PbOptions options;
butil::IOBuf& buf = ctrl->request_attachment();
butil::IOBufAsZeroCopyInputStream iobuf_stream(buf);
auto st = json2pb::JsonToProtoMessage(&iobuf_stream, req_pb, options, &error);
if (!st) {
ctrl->SetFailed(error);
LOG(ERROR) << "parse json to proto failed: " << error;
Expand Down Expand Up @@ -248,10 +250,13 @@ void APIService::ImageGenerationHttp(
auto resp_pb =
google::protobuf::Arena::CreateMessage<proto::ImageGenerationResponse>(
arena);

auto ctrl = reinterpret_cast<brpc::Controller*>(controller);
std::string attachment = std::move(ctrl->request_attachment().to_string());
std::string error;
auto st = json2pb::JsonToProtoMessage(attachment, req_pb, &error);
json2pb::Json2PbOptions options;
butil::IOBuf& buf = ctrl->request_attachment();
butil::IOBufAsZeroCopyInputStream iobuf_stream(buf);
auto st = json2pb::JsonToProtoMessage(&iobuf_stream, req_pb, options, &error);
if (!st) {
ctrl->SetFailed(error);
LOG(ERROR) << "parse json to proto failed: " << error;
Expand Down Expand Up @@ -290,9 +295,11 @@ void APIService::RerankHttp(::google::protobuf::RpcController* controller,
google::protobuf::Arena::CreateMessage<proto::RerankResponse>(arena);

auto ctrl = reinterpret_cast<brpc::Controller*>(controller);
std::string attachment = std::move(ctrl->request_attachment().to_string());
std::string error;
auto st = json2pb::JsonToProtoMessage(attachment, req_pb, &error);
json2pb::Json2PbOptions options;
butil::IOBuf& buf = ctrl->request_attachment();
butil::IOBufAsZeroCopyInputStream iobuf_stream(buf);
auto st = json2pb::JsonToProtoMessage(&iobuf_stream, req_pb, options, &error);
if (!st) {
ctrl->SetFailed(error);
LOG(ERROR) << "parse json to proto failed: " << error;
Expand Down Expand Up @@ -398,9 +405,11 @@ void APIService::LinkCluster(::google::protobuf::RpcController* controller,
google::protobuf::Arena::CreateMessage<proto::RpcStatus>(arena);

auto ctrl = reinterpret_cast<brpc::Controller*>(controller);
std::string attachment = std::move(ctrl->request_attachment().to_string());
std::string error;
auto st = json2pb::JsonToProtoMessage(attachment, req_pb, &error);
json2pb::Json2PbOptions options;
butil::IOBuf& buf = ctrl->request_attachment();
butil::IOBufAsZeroCopyInputStream iobuf_stream(buf);
auto st = json2pb::JsonToProtoMessage(&iobuf_stream, req_pb, options, &error);
if (!st) {
ctrl->SetFailed(error);
LOG(ERROR) << "parse json to proto failed: " << error;
Expand Down Expand Up @@ -452,9 +461,11 @@ void APIService::UnlinkCluster(::google::protobuf::RpcController* controller,
google::protobuf::Arena::CreateMessage<proto::RpcStatus>(arena);

auto ctrl = reinterpret_cast<brpc::Controller*>(controller);
std::string attachment = std::move(ctrl->request_attachment().to_string());
std::string error;
auto st = json2pb::JsonToProtoMessage(attachment, req_pb, &error);
json2pb::Json2PbOptions options;
butil::IOBuf& buf = ctrl->request_attachment();
butil::IOBufAsZeroCopyInputStream iobuf_stream(buf);
auto st = json2pb::JsonToProtoMessage(&iobuf_stream, req_pb, options, &error);
if (!st) {
ctrl->SetFailed(error);
LOG(ERROR) << "parse json to proto failed: " << error;
Expand Down