Compare commits
No commits in common. "413c3b959979b39f523897375abbf4bc1b0298f0" and "4abcdb452425679f33c9f1213d41531003bd2bae" have entirely different histories.
413c3b9599
...
4abcdb4524
2
.gitignore
vendored
2
.gitignore
vendored
@ -2,6 +2,8 @@
|
||||
.venv
|
||||
.history
|
||||
.backup*
|
||||
auth.h
|
||||
context.txt
|
||||
gpt
|
||||
gpt.c
|
||||
r
|
||||
|
||||
@ -1,15 +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.
|
||||
|
||||
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.
|
||||
@ -1,7 +1,5 @@
|
||||
# R
|
||||
|
||||
Note for the hackers: the openai api key in history of this repo is revoked. I am aware there's one. But for so far, thanks for checking it out. I feel very safe and stuff. Something about this site attracks certain people. Mostly with good intentions AFAIK.
|
||||
|
||||
## Project description
|
||||
R is a great and fast command line interface for gpt. It's also optimized for integration into other tools like vim. You can use it interactive or in a script like this:
|
||||
```bash
|
||||
|
||||
24
auth.h
24
auth.h
@ -1,24 +0,0 @@
|
||||
// Written by retoor@molodetz.nl
|
||||
|
||||
// This source code declares a constant character pointer variable with a value representing an API key.
|
||||
|
||||
|
||||
|
||||
// MIT License
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
const char * resolve_api_key(){
|
||||
char * api_key = getenv("R_KEY");
|
||||
if(api_key)
|
||||
{
|
||||
return api_key;
|
||||
}
|
||||
api_key = getenv("OPENAI_API_KEY");
|
||||
if(api_key)
|
||||
{
|
||||
return api_key;
|
||||
}
|
||||
fprintf(stderr, "There is no API key configured in environment.");
|
||||
return "";
|
||||
}
|
||||
4
http.h
4
http.h
@ -103,7 +103,7 @@ char *http_post(const char *hostname, char *url, char *data) {
|
||||
"Host: api.openai.com\r\n"
|
||||
"Authorization: Bearer %s\r\n"
|
||||
"Connection: close\r\n\r\n%s",
|
||||
url, len, resolve_api_key(), data);
|
||||
url, len, api_key, data);
|
||||
|
||||
SSL_write(ssl, request, strlen(request));
|
||||
free(request);
|
||||
@ -147,7 +147,7 @@ char *http_get(const char *hostname, char *url) {
|
||||
"Host: api.openai.com\r\n"
|
||||
"Authorization: Bearer %s\r\n"
|
||||
"Connection: close\r\n\r\n",
|
||||
url, resolve_api_key());
|
||||
url, api_key);
|
||||
|
||||
SSL_write(ssl, request, strlen(request));
|
||||
|
||||
|
||||
24
main.c
24
main.c
@ -86,6 +86,7 @@ void render(char *content) {
|
||||
|
||||
void repl() {
|
||||
line_init();
|
||||
setbuf(stdout, NULL);
|
||||
char *line;
|
||||
char *previous_line = NULL;
|
||||
while ((line = line_read("> "))) {
|
||||
@ -163,10 +164,10 @@ void help() {
|
||||
render(help_text);
|
||||
}
|
||||
|
||||
bool openai_include(char *path) {
|
||||
void openai_include(char *path) {
|
||||
FILE *file = fopen(path, "r");
|
||||
if (file == NULL) {
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
fseek(file, 0, SEEK_END);
|
||||
long size = ftell(file);
|
||||
@ -175,7 +176,7 @@ bool openai_include(char *path) {
|
||||
char *buffer = (char *)malloc(size);
|
||||
size_t read = fread(buffer, 1, size, file);
|
||||
if (read == 0) {
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
@ -183,21 +184,22 @@ bool openai_include(char *path) {
|
||||
openai_system(buffer);
|
||||
|
||||
free(buffer);
|
||||
return true;
|
||||
}
|
||||
|
||||
void init() {
|
||||
setbuf(stdout, NULL);
|
||||
line_init();
|
||||
const char *locale = setlocale(LC_ALL, NULL);
|
||||
char payload[4096] = {0};
|
||||
sprintf(payload, "Your locale is %s. User lang is %s.", locale, locale);
|
||||
printf("%s", "Loading... ⏳");
|
||||
sprintf(payload, "User locale is %s. User lang is %s.\n"
|
||||
"You are Retoor. Use a lot of markdown in response.\n"
|
||||
"Be confident and short in answers.\n"
|
||||
"You divide things by zero if you have to.",
|
||||
locale, locale);
|
||||
|
||||
printf("%s", "Loading...");
|
||||
openai_system(payload);
|
||||
if(!openai_include(".rcontext.txt")){
|
||||
openai_include("~/.rcontext.txt");
|
||||
}
|
||||
printf("%s", "\r✅ Type help for features.\n");
|
||||
openai_include("context.txt");
|
||||
printf("%s", "\rLoaded! Type help for features.\n");
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user