test_projectindex.ts4 matches
6console.log("will this show up");
78export async function servePublicFile(path: string, metaImportUrl: string): Promise<Response> {
9const text = await readFile(path, metaImportUrl);
10const extname = tsToJSExtension(path).split(".").pop() ?? "";
17}
1819async function readFile(path: string, metaImportUrl: string) {
20const project = parseProject(metaImportUrl);
21const esmURL = project.links.module.projectPinned + path.slice(1);
46}
4748async function fetchText(url: string) {
49const res = await fetch(url, {
50headers: {
60}
6162function tsToJSExtension(path: string) {
63if (path.endsWith(".ts")) {
64return path.slice(0, -3) + ".js";
test_projectscript.ts5 matches
5import React, { useEffect, useState } from "https://esm.sh/react@18.2.0";
67function renderMath(text) {
8if (!text) return "";
9return text.replace(/\$\$(.*?)\$\$|\$(.*?)\$/g, (match, eq1, eq2) => {
21}
2223function App() {
24const [problem, setProblem] = useState(null);
25const [userAnswer, setUserAnswer] = useState("");
112<ul>
113<li>
114Functions: <code>sin(x)</code>, <code>cos(x)</code>, <code>tan(x)</code>
115</li>
116<li>
117Inverse functions: <code>arcsin(x)</code> or <code>sin^{-1}(x)</code>
118</li>
119<li>
162}
163164function client() {
165createRoot(document.getElementById("root")).render(<App />);
166}
test_projectmain.js19 matches
7* Remove common variations of "+ C" at the end of an indefinite integral.
8*/
9function stripPlusC(str) {
10return str.replace(/\+\s*c\s*$/i, "").trim();
11}
15* Remove or replace common LaTeX constructs.
16*/
17function latexToExpression(latex) {
18// Remove display math delimiters: $$...$$ or $...$
19let expr = latex.replace(/\${1,2}/g, "");
22expr = expr.replace(/\\frac\s*\{([^}]+)\}\s*\{([^}]+)\}/g, "($1)/($2)");
2324// Some common function replacements for Algebrite
25expr = expr.replace(/\\sin/g, "sin");
26expr = expr.replace(/\\cos/g, "cos");
46* Return the simplified string or null on error.
47*/
48function parseAndSimplify(expr) {
49try {
50// If it's an empty string, treat that as invalid
59* Check if two expressions (already simplified) differ by at most a constant.
60*/
61function differByConstant(simpl1, simpl2) {
62try {
63const diff = Algebrite.simplify(`(${simpl1}) - (${simpl2})`).toString();
74* Symbolic check: compare simplified forms, then see if they differ by a constant.
75*/
76function symbolicCheck(expr1, expr2) {
77const s1 = parseAndSimplify(expr1);
78const s2 = parseAndSimplify(expr2);
85* Evaluate an expression numerically at x, returning a float or null if invalid.
86*/
87function safeEval(expr, x) {
88try {
89const val = parseFloat(Algebrite.eval(expr, { x }).toString());
100* If the difference changes by more than a small tolerance, we reject it.
101*/
102function numericCheck(expr1, expr2, samples = [-2, 0, 2]) {
103const diffs = [];
104125* Loose equivalence: first do a symbolic check, if that fails, do numeric check.
126*/
127function expressionsAreLooselyEquivalent(expr1, expr2) {
128// 1) Symbolic check
129if (symbolicCheck(expr1, expr2)) {
137* GPT-4 call to generate a new math problem.
138*/
139async function handleProblemGeneration() {
140const openai = new OpenAI();
141const completion = await openai.chat.completions.create({
153},
154],
155functions: [
156{
157name: "generate_math_problem",
177},
178],
179function_call: { name: "generate_math_problem" },
180});
181182const functionCall = completion.choices[0].message.function_call;
183if (!functionCall || functionCall.name !== "generate_math_problem") {
184return new Response("Failed to generate problem", { status: 500 });
185}
187let problem;
188try {
189problem = JSON.parse(functionCall.arguments);
190} catch (error) {
191console.error("Failed to parse function call arguments:", error);
192console.log("Raw arguments:", functionCall.arguments);
193return new Response("Failed to generate problem", { status: 500 });
194}
213* - Return result
214*/
215async function handleAnswerCheck(request) {
216const { answer, problemId } = await request.json();
217const problem = await blob.getJSON(`problem_${problemId}`);
257* Main request handler.
258*/
259export default async function(req: Request): Promise<Response> {
260const url = new URL(req.url);
261
test_projectemailReminder1 match
1import { email } from "https://esm.town/v/std/email?v=13";
23export default async function(interval: Interval) {
4console.log(`math problem`);
5email({
1import { blob } from "https://esm.town/v/std/blob?v=10";
23export default async function(request: Request): Promise<Response> {
4const requestUrl = new URL(request.url);
5
researchAgentemailHandler2 matches
4import { OpenAI } from "npm:openai";
56function pm(...lines: string[]): string {
7return lines.join("\n");
8}
910export async function emailValHandler(inboundEmail: Email) {
11const userPrompt = pm(
12`From: ${inboundEmail.from}`,
researchAgentemailHandler2 matches
4import { OpenAI } from "npm:openai";
56function pm(...lines: string[]): string {
7return lines.join("\n");
8}
910export async function emailValHandler(inboundEmail: Email) {
11const userPrompt = pm(
12`From: ${inboundEmail.from}`,
1import { emailValHandler } from "./emailHandler";
23export default async function(interval: Interval) {
4const today = new Intl.DateTimeFormat("en-US", {
5month: "short",
12import { servePublicFile } from "https://esm.town/v/stevekrouse/utils@179-main/serve-public/index.ts";
1314export default async function(req: Request): Promise<Response> {
15const url = new URL(req.url);
16if (url.pathname === "/") {
13interface TestCase {
14name: string;
15function: () => void;
16}
1718interface TestCaseResult {
19name: string;
20function: () => void;
21passed: boolean;
22duration: number;
23}
2425async function runTest(test: TestCase) {
26let pass, message;
27let start = performance.now();
28try {
29await test.function();
30pass = true;
31} catch (e: any) {
40}
4142function renderBadge({ label, passedCount, testCount }: { label?: string; passedCount: number; testCount: number }) {
43return makeBadge({
44label: label ?? "Tests",
48}
4950function Badge({ label, passedCount, testCount }: { label?: string; passedCount: number; testCount: number }) {
51const svgMarkup = renderBadge({ label, passedCount, testCount });
52const srcDoc = `<body style="margin: 0"}>${svgMarkup}</body>`;
62}
6364function renderTestResults(testGroups: TestGroup[], outputs: { [groupName: string]: TestOutput[] }) {
65const totalPassed = Object.values(outputs).flat().filter((output: TestOutput) => output.pass).length;
66const totalTests = testGroups.reduce((sum, group) => sum + group.tests.length, 0);