Search

3,779 results found for openai (8788ms)

Code
3,676

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" },
Get/Pricing/main.tsx
11 matches
export default async function server(request: Request): Promise<Response> {
// Server-side imports (dynamic import within the function)
const { OpenAI } = await import("https://esm.town/v/std/openai");
// Server-side logging utility
}
// Initialize OpenAI Client
let openai: OpenAI;
try {
// Assumes OPENAI_API_KEY is set as an environment variable in the runtime (e.g., Val Town S
openai = new OpenAI();
} catch (e: any) { // Type assertion for error
logServer("ERROR", "Failed to initialize OpenAI Client", { error: e.message });
// Return a structured error response
return new Response(JSON.stringify({
response: "Error: The AI backend could not be initialized. Please check server configura
error: `OpenAI Initialization Failed: ${e.message}`
}), {
status: 503, // Service Unavailable might be appropriate
try {
// Call the OpenAI API (using gpt-4o or a similar vision model)
const completion = await openai.chat.completions.create({
model: "gpt-4o", // Recommended model for vision and JSON output
response_format: { type: "json_object" }, // Ensure JSON output
try {
// Call OpenAI API (gpt-4o-mini or similar is often sufficient and faster/cheaper)
const completion = await openai.chat.completions.create({
model: "gpt-4o-mini", // Use a cost-effective model if appropriate
response_format: { type: "json_object" },
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" },
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" },
export default async function server(request: Request): Promise<Response> {
if (request.method === "POST" && new URL(request.url).pathname === "/summarize") {
const { OpenAI } = await import("https://esm.town/v/std/openai");
const openai = new OpenAI();
const { url } = await request.json();
const articleText = await articleResponse.text();
const completion = await openai.chat.completions.create({
messages: [
{ role: "system", content: "You are a helpful assistant that summarizes articles in tw
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" },