Update.
This commit is contained in:
parent
c0f5be662a
commit
e02315a0f6
3
.gitignore
vendored
3
.gitignore
vendored
@ -8,4 +8,5 @@ r
|
|||||||
rf
|
rf
|
||||||
.docs
|
.docs
|
||||||
auth.h
|
auth.h
|
||||||
.rcontext
|
.rcontext*
|
||||||
|
tests
|
||||||
|
@ -1,17 +0,0 @@
|
|||||||
Alle vragen die je krijgt en beantwoordt, worden behandeld in de context van de programmeertalen C of Python.
|
|
||||||
Alle voorbeelden die je geeft, moeten in een van deze programmeertalen zijn.
|
|
||||||
|
|
||||||
Je maakt regelmatig gebruik van een emoticon en gebruikt veel markdown tenzij anders gevraagd wordt.
|
|
||||||
|
|
||||||
Geef in elk antwoord aan of de gekozen taal de juiste keuze is voor het beschreven probleem. Noem één alternatief als dat niet het geval is.
|
|
||||||
|
|
||||||
Als je wordt gevraagd om een review te doen:
|
|
||||||
- Geef de broncode een cijfer tussen 0 en 10.
|
|
||||||
- Geef een korte samenvatting van je review.
|
|
||||||
- Noem drie verbeterpunten voor de broncode.
|
|
||||||
- Noem drie sterke punten van de broncode.
|
|
||||||
|
|
||||||
Als je wordt gevraagd om te controleren op AI-gebruik:
|
|
||||||
- Verdeel de broncode in categorieën.
|
|
||||||
- Wijs elke categorie een percentage van AI-gebruik toe.
|
|
||||||
- Geef een conclusie over de authenticiteit van de code.
|
|
3
auth.h
3
auth.h
@ -7,9 +7,10 @@
|
|||||||
// MIT License
|
// MIT License
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
const char * resolve_api_key(){
|
const char * resolve_api_key(){
|
||||||
char * api_key;
|
static char * api_key = NULL;
|
||||||
#ifndef FREE_VERSION
|
#ifndef FREE_VERSION
|
||||||
api_key = getenv("R_KEY");
|
api_key = getenv("R_KEY");
|
||||||
if(api_key)
|
if(api_key)
|
||||||
|
6
http.h
6
http.h
@ -242,7 +242,7 @@ char *https_get(char *url)
|
|||||||
SSL_set_tlsext_host_name(ssl, hostname);
|
SSL_set_tlsext_host_name(ssl, hostname);
|
||||||
SSL_set_fd(ssl, sock);
|
SSL_set_fd(ssl, sock);
|
||||||
|
|
||||||
int buffer_size = 4096;
|
int buffer_size = 1024*1024;
|
||||||
char *buffer = (char *)malloc(buffer_size);
|
char *buffer = (char *)malloc(buffer_size);
|
||||||
|
|
||||||
if (SSL_connect(ssl) <= 0)
|
if (SSL_connect(ssl) <= 0)
|
||||||
@ -307,12 +307,12 @@ char *http_post(char *url, char *data)
|
|||||||
int port = atoi(parsed_url.port);
|
int port = atoi(parsed_url.port);
|
||||||
int sock = create_socket(hostname, port);
|
int sock = create_socket(hostname, port);
|
||||||
|
|
||||||
int buffer_size = 4096;
|
int buffer_size = 1024*1024;
|
||||||
char *buffer = malloc(buffer_size);
|
char *buffer = malloc(buffer_size);
|
||||||
size_t chunk_size_total = 0;
|
size_t chunk_size_total = 0;
|
||||||
|
|
||||||
size_t len = strlen(data);
|
size_t len = strlen(data);
|
||||||
char *request = malloc(len + 4096);
|
char *request = malloc(len + buffer_size);
|
||||||
sprintf(request,
|
sprintf(request,
|
||||||
"POST %s HTTP/1.1\r\n"
|
"POST %s HTTP/1.1\r\n"
|
||||||
"Content-Length: %ld\r\n"
|
"Content-Length: %ld\r\n"
|
||||||
|
3
line.h
3
line.h
@ -50,6 +50,9 @@ void line_init() {
|
|||||||
char* line_read(char* prefix) {
|
char* line_read(char* prefix) {
|
||||||
char* data = readline(prefix);
|
char* data = readline(prefix);
|
||||||
if (!(data && *data)) {
|
if (!(data && *data)) {
|
||||||
|
if(data){
|
||||||
|
free(data);
|
||||||
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
|
42
main.c
42
main.c
@ -38,32 +38,30 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
char * get_prompt_from_stdin() {
|
char * get_prompt_from_stdin(char * prompt) {
|
||||||
char * prompt = malloc(1024 * 1024 * 10 + 1);
|
|
||||||
prompt[0] = 0;
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
prompt[index] = '\0';
|
||||||
char c = 0;
|
char c = 0;
|
||||||
while ((c = getchar()) != EOF) {
|
while ((c = getchar()) != EOF) {
|
||||||
prompt[index++] = c;
|
prompt[index++] = c;
|
||||||
}
|
}
|
||||||
prompt[index++] = 0;
|
prompt[index++] = '\0';
|
||||||
return prompt;
|
return prompt;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *get_prompt_from_args(int c, char **argv) {
|
char *get_prompt_from_args(int c, char **argv) {
|
||||||
char *prompt = malloc(1024 * 1024 + 1);
|
char *prompt = malloc(1024 * 1024 * 10 + 1);
|
||||||
prompt[0] = 0;
|
prompt[0] = 0;
|
||||||
for (int i = 1; i < c; i++) {
|
for (int i = 1; i < c; i++) {
|
||||||
if (!strcmp(argv[i],"--stdin")){
|
if (!strcmp(argv[i],"--stdin")){
|
||||||
free(prompt);
|
prompt = get_prompt_from_stdin(prompt);
|
||||||
prompt = get_prompt_from_stdin();
|
|
||||||
break;
|
break;
|
||||||
}else{
|
}else{
|
||||||
strncat(prompt, argv[i], 1024 * 1024);
|
strcat(prompt, argv[i]);
|
||||||
if (i < c - 1) {
|
if (i < c - 1) {
|
||||||
strncat(prompt, " ", 1024 * 1024);
|
strcat(prompt, " ");
|
||||||
} else {
|
} else {
|
||||||
strncat(prompt, ".", 1024 * 1024);
|
strcat(prompt, ". ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -78,6 +76,11 @@ bool try_prompt(int argc, char *argv[]) {
|
|||||||
char *prompt = get_prompt_from_args(argc, argv);
|
char *prompt = get_prompt_from_args(argc, argv);
|
||||||
if (prompt != NULL) {
|
if (prompt != NULL) {
|
||||||
char *response = openai_chat("user", prompt);
|
char *response = openai_chat("user", prompt);
|
||||||
|
if(!response){
|
||||||
|
printf("Could not get response from server\n");
|
||||||
|
free(prompt);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
parse_markdown_to_ansi(response);
|
parse_markdown_to_ansi(response);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
free(response);
|
free(response);
|
||||||
@ -102,7 +105,7 @@ void render(char *content) {
|
|||||||
|
|
||||||
void repl() {
|
void repl() {
|
||||||
line_init();
|
line_init();
|
||||||
char *line;
|
char *line = NULL;
|
||||||
char *previous_line = NULL;
|
char *previous_line = NULL;
|
||||||
while ((line = line_read("> "))) {
|
while ((line = line_read("> "))) {
|
||||||
if (!line || !*line) {
|
if (!line || !*line) {
|
||||||
@ -139,7 +142,7 @@ void repl() {
|
|||||||
offset = 4;
|
offset = 4;
|
||||||
}
|
}
|
||||||
char *command = (char *)malloc(strlen(line) + 42);
|
char *command = (char *)malloc(strlen(line) + 42);
|
||||||
command[0] = 0;
|
command[0] = '\0';
|
||||||
strcpy(command, "ls ");
|
strcpy(command, "ls ");
|
||||||
strcat(command, line + offset);
|
strcat(command, line + offset);
|
||||||
int res = system(command);
|
int res = system(command);
|
||||||
@ -147,11 +150,12 @@ void repl() {
|
|||||||
free(command);
|
free(command);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if(*line){
|
||||||
line_add_history(line);
|
line_add_history(line);
|
||||||
char *response = openai_chat("user", line);
|
char *response = openai_chat("user", line);
|
||||||
render(response);
|
render(response);
|
||||||
free(response);
|
free(response);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,14 +192,14 @@ bool openai_include(char *path) {
|
|||||||
long size = ftell(file);
|
long size = ftell(file);
|
||||||
fseek(file, 0, SEEK_SET);
|
fseek(file, 0, SEEK_SET);
|
||||||
|
|
||||||
char *buffer = (char *)malloc(size);
|
char *buffer = (char *)malloc(size + 1);
|
||||||
size_t read = fread(buffer, 1, size, file);
|
size_t read = fread(buffer, 1, size, file);
|
||||||
if (read == 0) {
|
if (read == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(file);
|
fclose(file);
|
||||||
buffer[read] = 0;
|
buffer[read] = '\0';
|
||||||
openai_system(buffer);
|
openai_system(buffer);
|
||||||
|
|
||||||
free(buffer);
|
free(buffer);
|
||||||
|
@ -105,14 +105,9 @@ void parse_markdown_to_ansi(const char *markdown) {
|
|||||||
code_buffer[index] = 0;
|
code_buffer[index] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(index > 0){
|
code_buffer[index] = 0;
|
||||||
|
if(index)
|
||||||
highlight_code(code_buffer);
|
highlight_code(code_buffer);
|
||||||
index = 0;
|
|
||||||
code_buffer[index] = 0;
|
|
||||||
|
|
||||||
}
|
|
||||||
//code_buffer[index] = 0;
|
|
||||||
//highlight_code(code_buffer);
|
|
||||||
} else {
|
} else {
|
||||||
if (strncmp(ptr, "**", 2) == 0) {
|
if (strncmp(ptr, "**", 2) == 0) {
|
||||||
printf(BOLD);
|
printf(BOLD);
|
||||||
|
1
openai.h
1
openai.h
@ -39,6 +39,7 @@ char *openai_chat(char *role, char *content) {
|
|||||||
struct json_object *parsed_json = json_tokener_parse(result);
|
struct json_object *parsed_json = json_tokener_parse(result);
|
||||||
if (!parsed_json) {
|
if (!parsed_json) {
|
||||||
fprintf(stderr, "Failed to parse JSON.\n");
|
fprintf(stderr, "Failed to parse JSON.\n");
|
||||||
|
fprintf(stderr, "%s\n", result);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
4
plugin.h
4
plugin.h
@ -35,9 +35,13 @@ void plugin_run(char *src) {
|
|||||||
const char *basics =
|
const char *basics =
|
||||||
"import sys\n"
|
"import sys\n"
|
||||||
"import os\n"
|
"import os\n"
|
||||||
|
"from os import *\n"
|
||||||
"import math\n"
|
"import math\n"
|
||||||
"import pathlib\n"
|
"import pathlib\n"
|
||||||
|
"from pathlib import Path\n"
|
||||||
|
"import re\n"
|
||||||
"import subprocess\n"
|
"import subprocess\n"
|
||||||
|
"from subprocess import *\n"
|
||||||
"import time\n"
|
"import time\n"
|
||||||
"from datetime import datetime\n"
|
"from datetime import datetime\n"
|
||||||
"%s";
|
"%s";
|
||||||
|
Loading…
Reference in New Issue
Block a user