This repository has been archived on 2026-11-24. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
radiance-sycl/tests/legacy/toolparse_legacy.h
T
Deadcode 1e968f6e1d radiance 1.7.0
- every model serves without a GPU: libavx covers every op, so `--kernels libavx` alone serves
  every shipped container
- Qwen3-ASR (zivius): speech to text on /v1/audio/transcriptions and live over /v1/realtime
- /v1/messages works with Claude Code as it ships (gearwave00001)
- a long agent conversation keeps its cached history when the client rewrites its last turn
  (manueloverride)
- a stream's first event goes out with the first token, so llama-benchy measures prefill right
- opt-in --prefill-interleave (Smellyyyy, baKon) and --prefill-span (keptn42)
- four-rank TP releases the link early; four-rank selftests and docs/TP4.md (goodman-b)
- NVFP4 and FP8 compressed-tensors imports (devmilan); tools/rad-export for finetunes and LoRA
  adapters (baKon)
- many fixes, among them lost tokens on stop strings under concurrency, keep-alive, MiniCPM5 tool
  arguments and the CPU's vision and audio encoders
- plugin ABI 17 and changed op schemas: out-of-tree plugins must be rebuilt
2026-10-16 18:25:18 +02:00

95 lines
3.8 KiB
C++

/* toolparse_legacy.h -- a whole-reply parser built on llama.cpp's PEG auto-parser, the oracle the
* differential tests compare the streaming parser (core/text/chatparse.h) against. Built into the
* test binaries and the acceptance tool, never into the engine.
*
* It keeps every layer of the legacy path, since the answer is what they produce together:
*
* * ToolParser -- llama.cpp's PEG parser, generated per request from the chat template by the
* vendored auto-parser (vendor/llama/common/chat-auto-parser*.cpp), run over the whole reply;
* * legacy_parse -- the bridge: trims a turn terminator off the content and, when the strict
* parse produced no call but the content still carries call syntax, lifts calls by hand;
* * LegacyDeltaStream -- re-parses the accumulated reply on every chunk and sends what grew.
*/
#pragma once
#include "rad_internal.h"
#include <memory>
#include <string>
#include <vector>
namespace rad {
struct ChatPrompt;
namespace legacy {
struct ToolCall {
std::string name;
std::string arguments;
std::string id;
};
struct ParsedReply {
std::string content;
std::string reasoning_content;
std::vector<ToolCall> tool_calls;
};
/* The by-hand lifter: reads `<function name="N"><param name="K">V</param></function>` and
* `<tool_call><function=N><parameter=K>V</parameter></function></tool_call>` spans out of `text`
* regardless of the model's format, appends them to `out` and removes them. */
size_t toolparse_lift_xml_calls(std::string& text, std::vector<ToolCall>& out);
/* The earliest byte of `text` that could begin a call in either spelling, or npos. */
size_t toolparse_find_call_open(const std::string& text);
/* The vendored PEG parser for one rendered request. */
class ToolParser {
public:
ToolParser();
~ToolParser();
int init(const ChatPrompt& p, const std::string& reasoning_format = "auto",
bool parse_tool_calls = true);
/* RAD_OK, or RAD_E_FORMAT when the reply does not match the format at all. */
int parse(const std::string& text, bool is_partial, ParsedReply* out) const;
bool ready() const;
private:
struct Impl;
std::unique_ptr<Impl> impl_;
};
/* What the legacy path answers for a reply, and which of its layers produced the answer. */
struct Answer {
std::string content, reasoning;
std::vector<ToolCall> calls;
bool strict_failed = false; /* the PEG parse failed; the whole reply became content */
size_t lifted = 0; /* calls the by-hand lifter took out of the content */
};
/* The bridge's reading of a reply: the PEG parse, the terminator trim and, for a request that
* offered tools, the lifter. `is_partial` is the streaming path's question. */
Answer legacy_parse(const ToolParser& tp, const std::string& text, bool is_partial,
bool want_calls, const std::vector<std::string>& terminators);
/* The legacy streaming diff over the accumulated text. push() returns the bytes of deltas sent;
* the accessors hold the concatenation of what was sent. */
class LegacyDeltaStream {
public:
LegacyDeltaStream(const ToolParser& tp, bool want_calls, std::vector<std::string> terminators)
: tp_(tp), want_calls_(want_calls), terms_(std::move(terminators)) {}
size_t push(const std::string& full_text, bool is_final);
const std::string& content() const { return content_; }
const std::string& reasoning() const { return reasoning_; }
const std::vector<std::string>& arguments() const { return args_; }
const std::vector<std::string>& names() const { return names_; }
private:
const ToolParser& tp_;
bool want_calls_;
std::vector<std::string> terms_;
std::string content_, reasoning_;
std::vector<std::string> names_, args_;
};
} /* namespace legacy */
} /* namespace rad */