Search

3,343 results found for openai (1784ms)

Code
3,248

import { ChatCompletion, SearchResult } from "https://esm.town/v/cmknz/maine-bills-tax/types.ts"
import { OpenAI } from "https://esm.town/v/std/openai";
const openai = new OpenAI();
const prompt =
// Prompt request
const chatPromise: Promise<ChatCompletion> = openai.chat.completions.create({
messages: [
{ role: "user", content: prompt + ": " + extractImportantInfo },
// SERVER-SIDE LOGIC (TypeScript)
// =============================================================================
import { OpenAI } from "https://esm.town/v/std/openai";
// --- Configuration ---
maskSrc?: string; // Used for holo mask layer
}
interface OpenAIResponse {
races: RaceInfo[];
}
];
// --- OpenAI Generation Function ---
// <<< No changes needed in OpenAI function logic itself >>>
async function generateRaceDataWithOpenAI(): Promise<RaceInfo[]> {
const openai = new OpenAI();
const numToRequest = Math.max(1, NUM_CARDS_TO_GENERATE);
const prompt =
Return STRICTLY as a single JSON object: { "races": [ { race1 }, { race2 }, ... ] }. No introduc
try {
console.info(`Requesting ${numToRequest} race data generation from OpenAI...`);
const completion = await openai.chat.completions.create({
model: "gpt-4o",
messages: [{ role: "user", content: prompt }],
});
const rawContent = completion.choices[0]?.message?.content;
if (!rawContent) throw new Error("OpenAI returned an empty response message.");
let parsedJson;
parsedJson = JSON.parse(rawContent);
} catch (parseError) {
console.error("Failed to parse OpenAI JSON response:", parseError);
console.error("Raw OpenAI response:", rawContent);
throw new Error(`JSON Parsing Error: ${parseError.message}`);
}
) {
console.warn(
`OpenAI response JSON failed validation for ${numToRequest} races:`,
JSON.stringify(parsedJson, null, 2),
);
throw new Error(
"OpenAI response JSON structure, count, data types, color format, hint value, or mask UR
);
}
// --- End Validation ---
const generatedData = (parsedJson as OpenAIResponse).races.map(race => ({
...race,
borderAnimationHint: race.borderAnimationHint || "none",
// No need to override maskSrc here, default is handled in client script
}));
enerated and validated ${generatedData.length} races from OpenAI.`);
return generatedData;
} catch (error) {
console.error("Error fetching or processing data from OpenAI:", error);
console.warn("Using fallback race data due to the error.");
return fallbackRaceData.slice(0, numToRequest).map(race => ({
// --- Main HTTP Handler (Val Town Entry Point) ---
export default async function server(request: Request): Promise<Response> {
const activeRaceData = await generateRaceDataWithOpenAI();
// Define CSS Styles
// liteBriteGPTHTTP.val.ts
// Set OPENAI_API_KEY as a secret on Val Town first.
import OpenAI from "npm:openai"; // works in Deno/Val Town
const openai = new OpenAI({ apiKey: Deno.env.get("OPENAI_API_KEY")! });
const WIDTH = 60, HEIGHT = 40;
if (pathname === "/draw") {
const idea = searchParams.get("prompt") ?? "smiley face";
const chat = await openai.chat.completions.create({
model: "gpt-4o-mini",
temperature: 0.7,
Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to cre
### OpenAI
```ts
import { 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 cre
### OpenAI
```ts
import { 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" },
import { Levenshtein } from "npm:autoevals";
import { Eval, initDataset, wrapOpenAI } from "npm:braintrust";
import OpenAI from "npm:openai";
import { z } from "npm:zod";
const client = wrapOpenAI(new OpenAI());
Eval("Simple eval", {
Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to cre
### OpenAI
```ts
import { 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" },
import { 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" },
import { nanoid } from "https://esm.sh/nanoid@5.0.5";
import { sqlite } from "https://esm.town/v/stevekrouse/sqlite";
import OpenAI from "npm:openai@4.24.1";
const TABLE_NAME = `memories`;
try {
// Get API key from environment
const apiKey = Deno.env.get("OPENAI_API_KEY");
if (!apiKey) {
console.error("OpenAI API key is not configured.");
return null;
}
// Initialize OpenAI client
const openai = new OpenAI({ apiKey });
// Format previous facts for the prompt
console.log({ message });
const response = await openai.chat.completions.create({
model: "gpt-4",
max_tokens: 1000,
Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to cre
### OpenAI
```ts
import { 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" },