Search

3,988 results found for openai (1168ms)

Code
3,885

import { OpenAI } from "npm:openai";
import ValTown from "npm:@valtown/sdk";
const openai = new OpenAI();
const client = new ValTown();
}
const response = await openai.chat.completions.create({
model: "gpt-4o-mini",
messages: [{
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" },
_2 or _3) to create a fresh table.
### 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" },
- Cron triggers: `*.cron.ts`, export default async function()
- Email triggers: `*.email.ts`, export default async function(email: Email)
- Use Val Town std libraries: `blob`, `sqlite`, `openai`, `email`
- Never use Deno KV, avoid external images, use Tailwind via CDN
import { z } from "npm:zod@4.0.5";
import { generateText, stepCountIs, tool } from "npm:ai@5.0.15";
import { openai } from "npm:@ai-sdk/openai@2.0.15";
import { Sandbox } from "npm:@e2b/code-interpreter";
const result = await generateText({
model: openai("gpt-4o"),
stopWhen: stepCountIs(5),
tools: {
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 { OpenAI } from "https://esm.town/v/std/openai?v=4";
// --- CONFIGURATION & PROMPTS ---
try {
const body = await req.json();
const openai = new OpenAI();
const completion = await openai.chat.completions.create({
model: "gpt-4o",
messages: [
// Required header: x-api-key: <AUTH_TOKEN>
import { OpenAI } from "npm:openai@4";
import { Pinecone } from "npm:@pinecone-database/pinecone@3";
import Anthropic from "npm:@anthropic-ai/sdk@0.27";
// Env vars
const AUTH_TOKEN = Deno.env.get("AUTH_TOKEN");
const OPENAI_API_KEY = Deno.env.get("OPENAI_API_KEY");
const PINECONE_API_KEY = Deno.env.get("PINECONE_API_KEY");
const PINECONE_INDEX_NAME = Deno.env.get("PINECONE_INDEX_NAME") ||
Deno.env.get("PINECONE_DIMENSIONS") || "1536",
);
const OPENAI_EMBEDDINGS_MODEL = Deno.env.get("OPENAI_EMBEDDINGS_MODEL") ||
"text-embedding-3-small";
const ANTHROPIC_API_KEY = Deno.env.get("ANTHROPIC_API_KEY");
// Validate required environment variables
if (!OPENAI_API_KEY) {
throw new Error("OPENAI_API_KEY environment variable is required");
}
if (!PINECONE_API_KEY) {
// Clients (reused across invocations)
const openai = new OpenAI({ apiKey: OPENAI_API_KEY });
const pinecone = new Pinecone({ apiKey: PINECONE_API_KEY });
const anthropic = new Anthropic({ apiKey: ANTHROPIC_API_KEY });
async function embedQuestion(question: string): Promise<number[]> {
const response = await openai.embeddings.create({
model: OPENAI_EMBEDDINGS_MODEL,
input: question,
dimensions: PINECONE_DIMENSIONS,
import { blob } from "https://esm.town/v/std/blob?v=11";
import { OpenAI } from "https://esm.town/v/std/openai?v=4";
import { Hono } from "npm:hono@3.11.7";
// --- CONFIGURATION ---
const app = new Hono();
const openai = new OpenAI();
const CORS_HEADERS = {
"Access-Control-Allow-Origin": "*",
try {
const { metrics } = await c.req.json();
const completion = await openai.chat.completions.create({
model: "gpt-4o",
messages: [