@@ -52,6 +52,25 @@ static PyObject* PyMNNLLM_generate(LLM *self, PyObject *args) {
5252 return toPyObj<int , toPyObj>(output_ids);
5353}
5454
55+ static PyObject* PyMNNLLM_eraseHistory (LLM *self, PyObject *args) {
56+ if (self->is_embedding ) {
57+ Py_RETURN_NONE;
58+ }
59+ size_t history = 0 ;
60+ size_t end = 0 ;
61+ if (!PyArg_ParseTuple (args, " LL" , &history, &end)) {
62+ Py_RETURN_NONE;
63+ }
64+ self->llm ->eraseHistory (history, end);
65+ Py_RETURN_NONE;
66+ }
67+ static PyObject* PyMNNLLM_getCurrentHistory (LLM *self, PyObject *args) {
68+ if (self->is_embedding ) {
69+ Py_RETURN_NONE;
70+ }
71+ auto history = self->llm ->getCurrentHistory ();
72+ return PyLong_FromLong (history);
73+ }
5574static PyObject* PyMNNLLM_response (LLM *self, PyObject *args) {
5675 if (self->is_embedding ) {
5776 Py_RETURN_NONE;
@@ -62,8 +81,8 @@ static PyObject* PyMNNLLM_response(LLM *self, PyObject *args) {
6281 Py_RETURN_NONE;
6382 }
6483 std::ostringstream null_os;
65- auto res = self->llm ->response (query, stream ? &std::cout : &null_os);
66- return string2Object (res );
84+ self->llm ->response (query, stream ? &std::cout : &null_os);
85+ return string2Object (null_os. str () );
6786}
6887
6988static PyObject* PyMNNLLM_tokenizer_encode (LLM *self, PyObject *args) {
@@ -109,6 +128,8 @@ static PyMethodDef PyMNNLLM_methods[] = {
109128 {" forward" , (PyCFunction)PyMNNLLM_forward, METH_VARARGS, " forward `logits` by `input_ids`." },
110129 {" generate" , (PyCFunction)PyMNNLLM_generate, METH_VARARGS, " generate `output_ids` by `input_ids`." },
111130 {" response" , (PyCFunction)PyMNNLLM_response, METH_VARARGS, " response `query` without hsitory." },
131+ {" get_current_history" , (PyCFunction)PyMNNLLM_getCurrentHistory, METH_VARARGS, " Get Current History." },
132+ {" erase_history" , (PyCFunction)PyMNNLLM_eraseHistory, METH_VARARGS, " Erase History." },
112133 {" tokenizer_encode" , (PyCFunction)PyMNNLLM_tokenizer_encode, METH_VARARGS, " tokenizer encode." },
113134 {" tokenizer_decode" , (PyCFunction)PyMNNLLM_tokenizer_decode, METH_VARARGS, " tokenizer decode." },
114135 {" txt_embedding" , (PyCFunction)PyMNNLLM_txt_embedding, METH_VARARGS, " txt embedding." },
0 commit comments