Search

3,375 results found for openai (4961ms)

Code
3,280

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" },
```
### OpenAI
library, import from https://esm.town/v/cricks_unmixed4u/openai-client/main.tsx and use
## GreenPTClient
```tsx
import { GreenPTClient } from "https://esm.town/v/cricks_unmixed4u/openai-client/main.tsx";
const client = GreenPTClient("green-l");
join/aura/main.tsx
5 matches
// @ts-ignore
import { blob } from "https://esm.town/v/std/blob?v=11";
import { OpenAI } from "https://esm.town/v/std/openai?v=4";
// --- AI BEHAVIORAL GUIDELINES ---
</div>
<div class="loading-indicator" id="loading-indicator" style="display: none;">Aura is pondering
by <a href="${sourceUrl}" target="_blank">Val Town</a> & OpenAI</footer>
</div>
if (req.method === "POST" && action === "chat") {
try {
const openai = new OpenAI();
const body = await req.json();
const userMessage = body.message;
// 2. Analyze user's mood
const moodCompletion = await openai.chat.completions.create({
model: "gpt-4o",
messages: [
// 3. Generate Aura's response
const auraCompletion = await openai.chat.completions.create({
model: "gpt-4o",
messages: systemAndUserMessages,
// @ts-ignore
import { OpenAI } from "https://esm.town/v/std/openai?v=4";
/**
try {
if (req.method === "POST" && action === "suggestProjects") {
const openai = new OpenAI();
const completion = await openai.chat.completions.create({
model: "gpt-4o",
messages: [
// @ts-ignore
import { OpenAI } from "https://esm.town/v/std/openai?v=4";
// --- AI BEHAVIORAL GUIDELINES ---
if (req.method === "POST" && action === "generate") {
try {
const openai = new OpenAI();
const completion = await openai.chat.completions.create({
model: "gpt-4o",
messages: [
// @ts-ignore
import { OpenAI } from "https://esm.town/v/std/openai?v=4";
// --- Configuration & Constants ---
const OPENAI_MODEL = "gpt-4o";
const MAX_TOKENS_RESPONSE = 800;
}
// --- OpenAI System Prompt ---
const SYSTEM_PROMPT = `
You are a Rick and Morty-styled transdimensional narrative engine. Your primary role is to gener
} = ensureDefaultsAndInferStates(inputContext);
const contextForOpenAI = {
...processedContext,
_inferred_states_for_your_convenience: {
},
};
const userMessage = `Input Context JSON:\n${JSON.stringify(contextForOpenAI, null, 2)}`;
try {
const openai = new OpenAI();
const completion = await openai.chat.completions.create({
model: OPENAI_MODEL,
response_format: { type: "json_object" },
messages: [
const rawContent = completion.choices[0]?.message?.content;
if (!rawContent) {
throw new Error("OpenAI returned an empty response message.");
}
|| typeof generatedJson.metadata.scene_id !== "string"
) {
throw new Error("OpenAI response missing critical fields or incorrect structure.");
}
generatedJson.metadata.weather_state = inferredWeather;
});
} catch (error) {
console.error("Error during OpenAI call or processing:", error);
return new Response(
JSON.stringify(getFallbackOutput(error.message, processedContext)),
// @ts-ignore
import { OpenAI } from "https://esm.town/v/std/openai?v=4";
import { Hono } from "npm:hono@4.4.12";
/**
* Calls the OpenAI API to compress the artistic idea.
* @param previousIdea The idea from the last iteration.
* @param sentiment The new user-provided sentiment.
theme: string,
): Promise<{ idea: string; reason: string }> {
const openai = new OpenAI();
const userInput =
`The previous concept was: "${previousIdea}". The new user input is a sentiment of "${sentim
try {
const completion = await openai.chat.completions.create({
model: "gpt-4o",
messages: [
const content = completion.choices[0].message.content;
if (!content) {
throw new Error("OpenAI returned an empty response for compression.");
}
const parsed = extractJson(content);
/**
* Calls the OpenAI API to generate an SVG from the compressed idea.
* @param idea The conceptual phrase to visualize.
* @returns The SVG code as a string.
*/
async function generateArtwork(idea: string): Promise<string> {
const openai = new OpenAI();
try {
const completion = await openai.chat.completions.create({
model: "gpt-4o",
messages: [
const content = completion.choices[0].message.content;
if (!content) {
throw new Error("OpenAI returned an empty response for artwork generation.");
}
const parsed = extractJson(content);
// @ts-ignore
import { OpenAI } from "https://esm.town/v/std/openai?v=4";
import { Hono } from "npm:hono@4.4.12";
if (action === "generateLevel") {
try {
const openai = new OpenAI();
const completion = await openai.chat.completions.create({
model: "gpt-4o",
messages: [
return c.json(levelData);
} catch (error) {
console.error("OpenAI API Error:", error);
// If AI fails, provide a safe fallback level
return c.json(FALLBACK_LEVEL, 500);
// @ts-ignore
import { OpenAI } from "https://esm.town/v/std/openai?v=4";
// --- AI BEHAVIORAL GUIDELINES ---
</main>
<footer class="footer">
A Val Town Frontier Tale powered by <a href="${sourceUrl}" target="_blank">OpenAI</a>
</footer>
</div>
if (req.method === "POST") {
try {
const openai = new OpenAI();
const body = await req.json();
}
const completion = await openai.chat.completions.create({
model: "gpt-4o",
messages: messages,
svc/March/main.tsx
3 matches
// @ts-ignore
import { OpenAI } from "https://esm.town/v/std/openai?v=4";
// --- AI BEHAVIORAL GUIDELINES & PROMPTS ---
if (req.method === "POST") {
try {
const openai = new OpenAI();
const body = await req.json();
];
const completion = await openai.chat.completions.create({
model: "gpt-4o",
messages: messages,