Skip to content

Commit 1063988

Browse files
committed
create harmony parser
1 parent cd6983d commit 1063988

File tree

4 files changed

+37
-6
lines changed

4 files changed

+37
-6
lines changed

common/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ add_library(${TARGET} STATIC
7070
sampling.h
7171
speculative.cpp
7272
speculative.h
73+
parsers/harmony.cpp
74+
parsers/harmony.h
7375
)
7476

7577
if (BUILD_SHARED_LIBS)

common/chat.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "json-schema-to-grammar.h"
66
#include "log.h"
77
#include "regex-partial.h"
8+
#include "parsers/harmony.h"
89

910
#include <minja/chat-template.hpp>
1011
#include <minja/minja.hpp>
@@ -1319,12 +1320,8 @@ static common_chat_params common_chat_params_init_gpt_oss(const common_chat_temp
13191320
return data;
13201321
}
13211322
static void common_chat_parse_gpt_oss(common_chat_msg_parser & builder) {
1322-
// TODO @ngxson : this won't work with --special enabled, we should fix that
1323-
builder.try_parse_reasoning("<|channel|>analysis<|message|>", "<|start|>assistant<|channel|>final<|message|>");
1324-
if (!builder.syntax().parse_tool_calls) {
1325-
builder.add_content(builder.consume_rest());
1326-
return;
1327-
}
1323+
harmony_msg_parser parser(builder);
1324+
parser.parse();
13281325
}
13291326

13301327
static common_chat_params common_chat_params_init_firefunction_v2(const common_chat_template & tmpl, const struct templates_params & inputs) {

common/parsers/harmony.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include "harmony.h"
2+
3+
harmony_msg_parser::harmony_msg_parser(common_chat_msg_parser & builder)
4+
: builder(builder)
5+
{
6+
// TODO
7+
}
8+
9+
void harmony_msg_parser::parse() {
10+
// TODO @ngxson : this won't work with --special enabled, we should fix that
11+
builder.try_parse_reasoning("<|channel|>analysis<|message|>", "<|start|>assistant<|channel|>final<|message|>");
12+
if (!builder.syntax().parse_tool_calls) {
13+
builder.add_content(builder.consume_rest());
14+
return;
15+
}
16+
}

common/parsers/harmony.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#pragma once
2+
3+
#include "chat-parser.h"
4+
5+
#include <optional>
6+
#include <string>
7+
#include <vector>
8+
9+
class harmony_msg_parser {
10+
common_chat_msg_parser & builder;
11+
12+
public:
13+
harmony_msg_parser(common_chat_msg_parser & builder);
14+
15+
void parse();
16+
};

0 commit comments

Comments
 (0)