// Name: OpenAI Playground with web search // Description: Query Open AI's API via response api and use websearch tool // Keyword: ai import "@johnlindquist/kit"; import OpenAI from "openai"; const openai = new OpenAI({ apiKey: await env("OPENAI_API_KEY"), }); let currentPanel: string = ``; let lastResponse: string = ``; while (true) { const content = await micro( { input: "", placeholder: "Prompt OpenAI", strict: false, onEscape: () => { exit(); }, shortcuts: [ { name: "Copy Response", key: `${cmd}+c`, onPress: async () => { if (lastResponse) { await copy(lastResponse); await toast("Response copied to clipboard!"); } else { await toast("No response to copy yet"); } }, bar: "right", visible: false } ] }, currentPanel ); setLoading(true); const response = await openai.responses.create({ model: "gpt-4.1-mini", tools: [ { type: "web_search_preview" } ], input: content || "Prompt missing?", instructions: "You are a helpful assistant with web access, today is " + Date }); const result = response?.output_text; lastResponse = result; currentPanel = md(result); setLoading(false); }