diff --git a/Makefile b/Makefile index bbf61db..f1f34dc 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ build: publish r build_rpylib: - $(CC) -shared -o rpylib.so -fPIC rpylib.c -lpython3.12 `python3-config --includes` -I/usr/include/CL -ljson-c -lcurl + $(CC) -shared -o rpylib.so -fPIC rpylib.c -lpython3.12 `python3-config --includes` -I/usr/include/CL -ljson-c -lcurl -lsqlite3 publish rpylib.so run: diff --git a/chat.h b/chat.h index 54e2437..2bea3af 100644 --- a/chat.h +++ b/chat.h @@ -43,7 +43,7 @@ const char * get_prompt_model() { } } -static int prompt_max_tokens = 2048; +static int prompt_max_tokens = 10000; static double prompt_temperature = 0.1; static json_object *_prompt = NULL; diff --git a/line.h b/line.h index b76ea21..9ec53fc 100644 --- a/line.h +++ b/line.h @@ -14,11 +14,22 @@ #include <string.h> #include <stdbool.h> #include <glob.h> - -#define HISTORY_FILE ".r_history" +#include "utils.h" +#define HISTORY_FILE "~/.r_history" bool line_initialized = false; + +char * get_history_file(){ + static char result[4096]; + result[0] = 0; + + char * expanded = expand_home_directory(HISTORY_FILE); + strcpy(result, expanded); + free(expanded); + return result; +} + char* line_command_generator(const char* text, int state) { static int list_index, len = 0; const char* commands[] = {"help", "exit", "list", "review", "refactor", "obfuscate", NULL}; @@ -72,7 +83,7 @@ void line_init() { if (!line_initialized) { rl_attempted_completion_function = line_command_completion; line_initialized = true; - read_history(HISTORY_FILE); + read_history(get_history_file()); } } @@ -87,5 +98,5 @@ char* line_read(char* prefix) { void line_add_history(char* data) { add_history(data); - write_history(HISTORY_FILE); + write_history(get_history_file()); } diff --git a/openai.h b/openai.h index f944df9..0bae875 100644 --- a/openai.h +++ b/openai.h @@ -99,10 +99,10 @@ char* openai_chat(const char* user_role, const char* message_content) { if(message_content == NULL || *message_content == '\0' || *message_content == '\n') { return NULL; } - const char* api_url = "https://api.openai.com/v1/chat/completions"; char* json_data = chat_json(user_role, message_content); + struct json_object* message_object = openai_process_chat_message(api_url, json_data); message_add_object(message_object); if (message_object == NULL) { diff --git a/rpylib.c b/rpylib.c index 874744f..88d900b 100644 --- a/rpylib.c +++ b/rpylib.c @@ -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; } diff --git a/rpylib.so b/rpylib.so index 3fe6a56..561f764 100755 Binary files a/rpylib.so and b/rpylib.so differ diff --git a/tools.h b/tools.h index 99f249e..b0ad573 100644 --- a/tools.h +++ b/tools.h @@ -529,7 +529,7 @@ struct json_object* tool_description_write_file() { struct json_object* function = json_object_new_object(); json_object_object_add(function, "name", json_object_new_string("write_file")); - json_object_object_add(function, "description", json_object_new_string("Writes / saves / stores content to a file.")); + json_object_object_add(function, "description", json_object_new_string("Writes / saves / stores content to a file. Content should be in plain format, not json encoded.")); struct json_object* parameters = json_object_new_object(); json_object_object_add(parameters, "type", json_object_new_string("object")); @@ -538,12 +538,12 @@ struct json_object* tool_description_write_file() { struct json_object* path = json_object_new_object(); json_object_object_add(path, "type", json_object_new_string("string")); - json_object_object_add(path, "description", json_object_new_string("Path to the file to write / save / store.")); + json_object_object_add(path, "description", json_object_new_string("Path to the plain file to write / save / store.")); json_object_object_add(properties, "path", path); struct json_object* content = json_object_new_object(); json_object_object_add(content, "type", json_object_new_string("string")); - json_object_object_add(content, "description", json_object_new_string("Content to write / save / store into the file.")); + json_object_object_add(content, "description", json_object_new_string("Plain content to write / save / store into the file.")); json_object_object_add(properties, "content", content); json_object_object_add(parameters, "properties", properties);