Update.
This commit is contained in:
parent
d712b25bd0
commit
6c2dfaa557
2
Makefile
2
Makefile
@ -10,7 +10,7 @@ build:
|
|||||||
publish r
|
publish r
|
||||||
|
|
||||||
build_rpylib:
|
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
|
publish rpylib.so
|
||||||
|
|
||||||
run:
|
run:
|
||||||
|
2
chat.h
2
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 double prompt_temperature = 0.1;
|
||||||
|
|
||||||
static json_object *_prompt = NULL;
|
static json_object *_prompt = NULL;
|
||||||
|
19
line.h
19
line.h
@ -14,11 +14,22 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <glob.h>
|
#include <glob.h>
|
||||||
|
#include "utils.h"
|
||||||
#define HISTORY_FILE ".r_history"
|
#define HISTORY_FILE "~/.r_history"
|
||||||
|
|
||||||
bool line_initialized = false;
|
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) {
|
char* line_command_generator(const char* text, int state) {
|
||||||
static int list_index, len = 0;
|
static int list_index, len = 0;
|
||||||
const char* commands[] = {"help", "exit", "list", "review", "refactor", "obfuscate", NULL};
|
const char* commands[] = {"help", "exit", "list", "review", "refactor", "obfuscate", NULL};
|
||||||
@ -72,7 +83,7 @@ void line_init() {
|
|||||||
if (!line_initialized) {
|
if (!line_initialized) {
|
||||||
rl_attempted_completion_function = line_command_completion;
|
rl_attempted_completion_function = line_command_completion;
|
||||||
line_initialized = true;
|
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) {
|
void line_add_history(char* data) {
|
||||||
add_history(data);
|
add_history(data);
|
||||||
write_history(HISTORY_FILE);
|
write_history(get_history_file());
|
||||||
}
|
}
|
||||||
|
2
openai.h
2
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') {
|
if(message_content == NULL || *message_content == '\0' || *message_content == '\n') {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const char* api_url = "https://api.openai.com/v1/chat/completions";
|
const char* api_url = "https://api.openai.com/v1/chat/completions";
|
||||||
char* json_data = chat_json(user_role, message_content);
|
char* json_data = chat_json(user_role, message_content);
|
||||||
|
|
||||||
struct json_object* message_object = openai_process_chat_message(api_url, json_data);
|
struct json_object* message_object = openai_process_chat_message(api_url, json_data);
|
||||||
message_add_object(message_object);
|
message_add_object(message_object);
|
||||||
if (message_object == NULL) {
|
if (message_object == NULL) {
|
||||||
|
17
rpylib.c
17
rpylib.c
@ -36,6 +36,7 @@ SOFTWARE.
|
|||||||
#define PY_SSIZE_T_CLEAN
|
#define PY_SSIZE_T_CLEAN
|
||||||
#include <Python.h>
|
#include <Python.h>
|
||||||
#include "openai.h"
|
#include "openai.h"
|
||||||
|
#include "auth.h"
|
||||||
|
|
||||||
static PyObject* rpylib_reset(PyObject *self, PyObject *args) {
|
static PyObject* rpylib_reset(PyObject *self, PyObject *args) {
|
||||||
return PyUnicode_FromString("True");
|
return PyUnicode_FromString("True");
|
||||||
@ -43,9 +44,13 @@ static PyObject* rpylib_reset(PyObject *self, PyObject *args) {
|
|||||||
|
|
||||||
static PyObject* rpylib_chat(PyObject *self, PyObject *args) {
|
static PyObject* rpylib_chat(PyObject *self, PyObject *args) {
|
||||||
const char *role, *message;
|
const char *role, *message;
|
||||||
|
|
||||||
|
|
||||||
|
printf("That goes alright! 1\n");
|
||||||
if (!PyArg_ParseTuple(args, "ss", &role, &message)) {
|
if (!PyArg_ParseTuple(args, "ss", &role, &message)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
printf("That goes alright! 2\n");
|
||||||
char *result = openai_chat(role, message);
|
char *result = openai_chat(role, message);
|
||||||
PyObject *py_result = PyUnicode_FromString(result);
|
PyObject *py_result = PyUnicode_FromString(result);
|
||||||
free(result);
|
free(result);
|
||||||
@ -75,8 +80,8 @@ static PyObject* rpylib_system(PyObject *self, PyObject *args) {
|
|||||||
}
|
}
|
||||||
static PyMethodDef MyModuleMethods[] = {
|
static PyMethodDef MyModuleMethods[] = {
|
||||||
{"chat", rpylib_chat, METH_VARARGS, "Chat with OpenAI."},
|
{"chat", rpylib_chat, METH_VARARGS, "Chat with OpenAI."},
|
||||||
{"prompt", rpylib_prompt, METH_VARARGS, "Prompt to OpenAI."},
|
//{"prompt", rpylib_prompt, METH_VARARGS, "Prompt to OpenAI."},
|
||||||
{"system", rpylib_system, METH_VARARGS, "Add system message."},
|
//{"system", rpylib_system, METH_VARARGS, "Add system message."},
|
||||||
{"reset", rpylib_reset, METH_NOARGS, "Reset message history."},
|
{"reset", rpylib_reset, METH_NOARGS, "Reset message history."},
|
||||||
{NULL, NULL, 0, NULL}
|
{NULL, NULL, 0, NULL}
|
||||||
};
|
};
|
||||||
@ -90,5 +95,11 @@ static struct PyModuleDef rpylib = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
PyMODINIT_FUNC PyInit_rpylib(void) {
|
PyMODINIT_FUNC PyInit_rpylib(void) {
|
||||||
return PyModule_Create(&rpylib);
|
|
||||||
|
auth_init();
|
||||||
|
|
||||||
|
printf("Init\n");
|
||||||
|
void * res = PyModule_Create(&rpylib);
|
||||||
|
printf("GLOB\n");
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
6
tools.h
6
tools.h
@ -529,7 +529,7 @@ struct json_object* tool_description_write_file() {
|
|||||||
|
|
||||||
struct json_object* function = json_object_new_object();
|
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, "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();
|
struct json_object* parameters = json_object_new_object();
|
||||||
json_object_object_add(parameters, "type", json_object_new_string("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();
|
struct json_object* path = json_object_new_object();
|
||||||
json_object_object_add(path, "type", json_object_new_string("string"));
|
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);
|
json_object_object_add(properties, "path", path);
|
||||||
|
|
||||||
struct json_object* content = json_object_new_object();
|
struct json_object* content = json_object_new_object();
|
||||||
json_object_object_add(content, "type", json_object_new_string("string"));
|
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(properties, "content", content);
|
||||||
|
|
||||||
json_object_object_add(parameters, "properties", properties);
|
json_object_object_add(parameters, "properties", properties);
|
||||||
|
Loading…
Reference in New Issue
Block a user