Search
Code212
}; // Call Grok API (uses OpenAI-compatible endpoint) const grokRes = await fetch("https://api.x.ai/v1/chat/completions", { method: "POST", }; // Call Grok API (uses OpenAI-compatible endpoint) const grokRes = await fetch("https://api.x.ai/v1/chat/completions", { method: "POST",/** @jsxImportSource https://esm.sh/react@18.2.0 */import { renderToString } from "https://esm.sh/react-dom@18.2.0/server";import OpenAI from "npm:openai@6.22.0";interface ChatRequestBody {const TAVILY_API_KEY = requireEnv("TAVILY_API_KEY");// Use Baseten through its OpenAI-compatible API endpoint via OpenAI SDK.const openai = new OpenAI({ apiKey: requireEnv("BASETEN_API_KEY"), baseURL: BASETEN_BASE_URL, const context = await buildContext(question); const completion = await openai.chat.completions.create({ model: MODEL, temperature: 0.2,Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.### OpenAI```tsimport { 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 create a fresh table.### OpenAI```tsimport { 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```tsimport { 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" }, Routes,} from "npm:discord-api-types/v10";import { OpenAI } from "https://esm.town/v/std/openai";import { getLastMessageId, init, setLastMessageId } from "./sqlite.ts"; .setToken(Deno.env.get("DISCORD_BOT_TOKEN")!);const openai = new OpenAI();// ============================================================================ author: string,): Promise<string> { const response = await openai.chat.completions.create({ model: "gpt-4.1-nano", max_tokens: 30,# auto-threadAutomatically creates Discord threads from new messages in configured channels, using OpenAI to generate descriptive thread titles.## How It Worksflowchart LR A[β° Cron every 1 min] --> B[π Poll every 5s] B -->|new messages| C[π€ OpenAI] C -->|thread title| D[Discord API] D --> E[π§΅ Thread Created]- `npm:@discordjs/rest` β Discord REST API with rate limiting and retries- `npm:discord-api-types` β Full TypeScript types for the Discord API- `std/openai` β Val Town's OpenAI wrapper- `std/sqlite` β Val Town's project-scoped SQLiteConfigure the following variables in your environment: - `AGENT_API_KEY` (This is a secure token that you choose to secure the agent.tsx POST endpoint)- `OPENAI_API_KEY` (An OpenAI API Key)- `EXA_API_KEY` (Optional, though needed if you use the web search tool)import { anthropic } from "npm:@ai-sdk/anthropic";import { openai } from "npm:@ai-sdk/openai";import { generateText, streamText } from "npm:ai";import { getSystemPrompt } from "./prompt.tsx"; const maxSteps = 10; const model = Deno.env.get("ANTHROPIC_API_KEY") ? anthropic("claude-3-7-sonnet-latest") : openai("gpt-4.1"); const options = {Users
No users found
Docs
No docs found