Search

3,306 results found for openai (5914ms)

Code
3,211

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 { parseBearerString } from "https://esm.town/v/andreterron/parseBearerString";
import { API_URL } from "https://esm.town/v/std/API_URL?v=5";
import { OpenAIUsage } from "./usage.ts";
const client = new OpenAIUsage();
const allowedPathnames = [
// Proxy the request
const url = new URL("." + pathname, "https://api.openai.com");
url.search = search;
const headers = new Headers(req.headers);
headers.set("Host", url.hostname);
headers.set("Authorization", `Bearer ${Deno.env.get("OPENAI_API_KEY")}`);
headers.set("OpenAI-Organization", Deno.env.get("OPENAI_API_ORG"));
const modifiedBody = await limitFreeModel(req, user);
});
const openAIRes = await fetch(url, {
method: req.method,
headers,
// Remove internal header
const res = new Response(openAIRes.body, openAIRes);
res.headers.delete("openai-organization");
return res;
}
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 Proxy
This OpenAI API proxy injects Val Town's API keys. For usage documentation,
check out https://www.val.town/v/std/openai
Adapted from https://blog.r0b.io/post/creating-a-proxy-with-deno/
import { OpenAIUsage } from "https://esm.town/v/std/OpenAIUsage";
const client = new OpenAIUsage();
const t0 = performance.now();
COUNT(*) AS count
FROM
openai_usage,
params
WHERE
};
export class OpenAIUsage {
constructor() {}
async migrate() {
await sqlite.batch([`CREATE TABLE IF NOT EXISTS openai_usage (
id INTEGER PRIMARY KEY,
user_id TEXT NOT NULL,
}
async drop() {
await sqlite.batch([`DROP TABLE IF EXISTS openai_usage`]);
}
async writeUsage(ur: UsageRow) {
sqlite.execute({
sql:
"INSERT INTO openai_usage (user_id, handle, tier, tokens, model) VALUES (?, ?, ?, ?, ?)"
args: [ur.userId, ur.handle, ur.tier, ur.tokens, ur.model],
});
let resp = await sqlite.execute({
sql: `SELECT count(*)
FROM openai_usage
WHERE (
(model LIKE 'gpt-4%' AND model NOT LIKE '%mini%')
- **Blob Storage**: `import { blob } from "https://esm.town/v/std/blob"`
- **SQLite**: Use Drizzle ORM instead of raw SQL
- **OpenAI**: `import { OpenAI } from "https://esm.town/v/std/openai"`
- **Email**: `import { email } from "https://esm.town/v/std/email"`
{
label: "LLMs",
subtitle: "OpenAI • Anthropic • Mistral • Local",
icon: Sparkles,
},
// @ts-ignore
import { OpenAI } from "https://esm.town/v/std/openai?v=4";
// @ts-ignore
import { Hono } from "npm:hono@4.4.12";
JSON.stringify(analysis, null, 2)
}`;
const openai = new OpenAI();
const completion = await openai.chat.completions.create({
model: "gpt-4o",
messages: [{ role: "system", content: PORTFOLIO_ANALYST_PROMPT }, {
},
];
const openai = new OpenAI();
const response = await openai.chat.completions.create({
model: "gpt-4o",
messages: messages,
// 导入 Val Town 的 OpenAI 模块
import { OpenAI } from "https://esm.town/v/std/openai";
// 初始化 OpenAI 客户端
const openai = new OpenAI();
// 主处理函数
try {
console.log(text);
// 使用 OpenAI 生成摘要
const completion = await openai.chat.completions.create({
messages: [
{
});
} catch (aiError) {
console.error("OpenAI API Error:", aiError);
return createJsonResponse(500, { success: false, error: "AI 总结失败,请检查 API Key 或稍后再试" });
}