Spaces:
Configuration error
Configuration error
Upload 8 files
Browse files- README.md +14 -11
- index.css +0 -0
- index.html +10 -19
- index.tsx +122 -0
- metadata.json +6 -0
- package.json +20 -0
- tsconfig.json +30 -0
- vite.config.ts +16 -0
README.md
CHANGED
|
@@ -1,11 +1,14 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Run and deploy your AI Studio app
|
| 2 |
+
|
| 3 |
+
This contains everything you need to run your app locally.
|
| 4 |
+
|
| 5 |
+
## Run Locally
|
| 6 |
+
|
| 7 |
+
**Prerequisites:** Node.js
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
1. Install dependencies:
|
| 11 |
+
`npm install`
|
| 12 |
+
2. Set the `API_KEY` in [.env.local](.env.local) to your Gemini API key
|
| 13 |
+
3. Run the app:
|
| 14 |
+
`npm run dev`
|
index.css
ADDED
|
File without changes
|
index.html
CHANGED
|
@@ -1,19 +1,10 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
<h1>Welcome to your static Space!</h1>
|
| 12 |
-
<p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
|
| 13 |
-
<p>
|
| 14 |
-
Also don't forget to check the
|
| 15 |
-
<a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
|
| 16 |
-
</p>
|
| 17 |
-
</div>
|
| 18 |
-
</body>
|
| 19 |
-
</html>
|
|
|
|
| 1 |
+
<script type="importmap">
|
| 2 |
+
{
|
| 3 |
+
"imports": {
|
| 4 |
+
"marked": "https://esm.sh/marked@^15.0.8",
|
| 5 |
+
"openai": "https://esm.sh/openai@^4.94.0"
|
| 6 |
+
}
|
| 7 |
+
}
|
| 8 |
+
</script>
|
| 9 |
+
<link rel="stylesheet" href="index.css">
|
| 10 |
+
<script src="index.tsx" type="module"></script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
index.tsx
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* @license
|
| 3 |
+
* SPDX-License-Identifier: Apache-2.0
|
| 4 |
+
*
|
| 5 |
+
* Fractal‑Syntax‑Forge Engine
|
| 6 |
+
* Engineered by James Burvel O'Callaghan III for Citibank Demo Business Inc.
|
| 7 |
+
*
|
| 8 |
+
* Mission: Birth “**FGL – Fractal Genesis Language**”, a meta‑programming tongue for
|
| 9 |
+
* engineering reality layers, holographic simulations, and 13‑D hyperframes.
|
| 10 |
+
*
|
| 11 |
+
* Paste into any TS‑aware bundler, supply your Gemini‑compatible key via
|
| 12 |
+
* `process.env.API_KEY`, open in‑browser, and watch constructs manifest.
|
| 13 |
+
*/
|
| 14 |
+
|
| 15 |
+
import { marked } from 'marked';
|
| 16 |
+
import OpenAI, {
|
| 17 |
+
type ClientOptions,
|
| 18 |
+
type ChatCompletionMessageParam,
|
| 19 |
+
} from 'openai';
|
| 20 |
+
|
| 21 |
+
// ──────────────────────────────────────────────────────────────
|
| 22 |
+
// ENV + OpenAI init
|
| 23 |
+
// ──────────────────────────────────────────────────────────────
|
| 24 |
+
|
| 25 |
+
const API_KEY = process.env.API_KEY;
|
| 26 |
+
if (!API_KEY) throw new Error('Missing API_KEY env var');
|
| 27 |
+
|
| 28 |
+
const openai = new OpenAI({
|
| 29 |
+
apiKey: API_KEY,
|
| 30 |
+
baseURL: 'https://generativelanguage.googleapis.com/v1beta/openai/',
|
| 31 |
+
dangerouslyAllowBrowser: true,
|
| 32 |
+
} as ClientOptions);
|
| 33 |
+
|
| 34 |
+
// ──────────────────────────────────────────────────────────────
|
| 35 |
+
// Fractal console
|
| 36 |
+
// ──────────────────────────────────────────────────────────────
|
| 37 |
+
|
| 38 |
+
async function consoleRender(...md: string[]): Promise<void> {
|
| 39 |
+
const el = document.createElement('section');
|
| 40 |
+
Object.assign(el.style, {
|
| 41 |
+
padding: '1.6rem',
|
| 42 |
+
background: 'radial-gradient(circle at top left,#0f172a 0%,#1e293b 40%,#020617 100%)',
|
| 43 |
+
border: '1px solid #6366f1',
|
| 44 |
+
borderRadius: '20px',
|
| 45 |
+
color: '#f1f5f9',
|
| 46 |
+
fontFamily: 'Fira Code, monospace',
|
| 47 |
+
margin: '1.5rem 0',
|
| 48 |
+
lineHeight: '1.6',
|
| 49 |
+
boxShadow: '0 0 30px rgba(99,102,241,0.25)',
|
| 50 |
+
} as Partial<CSSStyleDeclaration>);
|
| 51 |
+
|
| 52 |
+
el.innerHTML = (await Promise.all(md.map((m) => marked.parse(m)))).join('');
|
| 53 |
+
document.body.appendChild(el);
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
// ──────────────────────────────────────────────────────────────
|
| 57 |
+
// Helpers
|
| 58 |
+
// ──────────────────────────────────────────────────────────────
|
| 59 |
+
|
| 60 |
+
const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
|
| 61 |
+
|
| 62 |
+
async function chat(messages: ChatCompletionMessageParam[]): Promise<string> {
|
| 63 |
+
const rsp = await openai.chat.completions.create({ model: 'gemini-2.0-flash', messages });
|
| 64 |
+
const out = rsp.choices?.[0]?.message?.content ?? '';
|
| 65 |
+
if (!out) throw new Error('LLM yielded empty');
|
| 66 |
+
return out;
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
// ──────────────────────────────────────────────────────────────
|
| 70 |
+
// Prompts for FGL
|
| 71 |
+
// ──────────────────────────────────────────────────────────────
|
| 72 |
+
|
| 73 |
+
const SYS_PROMPT =
|
| 74 |
+
'You are FGL‑Core, a cosmic compiler forged by James Burvel O’Callaghan III. Your task: crystallise Fractal Genesis Language, a DSL for designing holographic realities and 13‑dimensional hyperframes. Emit concise Markdown with syntax blocks, metaphysical notes, and practical simulation hooks.';
|
| 75 |
+
|
| 76 |
+
const CONSTRUCT_PROMPT = (n: number) => `### Construct ${n}
|
| 77 |
+
Define Construct ${n} of FGL.
|
| 78 |
+
Include:
|
| 79 |
+
1. **Syntax pattern** – formal grammar.
|
| 80 |
+
2. **Sample \`fgl\` code**.
|
| 81 |
+
3. **Underlying metaphysics** – e.g., tesseract mapping, state‑vector displacement.
|
| 82 |
+
4. **Applied use‑case** – rendering cosmic scenes, morphing temporal logic, or tuning quantum chips.`;
|
| 83 |
+
|
| 84 |
+
// ──────────────────────────────────────────────────────────────
|
| 85 |
+
// Loop control
|
| 86 |
+
// ──────────────────────────────────────────────────────────────
|
| 87 |
+
|
| 88 |
+
let stop = false;
|
| 89 |
+
(window as any).stopLoop = () => (stop = true);
|
| 90 |
+
|
| 91 |
+
(async () => {
|
| 92 |
+
try {
|
| 93 |
+
await consoleRender('# 🌌 FGL Genesis Console', 'Spinning reality fibres…');
|
| 94 |
+
|
| 95 |
+
const MAX = 40; // language constructs
|
| 96 |
+
for (let c = 1; c <= MAX; c++) {
|
| 97 |
+
if (stop) break;
|
| 98 |
+
|
| 99 |
+
let backoff = 2500;
|
| 100 |
+
while (true) {
|
| 101 |
+
try {
|
| 102 |
+
const def = await chat([
|
| 103 |
+
{ role: 'system', content: SYS_PROMPT },
|
| 104 |
+
{ role: 'user', content: CONSTRUCT_PROMPT(c) },
|
| 105 |
+
]);
|
| 106 |
+
await consoleRender(`---\n\n## 🌀 Construct ${c}`, def);
|
| 107 |
+
break;
|
| 108 |
+
} catch (e) {
|
| 109 |
+
console.error(`Construct ${c} failed`, e);
|
| 110 |
+
await sleep(backoff);
|
| 111 |
+
backoff = Math.min(backoff * 2, 60000);
|
| 112 |
+
}
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
await sleep(4000);
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
await consoleRender('✨ **FGL genesis complete. Engage the matrix.**');
|
| 119 |
+
} catch (fatal) {
|
| 120 |
+
await consoleRender('💣 Fatal:', String(fatal));
|
| 121 |
+
}
|
| 122 |
+
})();
|
metadata.json
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "Copy of OpenAI SDK compatibility",
|
| 3 |
+
"description": "Access Gemini models with the OpenAI SDK",
|
| 4 |
+
"requestFramePermissions": [],
|
| 5 |
+
"prompt": ""
|
| 6 |
+
}
|
package.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "copy-of-openai-sdk-compatibility",
|
| 3 |
+
"private": true,
|
| 4 |
+
"version": "0.0.0",
|
| 5 |
+
"type": "module",
|
| 6 |
+
"scripts": {
|
| 7 |
+
"dev": "vite",
|
| 8 |
+
"build": "vite build",
|
| 9 |
+
"preview": "vite preview"
|
| 10 |
+
},
|
| 11 |
+
"dependencies": {
|
| 12 |
+
"marked": "^15.0.8",
|
| 13 |
+
"openai": "^4.94.0"
|
| 14 |
+
},
|
| 15 |
+
"devDependencies": {
|
| 16 |
+
"@types/node": "^22.14.0",
|
| 17 |
+
"typescript": "~5.7.2",
|
| 18 |
+
"vite": "^6.2.0"
|
| 19 |
+
}
|
| 20 |
+
}
|
tsconfig.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"compilerOptions": {
|
| 3 |
+
"target": "ES2020",
|
| 4 |
+
"experimentalDecorators": true,
|
| 5 |
+
"useDefineForClassFields": false,
|
| 6 |
+
"module": "ESNext",
|
| 7 |
+
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
| 8 |
+
"skipLibCheck": true,
|
| 9 |
+
|
| 10 |
+
/* Bundler mode */
|
| 11 |
+
"moduleResolution": "bundler",
|
| 12 |
+
"allowImportingTsExtensions": true,
|
| 13 |
+
"isolatedModules": true,
|
| 14 |
+
"moduleDetection": "force",
|
| 15 |
+
"noEmit": true,
|
| 16 |
+
"allowJs": true,
|
| 17 |
+
"jsx": "react-jsx",
|
| 18 |
+
|
| 19 |
+
/* Linting */
|
| 20 |
+
"strict": true,
|
| 21 |
+
"noUnusedLocals": true,
|
| 22 |
+
"noUnusedParameters": true,
|
| 23 |
+
"noFallthroughCasesInSwitch": true,
|
| 24 |
+
"noUncheckedSideEffectImports": true,
|
| 25 |
+
|
| 26 |
+
"paths": {
|
| 27 |
+
"@/*" : ["./*"]
|
| 28 |
+
}
|
| 29 |
+
}
|
| 30 |
+
}
|
vite.config.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import path from 'path';
|
| 2 |
+
import { defineConfig, loadEnv } from 'vite';
|
| 3 |
+
|
| 4 |
+
export default defineConfig(({ mode }) => {
|
| 5 |
+
const env = loadEnv(mode, '.', '');
|
| 6 |
+
return {
|
| 7 |
+
define: {
|
| 8 |
+
'process.env.API_KEY': JSON.stringify(env.API_KEY)
|
| 9 |
+
},
|
| 10 |
+
resolve: {
|
| 11 |
+
alias: {
|
| 12 |
+
'@': path.resolve(__dirname, '.'),
|
| 13 |
+
}
|
| 14 |
+
}
|
| 15 |
+
};
|
| 16 |
+
});
|