This commit is contained in:
2025-03-27 23:08:00 +01:00
parent d712b25bd0
commit 6c2dfaa557
7 changed files with 35 additions and 13 deletions
+14 -3
View File
@@ -36,6 +36,7 @@ SOFTWARE.
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include "openai.h"
#include "auth.h"
static PyObject* rpylib_reset(PyObject *self, PyObject *args) {
return PyUnicode_FromString("True");
@@ -43,9 +44,13 @@ 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);
PyObject *py_result = PyUnicode_FromString(result);
free(result);
@@ -75,8 +80,8 @@ static PyObject* rpylib_system(PyObject *self, PyObject *args) {
}
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."},
//{"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,5 +95,11 @@ static struct PyModuleDef rpylib = {
};
PyMODINIT_FUNC PyInit_rpylib(void) {
return PyModule_Create(&rpylib);
auth_init();
printf("Init\n");
void * res = PyModule_Create(&rpylib);
printf("GLOB\n");
return res;
}