You can access search results via JSON API by adding format=json
to your query:
https://codesearch.val.run/image-url.jpg%20%22Optional%20title%22?q=openai&page=3&format=json
For typeahead suggestions, use the /typeahead
endpoint:
https://codesearch.val.run/typeahead?q=openai
Returns an array of strings in format "username" or "username/projectName"
Found 1586 results for "openai"(775ms)
100Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
101102### OpenAI
103```ts
104import { OpenAI } from "https://esm.town/v/std/openai";
105const openai = new OpenAI();
106const completion = await openai.chat.completions.create({
107messages: [
108{ role: "user", content: "Say hello in a creative way" },
11* and also to upload new resources.
12* * It utilizes the LLM-Safe Fork of @std/sqlite (adjust import if necessary).
13* Assumes 'openai' secret is set in Val Town environment variables.
14* * Last Updated: 2025-05-08 (SQLite refactor, Glassmorphic UI, and Upload Form)
15*/
625export default async function(req: Request) {
626// --- Dynamic Imports (Inside Handler for Val Town) ---
627const { OpenAI } = await import("https://esm.town/v/std/openai");
628const val_fetch = (await import("https://esm.town/v/std/fetch")).fetch;
629const { PDFExtract } = await import("npm:pdf.js-extract");
653}
654655// --- Helper Function: Call OpenAI API ---
656async function callOpenAI(
657openai: OpenAI,
658systemPrompt: string,
659userMessage: string,
662): Promise<{ role: "assistant" | "system"; content: string | object }> {
663try {
664const response = await openai.chat.completions.create({
665model,
666messages: [{ role: "system", content: systemPrompt }, { role: "user", content: userMessage }],
680return { role: "assistant", content };
681} catch (error) {
682console.error(`OpenAI call failed (ExpectJSON: ${expectJson}):`, error);
683let msg = "Error communicating with AI.";
684if (error.message) msg += ` Details: ${error.message}`;
685if ((error as any).status === 401) msg = "OpenAI Auth Error. Check your 'openai' secret in Val Town.";
686if ((error as any).status === 429) msg = "OpenAI Rate Limit Exceeded.";
687return { role: "system", content: msg };
688}
694log: LogEntry[],
695): Promise<{ finalLog: LogEntry[]; extractedTagsCount: number; documentIdentifier: string | null }> {
696const openai = new OpenAI();
697log.push({ agent: "System", type: "step", message: "Workflow started." });
698805log.push({ agent: "System", type: "step", message: "Extracting searchable tags with LLM..." });
806const tagAgent = "Autism Tag Extraction Agent";
807const llmResponse = await callOpenAI(openai, autismTagExtractionSystemPrompt, textToAnalyze, "gpt-4o", true);
808809let extractedTags: string[] = [];