Search

4,002 results found for openai (5187ms)

Code
3,898

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" },
}
const apiKey = __secrets['openai_api_key'];
if (!apiKey) {
console.error('OpenAI API key not found in environment');
return Response.json(
{ error: 'OpenAI API key not configured' },
{ status: 500 }
);
}
console.log('Calling OpenAI API with prompt:', prompt);
// Call OpenAI API
const response = await fetch('https://api.openai.com/v1/chat/completions', {
method: 'POST',
headers: {
if (!response.ok) {
const error = await response.text();
console.error('OpenAI API error:', response.status, error);
return Response.json(
{ error: `OpenAI API error: ${response.status} - ${error}` },
{ status: 500 }
);
const data = await response.json();
console.log('OpenAI response received');
const poemText = data.choices[0].message.content.trim();
- **React** (because why not)
- **Leaflet** (so you get a map)
- **OpenAI** (to generate the GeoJSON and occasionally gaslight you)
## Disclaimer
const { query } = await request.json();
const { OpenAI } = await import("https://esm.town/v/std/openai");
const openai = new OpenAI();
const response = await openai.chat.completions.create({
messages: [
{
// 在 Val Town 中创建这个 val,然后在设置中配置 cron
import { OpenAI } from "https://esm.town/v/std/openai";
const TELEGRAM_BOT_TOKEN = process.env.TELEGRAM_BOT_TOKEN;
async function wisdom() {
const openai = new OpenAI();
try {
const completion = await openai.chat.completions.create({
messages: [
{
// @ts-ignore
import { OpenAI } from "https://esm.town/v/std/openai?v=4";
// @ts-ignore
import { blob } from "https://esm.town/v/std/blob?v=11";
const MAX_DEPTH = 4;
const CROSS_EXAMINE_DEPTH_INTERVAL = 2;
const openai = new OpenAI();
const INDEX_KEY = "claimguard_index";
}
const completion = await openai.chat.completions.create({
model: "gpt-4o",
messages: messages,
// @ts-ignore
import { OpenAI } from "https://esm.town/v/std/openai?v=4";
// @ts-ignore
import { blob } from "https://esm.town/v/std/blob?v=11";
// --- CORE AI & ESTIMATE LOGIC ---
const openai = new OpenAI();
const INDEX_KEY = "roofing_estimate_index";
): Promise<any> {
try {
const completion = await openai.chat.completions.create({
model: "gpt-4o",
messages: [
volt/Dynamic/main.ts
13 matches
import { Hono } from "npm:hono@4.4.12";
import { OpenAI } from "https://esm.town/v/std/openai";
import type { Context } from "npm:hono@4.4.12";
import { streamText } from "npm:hono@4.4.12/streaming";
// --- BACKEND SERVICES ---
const services = {
  async callOpenAI(
    systemPrompt: string,
    userContent: string | object,
      c = null,
    } = options;
    const openai = new OpenAI();
    const messages: any[] = [{ role: "system", content: systemPrompt }, {
      role: "user",
    if (isJson) requestPayload.response_format = { type: "json_object" };
    try {
      const completion = await openai.chat.completions.create(requestPayload);
      if (stream && c) {
        return streamText(c, async (s) => {
      return completion;
    } catch (e) {
      console.error(`Error calling OpenAI: ${e.message}`);
      throw new Error("AI service failed.");
    }
  }
  const userContent = `Company Context: ${JSON.stringify(company_context)}`;
  return services.callOpenAI(config.prompts.INDUSTRY_GENERATOR, userContent, {
    c,
    isJson: true,
    );
  try {
    const completion = await services.callOpenAI(
      "You are a helpful assistant following strict output rules.",
      prompt,
    ...(type === "occupations" && { industry: body.industry }),
SESSION };
  return services.callOpenAI(config.prompts.DYNAMIC_LIST_GENERATOR, payload, {
    c,
    isJson: true,
    .replace("{{company_context}}", JSON.stringify(company_context));
  return services.callOpenAI(
    "You are a helpful assistant following strict output rules.",
    userContent,
  const userPrompt = "Proceed with the task defined in your system instructions.";
  return services.callOpenAI(systemPrompt, userPrompt, { c, stream: true });
});
// --- END MODIFIED ENDPOINT ---
      briefing,
    );
    const criteriaCompletion = await services.callOpenAI(
      "You are a helpful assistant following strict output rules.",
      criteriaPrompt,
      raw_output: first_draft,
    };
    return services.callOpenAI(config.prompts.EVALUATOR_AGENT, userContent, {
      c,
      isJson: true,
## QA Critique
${critique}`;
  return services.callOpenAI(config.prompts.REFINER_AGENT, userContent, {
    c,
    stream: true,
refactored to use a serverless-friendly, short-polling mechanism. Clients
POST updates and GET the latest room state every 500ms.
5. AI (std/openai): The novel cornerstone of this application. When a user's
hand is detected, the raw 3D landmarks are periodically sent to the
backend. An OpenAI model (GPT-4o) classifies this spatial data into a
specific gesture (e.g., 'PEACE', 'FIST'). This classification is then
broadcast to all participants, triggering a 3D visual effect.
// --- VAL TOWN BACKEND ---
import { OpenAI } from "https://esm.town/v/std/openai?v=4";
import { blob } from "https://esm.town/v/std/blob?v=11";
import { Hono } from "npm:hono@4.4.12";
// --- Backend Initialization ---
const app = new Hono();
let openai: OpenAI;
// Initialization middleware to ensure OpenAI client is ready.
// This gates requests until the API key is confirmed.
app.use("*", async (c, next) => {
if (!openai) {
openai = new OpenAI();
await next();
try {
const completion = await openai.chat.completions.create({
model: "gpt-4o",
messages: [
}
const apiKey = __secrets['OPENAI_API_KEY'];
if (!apiKey) {
return Response.json({ error: 'OpenAI API key not configured' }, { status: 500 });
}
: '';
const response = await fetch('https://api.openai.com/v1/chat/completions', {
method: 'POST',
headers: {
if (!response.ok) {
const error = await response.text();
console.error('OpenAI API error:', error);
return Response.json({ error: 'Failed to generate poem' }, { status: 500 });
}