Compare commits

...

3 Commits

Author SHA1 Message Date
57c6619ce9 Cleanup. 2025-03-30 01:48:51 +01:00
59000167da clean. 2025-03-30 01:48:35 +01:00
213b6b0578 Cleanup. 2025-03-30 01:47:00 +01:00
10 changed files with 1 additions and 202 deletions

1
.gitignore vendored
View File

@ -11,3 +11,4 @@ auth.h
.rcontext*
tests
rpylib.so
rd

View File

@ -1,32 +0,0 @@
#!/usr/bin/env python3
# Not written by retoor! This is generated boiler plate to give an example!
import cgi
import cgitb
from xmlrpc.client import ServerProxy
client = ServerProxy("https://api.molodetz.nl/rpc")
ask_gpt = client.gpt4o_mini
cgitb.enable()
print("Content-Type: text/html")
print()
import pathlib
form = cgi.FieldStorage()
question = form.getvalue("question", "")
page_source = pathlib.Path(__file__).parent.joinpath("gpt_template.html").read_text()
if question:
try:
response = ask_gpt(question)
except Exception as e:
response = f"Error: {e}"
page_source = page_source.replace("...", response)
page_source = page_source.replace("display:none;","")
print(page_source)

View File

@ -1,64 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>GPT Example</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f4f4f9;
}
.container {
max-width: 600px;
margin: 50px auto;
padding: 20px;
background: #fff;
border-radius: 8px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}
h1 {
color: #333;
text-align: center;
}
textarea, input {
width: 100%;
padding: 10px;
margin: 10px 0;
font-size: 16px;
border: 1px solid #ddd;
border-radius: 4px;
}
input[type="submit"] {
background-color: #4CAF50;
color: white;
cursor: pointer;
}
input[type="submit"]:hover {
background-color: #45a049;
}
.response-box {
padding: 10px;
background: #f9f9f9;
border: 1px solid #ddd;
border-radius: 4px;
min-height: 100px;
}
</style>
</head>
<body>
<div class="container">
<h1>Ask GPT</h1>
<div style="display:none;" class="response-box">
<p id="response">...</p>
</div>
<form action="/cgi-bin/gpt.py" method="post">
<textarea name="question" rows="4" placeholder="Your prompt.."></textarea>
<input type="submit" value="Get Answer">
</form>
</div>
</body>
</html>

View File

@ -1,50 +0,0 @@
// Written by retoor@molodetz.nl
// This source code extracts URLs from an input string and replaces them inline
// with their respective content in Markdown style.
// Imports used: regex.h for regular expression operations, http.h and url.h for
// HTTP and URL-related utility functions.
// MIT License
#include "http.h"
#include "url.h"
#include <regex.h>
#include <stdlib.h>
#include <string.h>
void extract_urls(const char *input, char **urls, int *url_count) {
const char *pattern = "https?://[^ ]+";
regex_t regex;
regcomp(&regex, pattern, REG_EXTENDED);
regmatch_t match;
const char *cursor = input;
*url_count = 0;
while (!regexec(&regex, cursor, 1, &match, 0)) {
int length = match.rm_eo - match.rm_so;
urls[*url_count] = strndup(cursor + match.rm_so, length);
cursor += match.rm_eo;
(*url_count)++;
}
regfree(&regex);
}
void inplace_urls_markdown_style(char **input, char **urls, char **contents,
int url_count) {
for (int i = 0; i < url_count; i++) {
char *found = strstr(*input, urls[i]);
if (found) {
char *new_text = (char *)malloc(strlen(*input) + strlen(contents[i]) -
strlen(urls[i]) + 1);
strncpy(new_text, *input, found - *input);
new_text[found - *input] = '\0';
strcat(new_text, contents[i]);
strcat(new_text, found + strlen(urls[i]));
free(*input);
*input = new_text;
}
}
}

12
main.c
View File

@ -163,14 +163,6 @@ void repl() {
continue;
}
if (!strncmp(line, "exit", 4)) exit(0);
if (!strncmp(line, "help", 4)) {
help();
continue;
}
if (!strncmp(line, "!debug", 6)) {
r_malloc_stats();
continue;
}
while (line && *line != '\n') {
char *response = openai_chat("user", line);
@ -190,10 +182,6 @@ void repl() {
}
}
void help() {
const char * help_text = "Written by retoor@molodetz.nl\n\n";
render(help_text);
}
char *strreplace(const char *content, const char *what, const char *with) {
char *pos = strstr(content, what);

View File

@ -1 +0,0 @@
#include "malloc.h"

View File

@ -1,33 +0,0 @@
#ifndef R_MALLOC
#define R_MALLOC
#include <malloc.h>
long long int r_malloc_alloc_count = 0;
long long int r_malloc_alloc_total = 0;
void *r_malloc(size_t size) {
r_malloc_alloc_count++;
r_malloc_alloc_total++;
return malloc(size);
}
void r_free(void *ptr) {
r_malloc_alloc_count--;
free(ptr);
}
void r_malloc_stats() {
fprintf(stderr, "r_malloc_alloc_count: %lld\n", r_malloc_alloc_count);
fprintf(stderr, "r_malloc_alloc_total: %lld\n", r_malloc_alloc_total);
fprintf(stderr, "r_malloc_freed_total: %lld\n",
r_malloc_alloc_total - r_malloc_alloc_count);
}
#define malloc(x) r_malloc(x)
#define free(x) r_free(x)
#include <stdio.h>
#endif

1
r.h
View File

@ -1,7 +1,6 @@
#ifndef R_H
#define R_H
#include "auth.h"
#include "malloc.h"
#include "utils.h"
#include <stdbool.h>
#include <string.h>

BIN
rpylib.so

Binary file not shown.

View File

@ -1,9 +0,0 @@
#!/bin/bash
echo "This is a sample shell script."
echo "Running some commands..."
# Add your commands below
# Example command
ls -la