maine-bills-taxsummarize.ts3 matches
1import { ChatCompletion, SearchResult } from "https://esm.town/v/cmknz/maine-bills-tax/types.ts";
2import { OpenAI } from "https://esm.town/v/std/openai";
34const openai = new OpenAI();
56const prompt =
2425// Prompt request
26const chatPromise: Promise<ChatCompletion> = openai.chat.completions.create({
27messages: [
28{ role: "user", content: prompt + ": " + extractImportantInfo },
4// SERVER-SIDE LOGIC (TypeScript)
5// =============================================================================
6import { OpenAI } from "https://esm.town/v/std/openai";
78// --- Configuration ---
23maskSrc?: string; // Used for holo mask layer
24}
25interface OpenAIResponse {
26races: RaceInfo[];
27}
96];
9798// --- OpenAI Generation Function ---
99// <<< No changes needed in OpenAI function logic itself >>>
100async function generateRaceDataWithOpenAI(): Promise<RaceInfo[]> {
101const openai = new OpenAI();
102const numToRequest = Math.max(1, NUM_CARDS_TO_GENERATE);
103const prompt =
112Return STRICTLY as a single JSON object: { "races": [ { race1 }, { race2 }, ... ] }. No introductory text or explanations outside the JSON structure.`;
113try {
114console.info(`Requesting ${numToRequest} race data generation from OpenAI...`);
115const completion = await openai.chat.completions.create({
116model: "gpt-4o",
117messages: [{ role: "user", content: prompt }],
120});
121const rawContent = completion.choices[0]?.message?.content;
122if (!rawContent) throw new Error("OpenAI returned an empty response message.");
123124let parsedJson;
126parsedJson = JSON.parse(rawContent);
127} catch (parseError) {
128console.error("Failed to parse OpenAI JSON response:", parseError);
129console.error("Raw OpenAI response:", rawContent);
130throw new Error(`JSON Parsing Error: ${parseError.message}`);
131}
147) {
148console.warn(
149`OpenAI response JSON failed validation for ${numToRequest} races:`,
150JSON.stringify(parsedJson, null, 2),
151);
152throw new Error(
153"OpenAI response JSON structure, count, data types, color format, hint value, or mask URL invalid.",
154);
155}
156// --- End Validation ---
157158const generatedData = (parsedJson as OpenAIResponse).races.map(race => ({
159...race,
160borderAnimationHint: race.borderAnimationHint || "none",
161// No need to override maskSrc here, default is handled in client script
162}));
163console.info(`Successfully generated and validated ${generatedData.length} races from OpenAI.`);
164return generatedData;
165} catch (error) {
166console.error("Error fetching or processing data from OpenAI:", error);
167console.warn("Using fallback race data due to the error.");
168return fallbackRaceData.slice(0, numToRequest).map(race => ({
175// --- Main HTTP Handler (Val Town Entry Point) ---
176export default async function server(request: Request): Promise<Response> {
177const activeRaceData = await generateRaceDataWithOpenAI();
178179// Define CSS Styles
lite-britelitebrite.ts4 matches
1// liteBriteGPTHTTP.val.ts
2// Set OPENAI_API_KEY as a secret on Val Town first.
34import OpenAI from "npm:openai"; // works in Deno/Val Town
5const openai = new OpenAI({ apiKey: Deno.env.get("OPENAI_API_KEY")! });
67const WIDTH = 60, HEIGHT = 40;
67if (pathname === "/draw") {
68const idea = searchParams.get("prompt") ?? "smiley face";
69const chat = await openai.chat.completions.create({
70model: "gpt-4o-mini",
71temperature: 0.7,
stevensDemo.cursorrules4 matches
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" },
1import { email } from "https://esm.town/v/std/email";
2import { OpenAI } from "https://esm.town/v/std/openai";
3import { JSDOM } from "npm:jsdom";
4import { NodeHtmlMarkdown, NodeHtmlMarkdownOptions } from "npm:node-html-markdown";
16);
1718const openai = new OpenAI();
19console.log(trendingMarkdown);
2021const completion = await openai.chat.completions.create({
22messages: [
23{
remote-evalparameters.eval.ts3 matches
1import { Levenshtein } from "npm:autoevals";
2import { Eval, initDataset, wrapOpenAI } from "npm:braintrust";
3import OpenAI from "npm:openai";
4import { z } from "npm:zod";
56const client = wrapOpenAI(new OpenAI());
78Eval("Simple eval", {
stevensDemo.cursorrules4 matches
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" },
testOpenAInew-file-2085.tsx3 matches
1import { OpenAI } from "https://esm.town/v/std/openai";
23const openai = new OpenAI();
45const completion = await openai.chat.completions.create({
6messages: [
7{ role: "user", content: "Say hello in a creative way" },
testOpenAInew-file-2085.tsx3 matches
1import { OpenAI } from "https://esm.town/v/std/openai";
23const openai = new OpenAI();
45const completion = await openai.chat.completions.create({
6messages: [
7{ role: "user", content: "Say hello in a creative way" },
stevensDemogenerateFunFacts.ts6 matches
2import { nanoid } from "https://esm.sh/nanoid@5.0.5";
3import { sqlite } from "https://esm.town/v/stevekrouse/sqlite";
4import OpenAI from "npm:openai@4.24.1";
56const TABLE_NAME = `memories`;
78try {
79// Get API key from environment
80const apiKey = Deno.env.get("OPENAI_API_KEY");
81if (!apiKey) {
82console.error("OpenAI API key is not configured.");
83return null;
84}
8586// Initialize OpenAI client
87const openai = new OpenAI({ apiKey });
8889// Format previous facts for the prompt
139console.log({ message });
140141const response = await openai.chat.completions.create({
142model: "gpt-4",
143max_tokens: 1000,