Search
Code3,898
_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" },// @ts-ignoreimport { OpenAI } from "https://esm.town/v/std/openai?v=4";import { Hono } from "npm:hono@4.4.12"; </button> </form> <p class="text-sm text-gray-500 mt-6">Powered by Val Town & OpenAI</p> </div> <div id="start-overlay" class="fixed inset-0 bg-gray-900/80 backdrop-blur-sm z-20 flex flex-col justify-center items-center text-center p-8 opacity-0 pointer-events-none transition-opacity duration-500"> } const openai = new OpenAI(); const completion = await openai.chat.completions.create({ model: "gpt-4o", messages: [ } } catch (error) { console.error("OpenAI API Error:", error); return c.json({ error: "An error occurred while communicating with the AI designer.",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" },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" },// Akash Network OpenAI API Proxy - Val Town 真流式 SSE 版本// 本版仅修改“输出格式/解析”部分:只使用上游返回中以 "0:" 开头的行进行拼接(thinking 与正文均来自 0: 行)。// 其他逻辑保持不变:仅发送最后一条 user 消息 + 保留最后一条 system;温度/TopP 动态传递并夹逼 temperature=0 为 0.01。import { fetch } from "https://esm.town/v/std/fetch";class AkashOpenAIAPI { private baseUrl: string; private authUrl: string; "DeepSeek-V3.1", "Qwen3-235B-A22B-Instruct-2507-FP8", "openai-gpt-oss-120b", "meta-llama-Llama-4-Maverick-17B-128E-Instruct-FP8", ]; /** * 将 OpenAI 模型名映射到 Akash 可用模型 * 动态映射,确保只映射到实际可用的模型 * @param openaiModel - OpenAI 模型名 * @returns {string} Akash 模型名 */ public async modelNameMapping(openaiModel: string): Promise<string> { const availableModels = await this.getAvailableModels(); // 优先使用精确匹配 if (availableModels.includes(openaiModel)) { return openaiModel; } // 定义通用模型名到 Akash 模型的映射 const mapping: Record<string, string> = { "gpt-4": "openai-gpt-oss-120b", "gpt-4o": "DeepSeek-V3.1", "gpt-4-turbo": "openai-gpt-oss-120b", "gpt-3.5-turbo": "openai-gpt-oss-120b", "gpt-4o-mini": "DeepSeek-V3.1", }; const mappedModel = mapping[openaiModel]; // 如果找到了映射模型,且它在可用列表中,则返回 if (mappedModel && availableModels.includes(mappedModel)) { console.log(`🔗 模型映射: ${openaiModel} -> ${mappedModel}`); return mappedModel; } const fallbackModel = availableModels[0]; console.log( `⚠️ 模型 "${openaiModel}" 未找到直接映射,正在使用第一个可用模型: ${fallbackModel}`, ); return fallbackModel; "❌ 没有任何可用模型,将使用硬编码默认值。这表明获取模型列表失败且无回退列表。", ); return "openai-gpt-oss-120b"; }// ---- 全局实例 ----const akashApi = new AkashOpenAIAPI();// ---- Val Town 入口 ----function index(cors: Record<string, string>): Response { const data = { message: "Akash Network OpenAI API Proxy", version: "1.7.2-ZeroOnly", endpoints: { }, documentation: "This proxy converts OpenAI API requests to Akash Network format (Val Town version, with real SSE streaming). Output parser now strictly concatenates only lines starting with '0:'.", }; const question = decodeURIComponent(path.substring(1)).trim(); const json = await fetch("https://text.pollinations.ai/openai", { method: "POST", headers: { try { const apiKey = __secrets['OPENAI_API_KEY']; if (!apiKey) { return Response.json({ error: 'OpenAI API key not configured' }, { status: 500 }); } } // 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:', error); return Response.json({ error: 'Failed to get AI response' 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" },reconsumeralization
import { OpenAI } from "https://esm.town/v/std/openai";
import { sqlite } from "https://esm.town/v/stevekrouse/sqlite";
/**
* Practical Implementation of Collective Content Intelligence
* Bridging advanced AI with collaborative content creation
*/
exp
kwhinnery_openai
lost1991
import { OpenAI } from "https://esm.town/v/std/openai";
export default async function(req: Request): Promise<Response> {
if (req.method === "OPTIONS") {
return new Response(null, {
headers: {
"Access-Control-Allow-Origin": "*",
No docs found