Skip to content

Commit cbe4fab

Browse files
committed
Create rapidjson utils
1 parent 84ac218 commit cbe4fab

File tree

6 files changed

+88
-16
lines changed

6 files changed

+88
-16
lines changed

src/BUILD

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ COPTS_OV_TRACE = select({
2323
"//conditions:default": ["-DOV_TRACE=0"],
2424
"//:not_disable_ov_trace" : ["-DOV_TRACE=1"],
2525
})
26-
COPTS_ADJUSTED = COMMON_STATIC_LIBS_COPTS + select({
27-
"//conditions:default": [],
28-
"//:fuzzer_build" : COMMON_FUZZER_COPTS,
29-
})
3026
LINKOPTS_ADJUSTED = COMMON_STATIC_LIBS_LINKOPTS + select({
3127
"//conditions:default": [],
3228
"//:fuzzer_build" : COMMON_FUZZER_LINKOPTS,

src/llm/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ ovms_cc_library(
124124
"//src:libovmslogging",
125125
"//src:libovmsstring_utils",
126126
"//src:libovmsstatus",
127+
"//src/utils:rapidjson_utils",
127128
] + select({
128129
"//conditions:default": ["//third_party:genai", ":llm_engine"],
129130
"//:not_genai_bin" : [":llm_engine"],

src/llm/io_processing/qwen3coder/qwen3coder_tool_parser.cpp

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
#include "src/llm/io_processing/utils.hpp"
3131
#include "src/logging.hpp"
32+
#include "src/utils/rapidjson_utils.hpp"
3233
#include "qwen3coder_tool_parser.hpp"
3334

3435
namespace ovms {
@@ -314,18 +315,6 @@ std::optional<std::string> Qwen3CoderToolParserImpl::getCurrentFunctionName() co
314315
}
315316
return this->currentFunction.name;
316317
}
317-
// Example from OpenAI API. Keep in mind that for Qwen3Coder we will send only function name, and then second message with all arguments
318-
319-
// for Qwen3Coder we will send first response with function call name and id
320-
// then we will send only one delta with all arguments
321-
322-
static std::string documentToString(const rapidjson::Document& doc) {
323-
rapidjson::StringBuffer buffer;
324-
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
325-
doc.Accept(writer);
326-
return buffer.GetString();
327-
}
328-
329318
std::optional<rapidjson::Document> Qwen3CoderToolParser::sendFullDelta(std::optional<ToolCalls>& toolCallsOpt) {
330319
auto& toolCalls = toolCallsOpt.value();
331320
if (toolCalls.size() != 1) {

src/utils/BUILD

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#
2+
# Copyright (c) 2025 Intel Corporation
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
load("//:common_settings.bzl", "ovms_cc_library")
17+
18+
ovms_cc_library(
19+
name = "rapidjson_utils",
20+
hdrs = ["rapidjson_utils.hpp"],
21+
srcs = ["rapidjson_utils.cpp"],
22+
deps = [
23+
"@com_github_tencent_rapidjson//:rapidjson",
24+
],
25+
visibility = ["//visibility:public",],
26+
)

src/utils/rapidjson_utils.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//*****************************************************************************
2+
// Copyright 2025 Intel Corporation
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//*****************************************************************************
16+
#include "rapidjson_utils.hpp"
17+
18+
#include <string>
19+
20+
#pragma warning(push)
21+
#pragma warning(disable : 6313)
22+
#include <rapidjson/document.h>
23+
#include <rapidjson/stringbuffer.h>
24+
#include <rapidjson/writer.h>
25+
#pragma warning(pop)
26+
27+
namespace ovms {
28+
std::string documentToString(const rapidjson::Document& doc) {
29+
rapidjson::StringBuffer buffer;
30+
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
31+
doc.Accept(writer);
32+
return buffer.GetString();
33+
}
34+
} // namespace ovms

src/utils/rapidjson_utils.hpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#pragma once
2+
//*****************************************************************************
3+
// Copyright 2025 Intel Corporation
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
//*****************************************************************************
17+
#include <string>
18+
19+
#pragma warning(push)
20+
#pragma warning(disable : 6313)
21+
#include <rapidjson/document.h>
22+
#pragma warning(pop)
23+
24+
namespace ovms {
25+
std::string documentToString(const rapidjson::Document& doc);
26+
} // namespace ovms

0 commit comments

Comments
 (0)