Skip to content

Commit d352449

Browse files
committed
Rename test
1 parent ab238c1 commit d352449

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

extension/llm/runner/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ def generate_text(
238238
if hasattr(config, key):
239239
setattr(config, key, value)
240240

241-
return self._runner.generate_text(inputs, config)
241+
return self._runner.generate_text(inputs, config) # type: ignore[attr-defined]
242242

243243
def stop(self):
244244
"""Stop the current generation process."""

extension/llm/runner/pybindings.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,24 @@ class PyMultimodalRunner {
100100
}
101101
}
102102

103+
std::string generate_text(
104+
const std::vector<MultimodalInput>& inputs,
105+
const GenerationConfig& config) {
106+
if (!runner_) {
107+
throw std::runtime_error("Runner not initialized");
108+
}
109+
110+
std::string generated_text;
111+
auto cpp_token_callback = [&generated_text](const std::string& token) {
112+
generated_text += token;
113+
};
114+
Error error =
115+
runner_->generate(inputs, config, cpp_token_callback, nullptr);
116+
THROW_IF_ERROR(error, "Generation failed");
117+
118+
return generated_text;
119+
}
120+
103121
void stop() {
104122
if (runner_) {
105123
runner_->stop();
@@ -306,6 +324,13 @@ PYBIND11_MODULE(_llm_runner, m) {
306324
py::arg("stats_callback") = py::none(),
307325
"Generate text from multimodal inputs with optional callbacks")
308326
.def("stop", &PyMultimodalRunner::stop, "Stop the current generation")
327+
.def(
328+
"generate_text",
329+
&PyMultimodalRunner::generate_text,
330+
py::arg("inputs"),
331+
py::arg("config"),
332+
"Generate text from multimodal inputs and return the complete "
333+
"result")
309334
.def(
310335
"reset",
311336
&PyMultimodalRunner::reset,

0 commit comments

Comments
 (0)