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;
|
||||
}
|
||||
|
||||
|
||||
char * chat_json(char * role, char * message){
|
||||
chat_free();
|
||||
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;
|
||||
char *buffer = (char *)malloc(buffer_size);
|
||||
|
||||
|
||||
if (SSL_connect(ssl) <= 0)
|
||||
{
|
||||
ERR_print_errors_fp(stderr);
|
||||
}
|
||||
else
|
||||
{
|
||||
//printf("Connected with %s encryption\n", SSL_get_cipher(ssl));
|
||||
size_t len = strlen(data);
|
||||
char *request = (char *)malloc(len + 4096);
|
||||
request[0] = 0;
|
||||
@ -173,7 +171,6 @@ char *http_get(const char *hostname, char *url)
|
||||
}
|
||||
else
|
||||
{
|
||||
//printf("Connected with %s encryption\n", SSL_get_cipher(ssl));
|
||||
|
||||
char request[buffer_size];
|
||||
request[0] = 0;
|
||||
|
6
main.c
6
main.c
@ -43,11 +43,9 @@ void render(char *);
|
||||
void serve() {
|
||||
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");
|
||||
// Thanks tsoding!
|
||||
(void)res;
|
||||
}
|
||||
|
||||
|
||||
void render(char * content) {
|
||||
parse_markdown_to_ansi(content);
|
||||
printf("\n\n");
|
||||
@ -84,10 +82,7 @@ void repl(){
|
||||
while(true) {
|
||||
render(response);
|
||||
sleep(2);
|
||||
//line = line_read("> ");
|
||||
//if(!*line)
|
||||
response = openai_chat("user",response);
|
||||
|
||||
}
|
||||
}
|
||||
if(!strncmp(line,"ls",2) || !strncmp(line,"list",4)) {
|
||||
@ -112,7 +107,6 @@ void repl(){
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void help() {
|
||||
char help_text[1024*1024] = {0};
|
||||
char * template = "# Help\n"
|
||||
|
8
openai.h
8
openai.h
@ -27,7 +27,6 @@ bool openai_system(char * content){
|
||||
return is_done;
|
||||
}
|
||||
|
||||
|
||||
char *openai_chat(char * role, char * content){
|
||||
const char *hostname = "api.openai.com";
|
||||
char *url = "/v1/chat/completions";
|
||||
@ -50,7 +49,6 @@ char *openai_chat(char * role, char * content){
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Get the first element of the "choices" array
|
||||
struct json_object *first_choice = json_object_array_get_idx(choices_array, 0);
|
||||
if (!first_choice) {
|
||||
fprintf(stderr, "Failed to get the first element of 'choices'.\n");
|
||||
@ -58,7 +56,6 @@ char *openai_chat(char * role, char * content){
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Extract the "message" object
|
||||
struct json_object *message_object;
|
||||
if (!json_object_object_get_ex(first_choice, "message", &message_object)) {
|
||||
fprintf(stderr, "Failed to get 'message' object.\n");
|
||||
@ -66,18 +63,13 @@ char *openai_chat(char * role, char * content){
|
||||
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")));
|
||||
// Clean up
|
||||
free(data);
|
||||
free(result);
|
||||
result = strdup((char *)json_object_get_string(json_object_object_get(message_object, "content")));
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user