revert: remove tablet Laya integration and restore pure OpenRouter Jev decision oracle
This commit is contained in:
parent
cf9aefc846
commit
455181290f
5 changed files with 13 additions and 174 deletions
|
|
@ -67,37 +67,6 @@ export async function onRequestPost(context) {
|
|||
const cleanQuestion = question.trim().slice(0, 300);
|
||||
const startTime = Date.now();
|
||||
|
||||
const layaUrl = env.LAYA_API_URL || "https://laya-api.oiupoyt.space";
|
||||
try {
|
||||
const layaRes = await fetch(`${layaUrl}/api/ask`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ question: cleanQuestion }),
|
||||
signal: AbortSignal.timeout(35000)
|
||||
});
|
||||
if (layaRes.ok) {
|
||||
const data = await layaRes.json();
|
||||
return json({
|
||||
question: cleanQuestion,
|
||||
answer: data.answer,
|
||||
sentiment: data.sentiment,
|
||||
noul: data.noul,
|
||||
confidence: data.confidence,
|
||||
probabilities: data.probabilities || {},
|
||||
aphorismKey: data.aphorismKey || "signs_yes",
|
||||
latency: Date.now() - startTime,
|
||||
cost: 0,
|
||||
usage: { prompt_tokens: data.raw?.usage?.input_tokens ?? 38, completion_tokens: 0 },
|
||||
model: data.model || "convaiinnovations/laya-typed-decisions",
|
||||
engine: "Laya System 1 (Android Tablet)",
|
||||
tablet: true,
|
||||
raw: data
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
// Fall back to OpenRouter
|
||||
}
|
||||
|
||||
try {
|
||||
const payload = {
|
||||
model: MODEL,
|
||||
|
|
|
|||
|
|
@ -4,23 +4,10 @@ const REPO_API_KEY = "sk-or-v1-6a1268b4a6aac87d2af72e859d6653bac1344ae4f99cfaf13
|
|||
|
||||
export async function onRequestGet(context) {
|
||||
const { env } = context;
|
||||
let layaOnline = false;
|
||||
let layaData = null;
|
||||
|
||||
const layaUrl = env.LAYA_API_URL || "https://laya-api.oiupoyt.space";
|
||||
try {
|
||||
const res = await fetch(`${layaUrl}/api/status`, { signal: AbortSignal.timeout(2500) });
|
||||
if (res.ok) {
|
||||
layaData = await res.json();
|
||||
layaOnline = Boolean(layaData.status === "online" || layaData.ready);
|
||||
}
|
||||
} catch (e) {}
|
||||
|
||||
return new Response(JSON.stringify({
|
||||
status: "online",
|
||||
model: layaOnline ? (layaData?.model || "convaiinnovations/laya-typed-decisions") : "typesafe/jev-1.13",
|
||||
engine: layaOnline ? "Laya System 1 (Tablet via Tunnel)" : "TypeSafe Jev (Cloudflare Pages Edge)",
|
||||
tablet: layaOnline,
|
||||
model: "typesafe/jev-1.13",
|
||||
engine: "TypeSafe Jev (Cloudflare Pages Edge)",
|
||||
hasKey: Boolean(env.OPENROUTER_API_KEY || REPO_API_KEY),
|
||||
keySource: env.OPENROUTER_API_KEY ? "env" : "repo"
|
||||
}), {
|
||||
|
|
|
|||
66
server.js
66
server.js
|
|
@ -19,7 +19,6 @@ const REPO_API_KEY = 'sk-or-v1-6a1268b4a6aac87d2af72e859d6653bac1344ae4f99cfaf13
|
|||
const OPENROUTER_API_KEY = process.env.OPENROUTER_API_KEY || REPO_API_KEY;
|
||||
const JEV_DECISIONS_URL = 'https://openrouter.ai/api/alpha/decisions';
|
||||
const MODEL = 'typesafe/jev-1.13';
|
||||
const LAYA_API_URL = process.env.LAYA_API_URL || 'http://192.168.0.103:8888';
|
||||
|
||||
if (!process.env.OPENROUTER_API_KEY) {
|
||||
console.warn('[jev-8ball] OPENROUTER_API_KEY is not set — using the in-repo key.');
|
||||
|
|
@ -56,29 +55,11 @@ const APHORISMS = {
|
|||
};
|
||||
|
||||
// GET /api/status
|
||||
app.get('/api/status', async (req, res) => {
|
||||
let layaOnline = false;
|
||||
let layaData = null;
|
||||
|
||||
try {
|
||||
const layaRes = await fetch(`${LAYA_API_URL}/api/status`, {
|
||||
signal: AbortSignal.timeout(1200)
|
||||
});
|
||||
if (layaRes.ok) {
|
||||
layaData = await layaRes.json();
|
||||
layaOnline = Boolean(layaData.status === 'online' || layaData.ready);
|
||||
}
|
||||
} catch (err) {
|
||||
layaOnline = false;
|
||||
}
|
||||
|
||||
app.get('/api/status', (req, res) => {
|
||||
res.json({
|
||||
status: 'online',
|
||||
model: layaOnline ? (layaData?.model || 'convaiinnovations/laya-typed-decisions') : MODEL,
|
||||
engine: layaOnline ? 'Laya System 1 Decision Model (Android Tablet)' : 'TypeSafe Jev (Cloud Decision Engine)',
|
||||
tablet: layaOnline,
|
||||
layaUrl: LAYA_API_URL,
|
||||
layaInfo: layaData,
|
||||
model: MODEL,
|
||||
engine: 'TypeSafe Jev (Non-autoregressive System One)',
|
||||
hasKey: Boolean(OPENROUTER_API_KEY),
|
||||
keySource: process.env.OPENROUTER_API_KEY ? 'env' : 'repo'
|
||||
});
|
||||
|
|
@ -98,44 +79,6 @@ app.post('/api/ask', async (req, res) => {
|
|||
const cleanQuestion = question.trim().slice(0, 300);
|
||||
const startTime = performance.now();
|
||||
|
||||
// 1. Attempt inference on Android Tablet running Laya System 1
|
||||
try {
|
||||
const layaRes = await fetch(`${LAYA_API_URL}/api/ask`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ question: cleanQuestion }),
|
||||
signal: AbortSignal.timeout(35000)
|
||||
});
|
||||
|
||||
if (layaRes.ok) {
|
||||
const data = await layaRes.json();
|
||||
const latency = Math.round(performance.now() - startTime);
|
||||
return res.json({
|
||||
question: cleanQuestion,
|
||||
answer: data.answer,
|
||||
sentiment: data.sentiment,
|
||||
noul: data.noul,
|
||||
confidence: data.confidence,
|
||||
probabilities: data.probabilities || {},
|
||||
aphorismKey: data.aphorismKey || 'signs_yes',
|
||||
latency,
|
||||
cost: 0,
|
||||
usage: { prompt_tokens: data.raw?.usage?.input_tokens ?? 38, completion_tokens: 0 },
|
||||
model: data.model || 'convaiinnovations/laya-typed-decisions',
|
||||
engine: 'Laya System 1 (Android Tablet ARM64)',
|
||||
tablet: true,
|
||||
raw: data
|
||||
});
|
||||
}
|
||||
} catch (layaErr) {
|
||||
// Graceful fallback to OpenRouter Jev cloud API
|
||||
console.warn(`[jev-8ball] Tablet Laya not reachable (${layaErr.message}), falling back to OpenRouter Jev`);
|
||||
}
|
||||
|
||||
if (!OPENROUTER_API_KEY) {
|
||||
return res.status(503).json({ error: 'Oracle is not configured. Set OPENROUTER_API_KEY.' });
|
||||
}
|
||||
|
||||
try {
|
||||
const payload = {
|
||||
model: MODEL,
|
||||
|
|
@ -288,6 +231,5 @@ app.use((req, res) => {
|
|||
|
||||
app.listen(PORT, () => {
|
||||
console.log(`[jev-8ball] Server running at http://localhost:${PORT}`);
|
||||
console.log(`[jev-8ball] Primary Engine: Laya on Android Tablet (${LAYA_API_URL})`);
|
||||
console.log(`[jev-8ball] Fallback Engine: ${MODEL} via OpenRouter Decisions API`);
|
||||
console.log(`[jev-8ball] Model: ${MODEL} via OpenRouter Decisions API`);
|
||||
});
|
||||
|
|
|
|||
70
worker.mjs
70
worker.mjs
|
|
@ -63,30 +63,10 @@ export default {
|
|||
|
||||
// GET /api/status
|
||||
if (url.pathname === "/api/status") {
|
||||
let layaOnline = false;
|
||||
let layaData = null;
|
||||
|
||||
if (env.LAYA_API_URL) {
|
||||
try {
|
||||
const layaRes = await fetch(`${env.LAYA_API_URL}/api/status`, {
|
||||
signal: AbortSignal.timeout(2500)
|
||||
});
|
||||
if (layaRes.ok) {
|
||||
layaData = await layaRes.json();
|
||||
layaOnline = Boolean(layaData.status === "online" || layaData.ready);
|
||||
}
|
||||
} catch (e) {
|
||||
layaOnline = false;
|
||||
}
|
||||
}
|
||||
|
||||
return json({
|
||||
status: "online",
|
||||
model: layaOnline ? (layaData?.model || "convaiinnovations/laya-typed-decisions") : MODEL,
|
||||
engine: layaOnline ? "Laya System 1 Decision Model (Android Tablet)" : "TypeSafe Jev (Cloudflare Edge Worker)",
|
||||
tablet: layaOnline,
|
||||
layaUrl: env.LAYA_API_URL || null,
|
||||
layaInfo: layaData,
|
||||
model: MODEL,
|
||||
engine: "TypeSafe Jev (Cloudflare Edge Worker)",
|
||||
hasKey: Boolean(resolveApiKey(env)),
|
||||
keySource: env.OPENROUTER_API_KEY ? "env" : "repo"
|
||||
});
|
||||
|
|
@ -94,6 +74,11 @@ export default {
|
|||
|
||||
// POST /api/ask
|
||||
if (url.pathname === "/api/ask" && request.method === "POST") {
|
||||
const apiKey = resolveApiKey(env);
|
||||
if (!apiKey) {
|
||||
return json({ error: "Oracle is not configured. Set the OPENROUTER_API_KEY secret." }, 503);
|
||||
}
|
||||
|
||||
let body;
|
||||
try {
|
||||
body = await request.json();
|
||||
|
|
@ -109,47 +94,6 @@ export default {
|
|||
const cleanQuestion = question.trim().slice(0, 300);
|
||||
const startTime = Date.now();
|
||||
|
||||
// 1. Primary Engine: Tablet Laya System 1 if configured in environment
|
||||
if (env.LAYA_API_URL) {
|
||||
try {
|
||||
const layaRes = await fetch(`${env.LAYA_API_URL}/api/ask`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ question: cleanQuestion }),
|
||||
signal: AbortSignal.timeout(35000)
|
||||
});
|
||||
if (layaRes.ok) {
|
||||
const data = await layaRes.json();
|
||||
if (data && data.answer) {
|
||||
return json({
|
||||
question: cleanQuestion,
|
||||
answer: data.answer,
|
||||
sentiment: data.sentiment,
|
||||
noul: data.noul,
|
||||
confidence: data.confidence,
|
||||
probabilities: data.probabilities || {},
|
||||
aphorismKey: data.aphorismKey || "signs_yes",
|
||||
latency: Date.now() - startTime,
|
||||
cost: 0,
|
||||
usage: { prompt_tokens: data.raw?.usage?.input_tokens ?? 38, completion_tokens: 0 },
|
||||
model: data.model || "convaiinnovations/laya-typed-decisions",
|
||||
engine: "Laya System 1 (Android Tablet)",
|
||||
tablet: true,
|
||||
raw: data
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (layaErr) {
|
||||
// Fall back to OpenRouter Jev
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Fallback Engine: OpenRouter Jev
|
||||
const apiKey = resolveApiKey(env);
|
||||
if (!apiKey) {
|
||||
return json({ error: "Oracle is not configured. Set the OPENROUTER_API_KEY secret." }, 503);
|
||||
}
|
||||
|
||||
try {
|
||||
const payload = {
|
||||
model: MODEL,
|
||||
|
|
|
|||
|
|
@ -5,8 +5,5 @@
|
|||
"assets": {
|
||||
"directory": "./public",
|
||||
"binding": "ASSETS"
|
||||
},
|
||||
"vars": {
|
||||
"LAYA_API_URL": "https://laya-api.oiupoyt.space"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue