Update.
This commit is contained in:
@@ -46,42 +46,59 @@ static PyObject *rpylib_reset(PyObject *self, PyObject *args) {
|
||||
static PyObject *rpylib_chat(PyObject *self, PyObject *args) {
|
||||
const char *role, *message;
|
||||
|
||||
printf("That goes alright! 1\n");
|
||||
if (!PyArg_ParseTuple(args, "ss", &role, &message)) {
|
||||
return NULL;
|
||||
}
|
||||
printf("That goes alright! 2\n");
|
||||
|
||||
char *result = openai_chat(role, message);
|
||||
if (!result) {
|
||||
PyErr_SetString(PyExc_RuntimeError, "Failed to get response from OpenAI.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PyObject *py_result = PyUnicode_FromString(result);
|
||||
free(result);
|
||||
return py_result;
|
||||
}
|
||||
|
||||
static PyObject *rpylib_prompt(PyObject *self, PyObject *args) {
|
||||
const char *role = "user";
|
||||
const char *message;
|
||||
if (!PyArg_ParseTuple(args, "s", &message)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *result = openai_chat(role, message);
|
||||
if (!result) {
|
||||
PyErr_SetString(PyExc_RuntimeError, "Failed to get response from OpenAI.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PyObject *py_result = PyUnicode_FromString(result);
|
||||
free(result);
|
||||
return py_result;
|
||||
}
|
||||
|
||||
static PyObject *rpylib_system(PyObject *self, PyObject *args) {
|
||||
const char *role = "system";
|
||||
const char *message;
|
||||
if (!PyArg_ParseTuple(args, "s", &message)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *result = openai_chat(role, message);
|
||||
if (!result) {
|
||||
PyErr_SetString(PyExc_RuntimeError, "Failed to get response from OpenAI.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PyObject *py_result = PyUnicode_FromString(result);
|
||||
free(result);
|
||||
return py_result;
|
||||
}
|
||||
|
||||
static PyMethodDef MyModuleMethods[] = {
|
||||
{"chat", rpylib_chat, METH_VARARGS, "Chat with OpenAI."},
|
||||
//{"prompt", rpylib_prompt, METH_VARARGS, "Prompt to OpenAI."},
|
||||
//{"system", rpylib_system, METH_VARARGS, "Add system message."},
|
||||
{"reset", rpylib_reset, METH_NOARGS, "Reset message history."},
|
||||
{NULL, NULL, 0, NULL}};
|
||||
|
||||
@@ -90,11 +107,6 @@ static struct PyModuleDef rpylib = {
|
||||
"R - the power of R in Python, made by retoor.", -1, MyModuleMethods};
|
||||
|
||||
PyMODINIT_FUNC PyInit_rpylib(void) {
|
||||
|
||||
auth_init();
|
||||
|
||||
printf("Init\n");
|
||||
void *res = PyModule_Create(&rpylib);
|
||||
printf("GLOB\n");
|
||||
return res;
|
||||
}
|
||||
return PyModule_Create(&rpylib);
|
||||
}
|
||||
Reference in New Issue
Block a user