diff --git a/Makefile b/Makefile index 1fecf82..6da7674 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -all: build run +all: build build_rpylib run # Variables for compiler and flags CC = gcc @@ -9,12 +9,9 @@ build: $(CC) main.c $(CFLAGS) -o r publish r -build_free: - $(CC) main.c -DFREE_VERSION $(CFLAGS) -o rf - publish rf - build_rpylib: $(CC) -shared -o rpylib.so -fPIC rpylib.c -lpython3.12 `python3-config --includes` -I/usr/include/CL -ljson-c -lcurl + publish rpylib.so run: ./r diff --git a/rpylib.c b/rpylib.c index 108a44c..874744f 100644 --- a/rpylib.c +++ b/rpylib.c @@ -51,9 +51,32 @@ static PyObject* rpylib_chat(PyObject *self, PyObject *args) { 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); + 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); + 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} };