@@ -8,6 +8,33 @@ namespace ctranslate2 {
88 namespace python {
99
1010 void register_generation_result (py::module & m) {
11+ py::class_<GenerationStepResult>(m, " GenerationStepResult" ,
12+ " The result for a single generation step." )
13+
14+ .def_readonly (" step" , &GenerationStepResult::step,
15+ " The decoding step." )
16+ .def_readonly (" batch_id" , &GenerationStepResult::batch_id,
17+ " The batch index." )
18+ .def_readonly (" token_id" , &GenerationStepResult::token_id,
19+ " ID of the generated token." )
20+ .def_readonly (" token" , &GenerationStepResult::token,
21+ " String value of the generated token." )
22+ .def_readonly (" log_prob" , &GenerationStepResult::log_prob,
23+ " Log probability of the token (``None`` if :obj:`return_log_prob` was disabled)." )
24+ .def_readonly (" is_last" , &GenerationStepResult::is_last,
25+ " Whether this step is the last decoding step for this batch." )
26+
27+ .def (" __repr__" , [](const GenerationStepResult& result) {
28+ return " GenerationStepResult(step=" + std::string (py::repr (py::cast (result.step )))
29+ + " , batch_id=" + std::string (py::repr (py::cast (result.batch_id )))
30+ + " , token_id=" + std::string (py::repr (py::cast (result.token_id )))
31+ + " , token=" + std::string (py::repr (py::cast (result.token )))
32+ + " , log_prob=" + std::string (py::repr (py::cast (result.log_prob )))
33+ + " , is_last=" + std::string (py::repr (py::cast (result.is_last )))
34+ + " )" ;
35+ })
36+ ;
37+
1138 py::class_<GenerationResult>(m, " GenerationResult" , " A generation result." )
1239
1340 .def_readonly (" sequences" , &GenerationResult::sequences,
0 commit comments