Everything safe.
This commit is contained in:
parent
de80b013c0
commit
016e335a23
1
chat.h
1
chat.h
@ -16,7 +16,6 @@ void chat_free(){
|
|||||||
_prompt = NULL;
|
_prompt = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char * chat_json(char * role, char * message){
|
char * chat_json(char * role, char * message){
|
||||||
chat_free();
|
chat_free();
|
||||||
message_add(role,message);
|
message_add(role,message);
|
||||||
|
3
http.h
3
http.h
@ -100,14 +100,12 @@ char *http_post(const char *hostname, char *url, char *data)
|
|||||||
int buffer_size = 4096;
|
int buffer_size = 4096;
|
||||||
char *buffer = (char *)malloc(buffer_size);
|
char *buffer = (char *)malloc(buffer_size);
|
||||||
|
|
||||||
|
|
||||||
if (SSL_connect(ssl) <= 0)
|
if (SSL_connect(ssl) <= 0)
|
||||||
{
|
{
|
||||||
ERR_print_errors_fp(stderr);
|
ERR_print_errors_fp(stderr);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//printf("Connected with %s encryption\n", SSL_get_cipher(ssl));
|
|
||||||
size_t len = strlen(data);
|
size_t len = strlen(data);
|
||||||
char *request = (char *)malloc(len + 4096);
|
char *request = (char *)malloc(len + 4096);
|
||||||
request[0] = 0;
|
request[0] = 0;
|
||||||
@ -173,7 +171,6 @@ char *http_get(const char *hostname, char *url)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//printf("Connected with %s encryption\n", SSL_get_cipher(ssl));
|
|
||||||
|
|
||||||
char request[buffer_size];
|
char request[buffer_size];
|
||||||
request[0] = 0;
|
request[0] = 0;
|
||||||
|
6
main.c
6
main.c
@ -43,11 +43,9 @@ void render(char *);
|
|||||||
void serve() {
|
void serve() {
|
||||||
render("Starting server. *Put executables in a dir named cgi-bin and they will behave as webpages.*");
|
render("Starting server. *Put executables in a dir named cgi-bin and they will behave as webpages.*");
|
||||||
int res = system("python3 -m http.server --cgi");
|
int res = system("python3 -m http.server --cgi");
|
||||||
// Thanks tsoding!
|
|
||||||
(void)res;
|
(void)res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void render(char * content) {
|
void render(char * content) {
|
||||||
parse_markdown_to_ansi(content);
|
parse_markdown_to_ansi(content);
|
||||||
printf("\n\n");
|
printf("\n\n");
|
||||||
@ -84,10 +82,7 @@ void repl(){
|
|||||||
while(true) {
|
while(true) {
|
||||||
render(response);
|
render(response);
|
||||||
sleep(2);
|
sleep(2);
|
||||||
//line = line_read("> ");
|
|
||||||
//if(!*line)
|
|
||||||
response = openai_chat("user",response);
|
response = openai_chat("user",response);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!strncmp(line,"ls",2) || !strncmp(line,"list",4)) {
|
if(!strncmp(line,"ls",2) || !strncmp(line,"list",4)) {
|
||||||
@ -112,7 +107,6 @@ void repl(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void help() {
|
void help() {
|
||||||
char help_text[1024*1024] = {0};
|
char help_text[1024*1024] = {0};
|
||||||
char * template = "# Help\n"
|
char * template = "# Help\n"
|
||||||
|
8
openai.h
8
openai.h
@ -27,7 +27,6 @@ bool openai_system(char * content){
|
|||||||
return is_done;
|
return is_done;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char *openai_chat(char * role, char * content){
|
char *openai_chat(char * role, char * content){
|
||||||
const char *hostname = "api.openai.com";
|
const char *hostname = "api.openai.com";
|
||||||
char *url = "/v1/chat/completions";
|
char *url = "/v1/chat/completions";
|
||||||
@ -50,7 +49,6 @@ char *openai_chat(char * role, char * content){
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the first element of the "choices" array
|
|
||||||
struct json_object *first_choice = json_object_array_get_idx(choices_array, 0);
|
struct json_object *first_choice = json_object_array_get_idx(choices_array, 0);
|
||||||
if (!first_choice) {
|
if (!first_choice) {
|
||||||
fprintf(stderr, "Failed to get the first element of 'choices'.\n");
|
fprintf(stderr, "Failed to get the first element of 'choices'.\n");
|
||||||
@ -58,7 +56,6 @@ char *openai_chat(char * role, char * content){
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract the "message" object
|
|
||||||
struct json_object *message_object;
|
struct json_object *message_object;
|
||||||
if (!json_object_object_get_ex(first_choice, "message", &message_object)) {
|
if (!json_object_object_get_ex(first_choice, "message", &message_object)) {
|
||||||
fprintf(stderr, "Failed to get 'message' object.\n");
|
fprintf(stderr, "Failed to get 'message' object.\n");
|
||||||
@ -66,18 +63,13 @@ char *openai_chat(char * role, char * content){
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print the "message" object
|
|
||||||
// printf("Message object:\n%s\n", json_object_to_json_string_ext(message_object, JSON_C_TO_STRING_PRETTY));
|
|
||||||
message_add("assistant",(char *)json_object_get_string(json_object_object_get(message_object, "content")));
|
message_add("assistant",(char *)json_object_get_string(json_object_object_get(message_object, "content")));
|
||||||
// Clean up
|
|
||||||
free(data);
|
free(data);
|
||||||
free(result);
|
free(result);
|
||||||
result = strdup((char *)json_object_get_string(json_object_object_get(message_object, "content")));
|
result = strdup((char *)json_object_get_string(json_object_object_get(message_object, "content")));
|
||||||
|
|
||||||
json_object_put(parsed_json);
|
json_object_put(parsed_json);
|
||||||
|
|
||||||
//printf("Parsed JSON:\n%s\n", json_object_to_json_string_ext(parsed_json, JSON_C_TO_STRING_PRETTY));
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
1
plugin.h
1
plugin.h
@ -10,7 +10,6 @@ bool plugin_construct(){
|
|||||||
|
|
||||||
Py_Initialize();
|
Py_Initialize();
|
||||||
|
|
||||||
// Check if Python initialized successfully
|
|
||||||
if (!Py_IsInitialized()) {
|
if (!Py_IsInitialized()) {
|
||||||
fprintf(stderr, "Failed to initialize Python interpreter\n");
|
fprintf(stderr, "Failed to initialize Python interpreter\n");
|
||||||
return plugin_initialized;
|
return plugin_initialized;
|
||||||
|
Loading…
Reference in New Issue
Block a user