Compare commits

..

2 Commits

Author SHA1 Message Date
413c3b9599 Added auth. 2025-01-04 16:54:48 +01:00
c05edc45d9 Readme. 2025-01-04 16:21:07 +01:00
6 changed files with 54 additions and 17 deletions

2
.gitignore vendored
View File

@ -2,8 +2,6 @@
.venv
.history
.backup*
auth.h
context.txt
gpt
gpt.c
r

15
.rcontext.txt Normal file
View File

@ -0,0 +1,15 @@
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.

View File

@ -1,5 +1,7 @@
# 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 Normal file
View File

@ -0,0 +1,24 @@
// 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
View File

@ -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, api_key, data);
url, len, resolve_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, api_key);
url, resolve_api_key());
SSL_write(ssl, request, strlen(request));

24
main.c
View File

@ -86,7 +86,6 @@ void render(char *content) {
void repl() {
line_init();
setbuf(stdout, NULL);
char *line;
char *previous_line = NULL;
while ((line = line_read("> "))) {
@ -164,10 +163,10 @@ void help() {
render(help_text);
}
void openai_include(char *path) {
bool openai_include(char *path) {
FILE *file = fopen(path, "r");
if (file == NULL) {
return;
return false;
}
fseek(file, 0, SEEK_END);
long size = ftell(file);
@ -176,7 +175,7 @@ void openai_include(char *path) {
char *buffer = (char *)malloc(size);
size_t read = fread(buffer, 1, size, file);
if (read == 0) {
return;
return false;
}
fclose(file);
@ -184,22 +183,21 @@ void 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, "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...");
sprintf(payload, "Your locale is %s. User lang is %s.", locale, locale);
printf("%s", "Loading... ⏳");
openai_system(payload);
openai_include("context.txt");
printf("%s", "\rLoaded! Type help for features.\n");
if(!openai_include(".rcontext.txt")){
openai_include("~/.rcontext.txt");
}
printf("%s", "\r✅ Type help for features.\n");
}
int main(int argc, char *argv[]) {