Compare commits
2 Commits
d0697da15e
...
e02315a0f6
| Author | SHA1 | Date | |
|---|---|---|---|
| e02315a0f6 | |||
| c0f5be662a |
3
.gitignore
vendored
3
.gitignore
vendored
@ -8,4 +8,5 @@ r
|
||||
rf
|
||||
.docs
|
||||
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.
|
||||
5
auth.h
5
auth.h
@ -7,9 +7,10 @@
|
||||
// MIT License
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
const char * resolve_api_key(){
|
||||
char * api_key;
|
||||
static char * api_key = NULL;
|
||||
#ifndef FREE_VERSION
|
||||
api_key = getenv("R_KEY");
|
||||
if(api_key)
|
||||
@ -26,4 +27,4 @@ const char * resolve_api_key(){
|
||||
#endif
|
||||
api_key = "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";
|
||||
return 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_fd(ssl, sock);
|
||||
|
||||
int buffer_size = 4096;
|
||||
int buffer_size = 1024*1024;
|
||||
char *buffer = (char *)malloc(buffer_size);
|
||||
|
||||
if (SSL_connect(ssl) <= 0)
|
||||
@ -307,12 +307,12 @@ char *http_post(char *url, char *data)
|
||||
int port = atoi(parsed_url.port);
|
||||
int sock = create_socket(hostname, port);
|
||||
|
||||
int buffer_size = 4096;
|
||||
int buffer_size = 1024*1024;
|
||||
char *buffer = malloc(buffer_size);
|
||||
size_t chunk_size_total = 0;
|
||||
|
||||
size_t len = strlen(data);
|
||||
char *request = malloc(len + 4096);
|
||||
char *request = malloc(len + buffer_size);
|
||||
sprintf(request,
|
||||
"POST %s HTTP/1.1\r\n"
|
||||
"Content-Length: %ld\r\n"
|
||||
|
||||
5
line.h
5
line.h
@ -50,6 +50,9 @@ void line_init() {
|
||||
char* line_read(char* prefix) {
|
||||
char* data = readline(prefix);
|
||||
if (!(data && *data)) {
|
||||
if(data){
|
||||
free(data);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
return data;
|
||||
@ -59,4 +62,4 @@ void line_add_history(char* data) {
|
||||
read_history(HISTORY_FILE);
|
||||
add_history(data);
|
||||
write_history(HISTORY_FILE);
|
||||
}
|
||||
}
|
||||
|
||||
54
main.c
54
main.c
@ -38,17 +38,31 @@
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
char * get_prompt_from_stdin(char * prompt) {
|
||||
int index = 0;
|
||||
prompt[index] = '\0';
|
||||
char c = 0;
|
||||
while ((c = getchar()) != EOF) {
|
||||
prompt[index++] = c;
|
||||
}
|
||||
prompt[index++] = '\0';
|
||||
return prompt;
|
||||
}
|
||||
|
||||
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;
|
||||
for (int i = 1; i < c; i++) {
|
||||
if (argv[i][0] == '-')
|
||||
if (!strcmp(argv[i],"--stdin")){
|
||||
prompt = get_prompt_from_stdin(prompt);
|
||||
break;
|
||||
strncat(prompt, argv[i], 1024 * 1024);
|
||||
if (i < c - 1) {
|
||||
strncat(prompt, " ", 1024 * 1024);
|
||||
} else {
|
||||
strncat(prompt, ".", 1024 * 1024);
|
||||
}else{
|
||||
strcat(prompt, argv[i]);
|
||||
if (i < c - 1) {
|
||||
strcat(prompt, " ");
|
||||
} else {
|
||||
strcat(prompt, ". ");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!*prompt) {
|
||||
@ -62,6 +76,11 @@ bool try_prompt(int argc, char *argv[]) {
|
||||
char *prompt = get_prompt_from_args(argc, argv);
|
||||
if (prompt != NULL) {
|
||||
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);
|
||||
printf("\n");
|
||||
free(response);
|
||||
@ -86,7 +105,7 @@ void render(char *content) {
|
||||
|
||||
void repl() {
|
||||
line_init();
|
||||
char *line;
|
||||
char *line = NULL;
|
||||
char *previous_line = NULL;
|
||||
while ((line = line_read("> "))) {
|
||||
if (!line || !*line) {
|
||||
@ -123,7 +142,7 @@ void repl() {
|
||||
offset = 4;
|
||||
}
|
||||
char *command = (char *)malloc(strlen(line) + 42);
|
||||
command[0] = 0;
|
||||
command[0] = '\0';
|
||||
strcpy(command, "ls ");
|
||||
strcat(command, line + offset);
|
||||
int res = system(command);
|
||||
@ -131,11 +150,12 @@ void repl() {
|
||||
free(command);
|
||||
continue;
|
||||
}
|
||||
|
||||
line_add_history(line);
|
||||
char *response = openai_chat("user", line);
|
||||
render(response);
|
||||
free(response);
|
||||
if(*line){
|
||||
line_add_history(line);
|
||||
char *response = openai_chat("user", line);
|
||||
render(response);
|
||||
free(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -172,14 +192,14 @@ bool openai_include(char *path) {
|
||||
long size = ftell(file);
|
||||
fseek(file, 0, SEEK_SET);
|
||||
|
||||
char *buffer = (char *)malloc(size);
|
||||
char *buffer = (char *)malloc(size + 1);
|
||||
size_t read = fread(buffer, 1, size, file);
|
||||
if (read == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
buffer[read] = 0;
|
||||
buffer[read] = '\0';
|
||||
openai_system(buffer);
|
||||
|
||||
free(buffer);
|
||||
@ -211,4 +231,4 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
repl();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
21
markdown.h
21
markdown.h
@ -46,15 +46,15 @@ int is_keyword(const char *word) {
|
||||
|
||||
void highlight_code(const char *code) {
|
||||
const char *ptr = code;
|
||||
char buffer[256];
|
||||
char buffer[4096];
|
||||
size_t index = 0;
|
||||
|
||||
buffer[index] = 0;
|
||||
while (*ptr) {
|
||||
if ((*ptr >= 'a' && *ptr <= 'z') || (*ptr >= 'A' && *ptr <= 'Z') || (*ptr == '_')) {
|
||||
while ((*ptr >= 'a' && *ptr <= 'z') || (*ptr >= 'A' && *ptr <= 'Z') || (*ptr >= '0' && *ptr <= '9') || (*ptr == '_')) {
|
||||
buffer[index++] = *ptr++;
|
||||
}
|
||||
buffer[index] = '\0';
|
||||
buffer[index] = 0;
|
||||
|
||||
if (is_keyword(buffer)) {
|
||||
printf(FG_BLUE "%s" RESET, buffer);
|
||||
@ -66,7 +66,7 @@ void highlight_code(const char *code) {
|
||||
while (*ptr >= '0' && *ptr <= '9') {
|
||||
buffer[index++] = *ptr++;
|
||||
}
|
||||
buffer[index] = '\0';
|
||||
buffer[index] = 0;
|
||||
printf(FG_CYAN "%s" RESET, buffer);
|
||||
index = 0;
|
||||
} else {
|
||||
@ -93,14 +93,21 @@ void parse_markdown_to_ansi(const char *markdown) {
|
||||
}
|
||||
|
||||
if (inside_code) {
|
||||
char code_buffer[256];
|
||||
char code_buffer[4096];
|
||||
size_t index = 0;
|
||||
|
||||
while (*ptr && *ptr != '`') {
|
||||
code_buffer[index++] = *ptr++;
|
||||
if(*ptr == '\n' || *ptr == ' ' || *ptr == '\t' || *ptr == '.'){
|
||||
code_buffer[index++] = 0;
|
||||
highlight_code(code_buffer);
|
||||
index = 0;
|
||||
code_buffer[index] = 0;
|
||||
}
|
||||
}
|
||||
code_buffer[index] = '\0';
|
||||
highlight_code(code_buffer);
|
||||
code_buffer[index] = 0;
|
||||
if(index)
|
||||
highlight_code(code_buffer);
|
||||
} else {
|
||||
if (strncmp(ptr, "**", 2) == 0) {
|
||||
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);
|
||||
if (!parsed_json) {
|
||||
fprintf(stderr, "Failed to parse JSON.\n");
|
||||
fprintf(stderr, "%s\n", result);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
6
plugin.h
6
plugin.h
@ -35,9 +35,13 @@ void plugin_run(char *src) {
|
||||
const char *basics =
|
||||
"import sys\n"
|
||||
"import os\n"
|
||||
"from os import *\n"
|
||||
"import math\n"
|
||||
"import pathlib\n"
|
||||
"from pathlib import Path\n"
|
||||
"import re\n"
|
||||
"import subprocess\n"
|
||||
"from subprocess import *\n"
|
||||
"import time\n"
|
||||
"from datetime import datetime\n"
|
||||
"%s";
|
||||
@ -52,4 +56,4 @@ void plugin_run(char *src) {
|
||||
void plugin_destruct() {
|
||||
if (plugin_initialized)
|
||||
Py_Finalize();
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user