Search
Code3,210
// Converts arbitrary text into a strict JSON object and returns the `results` arrayexport async function extractOrRepairJsonResults(rawText, apiKey, language = 'english') { const response = await fetch('https://api.groq.com/openai/v1/chat/completions', { method: 'POST', headers: { }, body: JSON.stringify({ model: 'openai/gpt-oss-120b', messages: [ {// This helper instructs the model to ONLY use URLs that appear in the provided text and never invent new ones.export async function extractResultsFromToolOutputs(toolText, apiKey, language = 'english') { const response = await fetch('https://api.groq.com/openai/v1/chat/completions', { method: 'POST', headers: { }, body: JSON.stringify({ model: 'openai/gpt-oss-120b', messages: [ {// Structured summary extraction to eliminate citation artifacts and enforce clean fieldsexport async function extractStructuredSummary(rawText, apiKey) { const response = await fetch('https://api.groq.com/openai/v1/chat/completions', { method: 'POST', headers: { }, body: JSON.stringify({ model: 'openai/gpt-oss-120b', messages: [ { if (reasoningText && String(reasoningText).trim()) parts.push('Reasoning text:\n' + String(reasoningText)); const response = await fetch('https://api.groq.com/openai/v1/chat/completions', { method: 'POST', headers: { }, body: JSON.stringify({ model: 'openai/gpt-oss-120b', messages: [ { if (reasoningText && String(reasoningText).trim()) parts.push('Reasoning text:\n' + String(reasoningText)); const response = await fetch('https://api.groq.com/openai/v1/chat/completions', { method: 'POST', headers: { }, body: JSON.stringify({ model: 'openai/gpt-oss-120b', messages: [ {
Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.### OpenAI```tsimport { OpenAI } from "https://esm.town/v/std/openai";const openai = new OpenAI();const completion = await openai.chat.completions.create({ messages: [ { role: "user", content: "Say hello in a creative way" },
Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.### OpenAI```tsimport { OpenAI } from "https://esm.town/v/std/openai";const openai = new OpenAI();const completion = await openai.chat.completions.create({ messages: [ { role: "user", content: "Say hello in a creative way" },
// @ts-ignoreimport { OpenAI } from "https://esm.town/v/std/openai?v=4";// --- AI BEHAVIORAL GUIDELINES --- if (req.method === "POST" && action === "getAstrology") { try { const openai = new OpenAI(); const { planetaryData } = await req.json(); }`; const completion = await openai.chat.completions.create({ model: "gpt-4o", messages: [
import { Hono } from "npm:hono@4.4.12";// @ts-ignoreimport { OpenAI } from "https://esm.town/v/std/openai?v=4";// --- TownCar: The JIT Journey Engine v4.0 (Autonomous Route Architect) ---const app = new Hono();async function callOpenAI(c, messages, response_format = { type: "text" }) { const openai = new OpenAI(); const completion = await openai.chat.completions.create({ model: "gpt-4o", messages: messages, content: META_PROMPTS.ROUTE_PLANNER.replace("{{goal}}", goal), }]; const planJson = await callOpenAI(c, messages, { type: "json_object" }); return c.json(JSON.parse(planJson)); } catch (e) { content: META_PROMPTS.ROUTE_PLANNER_RETRY.replace("{{goal}}", goal), }]; const retryPlanJson = await callOpenAI(c, retryMessages, { type: "json_object", }); ), }]; const specJson = await callOpenAI(c, architectMessages, { type: "json_object", }); content: META_PROMPTS.UI_BUILDER.replace("{{spec}}", specJson), }]; uiJson = await callOpenAI(c, uiBuilderMessages, { type: "json_object" }); } return c.json({ taskSpecification: spec, uiSchema: JSON.parse(uiJson) }); const { task, context, inputs } = await c.req.json(); const contextString = JSON.stringify(context, null, 2); const specJson = await callOpenAI(c, [{ role: "system", content: META_PROMPTS.STOP_ARCHITECT.replace("{{task}}", task).replace( ), }], { type: "json_object" }); let executionPrompt = await callOpenAI(c, [{ role: "system", content: META_PROMPTS.LOGIC_WEAVER.replace("{{spec}}", specJson) ); } const openai = new OpenAI(); const aiStream = await openai.chat.completions.create({ model: "gpt-4o", messages: [{ role: "user", content: executionPrompt }],
import { openai } from "npm:@ai-sdk/openai";import { generateText, tool } from "npm:ai";import { z } from "npm:zod@3.25.75";const { text } = await generateText({ model: openai("gpt-4.1"), tools: { checkWeather: tool({
# OpenAI ProxyThis OpenAI API proxy injects Val Town's API keys. For usage documentation, check out https://www.val.town/v/std/openai
// Proxy the request const url = new URL("." + pathname, "https://api.openai.com"); url.search = search; const headers = new Headers(req.headers); headers.set("Host", url.hostname); headers.set("Authorization", `Bearer ${Deno.env.get("OPENAI_API_KEY")}`); headers.set("OpenAI-Organization", Deno.env.get("OPENAI_API_ORG")); const openAIRes = await fetch(url, { method: req.method, headers, }); const res = new Response(openAIRes.body, openAIRes); // Remove internal header res.headers.delete("openai-organization"); return res;
COUNT(*) AS count FROM openai_usage, params WHERE};export class OpenAIUsage { constructor() {} async migrate() { await sqlite.batch([`CREATE TABLE IF NOT EXISTS openai_usage ( id INTEGER PRIMARY KEY, user_id TEXT NOT NULL, } async drop() { await sqlite.batch([`DROP TABLE IF EXISTS openai_usage`]); } async writeUsage(ur: UsageRow) { sqlite.execute({ sql: "INSERT INTO openai_usage (user_id, handle, tier, tokens, model) VALUES (?, ?, ?, ?, ?)", args: [ur.userId, ur.handle, ur.tier, ur.tokens, ur.model], }); let resp = await sqlite.execute({ sql: `SELECT count(*) FROM openai_usage WHERE ( (model LIKE 'gpt-4%' AND model NOT LIKE '%mini%')
import { OpenAIUsage } from "https://esm.town/v/std/OpenAIUsage";const client = new OpenAIUsage();const t0 = performance.now();
reconsumeralization
import { OpenAI } from "https://esm.town/v/std/openai";
import { sqlite } from "https://esm.town/v/stevekrouse/sqlite";
/**
* Practical Implementation of Collective Content Intelligence
* Bridging advanced AI with collaborative content creation
*/
exp
kwhinnery_openai
lost1991
import { OpenAI } from "https://esm.town/v/std/openai";
export default async function(req: Request): Promise<Response> {
if (req.method === "OPTIONS") {
return new Response(null, {
headers: {
"Access-Control-Allow-Origin": "*",
No docs found