Skip to content

Commit 65fbb93

Browse files
Merge branch 'ggml-org:master' into i8mm-ci
2 parents 500c066 + 99c53d6 commit 65fbb93

40 files changed

+3673
-254
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,14 +1390,10 @@ jobs:
13901390
strategy:
13911391
matrix:
13921392
arch: [x86, aarch64]
1393-
cann:
1394-
- '8.3.rc1.alpha001-910b-openeuler22.03-py3.11'
1395-
chip_type:
1396-
- '910b'
1397-
build:
1398-
- 'Release'
1393+
chip_type: ['910b', '310p']
1394+
build: ['Release']
13991395
runs-on: ${{ matrix.arch == 'aarch64' && 'ubuntu-24.04-arm' || 'ubuntu-24.04' }}
1400-
container: ascendai/cann:${{ matrix.cann }}
1396+
container: ascendai/cann:${{ matrix.chip_type == '910b' && '8.3.rc1.alpha001-910b-openeuler22.03-py3.11' || '8.2.rc1-310p-openeuler22.03-py3.11' }}
14011397
steps:
14021398
- name: Checkout
14031399
uses: actions/checkout@v4

.github/workflows/release.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -698,10 +698,9 @@ jobs:
698698
matrix:
699699
arch: [x86, aarch64]
700700
chip_type: ['910b', '310p']
701-
build:
702-
- 'Release'
701+
build: ['Release']
703702
runs-on: ${{ matrix.arch == 'aarch64' && 'ubuntu-24.04-arm' || 'ubuntu-24.04' }}
704-
container: ascendai/cann:${{ matrix.chip_type == '910b' && '8.3.rc1.alpha001-910b-openeuler22.03-py3.11' || '8.3.rc1.alpha001-310p-openeuler22.03-py3.11' }}
703+
container: ascendai/cann:${{ matrix.chip_type == '910b' && '8.3.rc1.alpha001-910b-openeuler22.03-py3.11' || '8.2.rc1-310p-openeuler22.03-py3.11' }}
705704
steps:
706705
- name: Checkout
707706
uses: actions/checkout@v4
@@ -737,7 +736,7 @@ jobs:
737736
uses: actions/upload-artifact@v4
738737
with:
739738
path: llama-${{ steps.tag.outputs.name }}-bin-${{ matrix.chip_type }}-openEuler-${{ matrix.arch }}.zip
740-
name: llama-${{ steps.tag.outputs.name }}-bin-${{ matrix.chip_type }}-openEuler-${{ matrix.arch }}
739+
name: llama-bin-${{ matrix.chip_type }}-openEuler-${{ matrix.arch }}.zip
741740

742741
release:
743742
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}

common/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ add_library(${TARGET} STATIC
5050
base64.hpp
5151
chat-parser.cpp
5252
chat-parser.h
53+
chat-parser-xml-toolcall.h
54+
chat-parser-xml-toolcall.cpp
5355
chat.cpp
5456
chat.h
5557
common.cpp

common/chat-parser-xml-toolcall.cpp

Lines changed: 861 additions & 0 deletions
Large diffs are not rendered by default.

common/chat-parser-xml-toolcall.h

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#pragma once
2+
3+
#include "chat.h"
4+
5+
#include <nlohmann/json.hpp>
6+
7+
#include <optional>
8+
#include <string>
9+
#include <vector>
10+
11+
12+
// Sample config:
13+
// MiniMax-M2 (left): <minimax:tool_call>\n<invoke name="tool-name">\n<parameter name="key">value</parameter>\n...</invoke>\n...</minimax:tool_call>
14+
// GLM 4.5 (right): <tool_call>function_name\n<arg_key>key</arg_key>\n<arg_value>value</arg_value>\n</tool_call>
15+
struct xml_tool_call_format {
16+
std::string scope_start; // <minimax:tool_call>\n // \n // can be empty
17+
std::string tool_start; // <invoke name=\" // <tool_call>
18+
std::string tool_sep; // \">\n // \n // can be empty only for parse_xml_tool_calls
19+
std::string key_start; // <parameter name=\" // <arg_key>
20+
std::string key_val_sep; // \"> // </arg_key>\n<arg_value>
21+
std::string val_end; // </parameter>\n // </arg_value>\n
22+
std::string tool_end; // </invoke>\n // </tool_call>\n
23+
std::string scope_end; // </minimax:tool_call> // // can be empty
24+
// Set this if there can be dynamic spaces inside key_val_sep.
25+
// e.g. key_val_sep=</arg_key> key_val_sep2=<arg_value> for GLM4.5
26+
std::optional<std::string> key_val_sep2 = std::nullopt;
27+
// Set true if argval should only be raw string. e.g. Hello "world" hi
28+
// Set false if argval should only be json string. e.g. "Hello \"world\" hi"
29+
// Defaults to std::nullopt, both will be allowed.
30+
std::optional<bool> raw_argval = std::nullopt;
31+
std::optional<std::string> last_val_end = std::nullopt;
32+
std::optional<std::string> last_tool_end = std::nullopt;
33+
bool trim_raw_argval = false;
34+
bool allow_toolcall_in_think = false; // TODO: UNTESTED!!!
35+
};
36+
37+
// make a GBNF that accept any strings except those containing any of the forbidden strings.
38+
std::string make_gbnf_excluding(std::vector<std::string> forbids);
39+
40+
/**
41+
* Build grammar for xml-style tool call
42+
* form.scope_start and form.scope_end can be empty.
43+
* Requires data.format for model-specific hacks.
44+
*/
45+
void build_grammar_xml_tool_call(common_chat_params & data, const nlohmann::ordered_json & tools, const struct xml_tool_call_format & form);

common/chat-parser.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include "chat.h"
4+
#include "chat-parser-xml-toolcall.h"
45
#include "json-partial.h"
56
#include "regex-partial.h"
67

@@ -119,5 +120,14 @@ class common_chat_msg_parser {
119120
const std::vector<std::vector<std::string>> & content_paths = {}
120121
);
121122

123+
/**
124+
* Parse XML-Style tool call for given xml_tool_call_format. Return false for invalid syntax and get the position untouched.
125+
* form.scope_start, form.tool_sep and form.scope_end can be empty.
126+
*/
127+
bool try_consume_xml_tool_calls(const struct xml_tool_call_format & form);
128+
129+
// Parse content uses reasoning and XML-Style tool call
130+
void consume_reasoning_with_xml_tool_calls(const struct xml_tool_call_format & form, const std::string & start_think = "<think>", const std::string & end_think = "</think>");
131+
122132
void clear_tools();
123133
};

0 commit comments

Comments
 (0)