Skip to content

Commit

Permalink
yay
Browse files Browse the repository at this point in the history
  • Loading branch information
adnan wahab committed Oct 21, 2024
1 parent b0085bf commit e1858bf
Show file tree
Hide file tree
Showing 11 changed files with 469 additions and 112 deletions.
7 changes: 7 additions & 0 deletions scripts/infra/caddy/Caddyfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ hashirama.blog {
resolvers 1.1.1.1
}

route /ws/* {
reverse_proxy localhost:3333 {
header_up Connection {>Connection}
header_up Upgrade {>Upgrade}
}
}

route /* {
reverse_proxy localhost:3333
}
Expand Down
33 changes: 33 additions & 0 deletions web-ui/docs/Flaws-in-Facebooks-Data-Pipeline.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

facebook is cool. llama is one of my favroite things ever!


llama is perhaps one of the most humane technologies on earth!!!!


but, sometimes instagram says people are fake when they are real :(


i wish they just used a slightly more better bayesian spam filter - heres a diagram.


but besdies this one small issue, i think meta is one of the most undervalued companies on earth

because peopel are what change the world, not technology.


i love llama :)


if you buy 3-4 used GPUS for 700 each - you can make 1 million in 90 days -- anyone can do it!!!



but if everyone does it , there will be notyhing left to do :(


one thing that can be infinite --- above software is hardware because -- -- chat bots can do anything - - except glue atoms together.


people who work with their hands will be the last to be automated, in facct they never will be.
to be continued..... (living bag that never stops imprving lo l)
3 changes: 3 additions & 0 deletions web-ui/docs/blag/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,6 @@ Advanced Computer Graphics Techniques
4. Voxels and Stixels
5. Server Side WebGPU Streaming
6. Ray Tracing (2D and 3D) - Visibility

# Miscellaneous
1. Flaws in Facebooks Data Pipeline
8 changes: 8 additions & 0 deletions web-ui/docs/designing strema game - ----
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
designing strema game - ----



everyone in the world could play saem game


they be desiginersi for quests that hey yget ive to orobot and then together tod oa epic group quests wow
2 changes: 1 addition & 1 deletion web-ui/js/LLAMA_Tools.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function LLAMA_Tools () {

{/* <div>LLAMA Tools for JP, Abid, Raffi, Eric, and Mark</div> */}
{/* <div><Dashboard panels={panels} /></div> */}
<iframe width="900" height="500" src="http://localhost:8000"></iframe>
{/* <iframe width="900" height="500" src="http://localhost:8000"></iframe> */}
<Grid />
</>

Expand Down
116 changes: 97 additions & 19 deletions web-ui/js/bun-helper-server.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
const { EgressClient, RoomCompositeEgressRequest } = require('livekit-server-sdk');

const ollama = require('ollama');
import {$} from 'bun'
import { renderToString } from "react-dom/server";
import React, { Suspense, lazy } from 'react';
import React, {lazy } from 'react';
import Bun from 'bun'
import fs from "fs";
import path from "path";
import { connect_to_livekit } from './bun_handlers/bun-livekit-server.js'
import llamaRoutes from './bun_handlers/llama-backend.js'
import CgiRoutes from './bun_handlers/cgi-backend.js'
import { renderToReadableStream } from 'react-dom/server';
//import { startEgress } from './bun_handlers/bun-livekit-server.js'
//import { renderToReadableStream } from 'react-dom/server';
import TurndownService from 'turndown';

const port = 8080;
const port = 8003;
console.log(`Server running at http://localhost:${port}`);

const LlamaGrid = lazy(() => import('./llama-grid.tsx'));
Expand All @@ -31,22 +34,22 @@ async function serveLlamaTools(req: Request) {
const filePath = path.join(process.cwd(), "js/views/blag.html");
let indexHtmlContent = fs.readFileSync(filePath, "utf-8");

const stream = await renderToReadableStream(
<React.Suspense fallback={<div>Loading...</div>}>
const result = await renderToString(

<LlamaGrid />
</React.Suspense>

);

// Wait for all content to be ready
await stream.allReady;

const reader = stream.getReader();
let result = '';
while (true) {
const { done, value } = await reader.read();
if (done) break;
result += new TextDecoder().decode(value);
}
// await stream.allReady;

// const reader = stream.getReader();
// let result = '';
// while (true) {
// const { done, value } = await reader.read();
// if (done) break;
// result += new TextDecoder().decode(value);
// }

const htmlContent = indexHtmlContent.replace(
"{{template blag}}",
Expand Down Expand Up @@ -159,6 +162,79 @@ async function serveBlagArchive(req: Request) {
}
}

function saveScreenShare() {

}

async function startEgress(roomName) {
const { EgressClient, RoomServiceClient } = require('livekit-server-sdk');
const apiKey = process.env.LIVEKIT_API_KEY;
const apiSecret = process.env.LIVEKIT_API_SECRET;
const wsUrl = process.env.LIVEKIT_WS_URL;

const egressClient = new EgressClient(wsUrl, apiKey, apiSecret);
const roomService = new RoomServiceClient(wsUrl, apiKey, apiSecret);

const outputParams = {
file: {
filepath: `./screen-share.mp4`, // Ensure this path is valid and writable
},
};

const request = {
room_name: roomName,
output: outputParams,
};

// Check if outputParams is correctly structured
if (!outputParams.file || !outputParams.file.filepath) {
throw new Error("Output parameters are not correctly defined.");
}

// Initiate egress
const response = await egressClient.startRoomCompositeEgress(request);
console.log('Egress response:', response);
}


function ReplayAnalyzer() {
startEgress('example-room')
return (<div className="max-w-4xl mx-auto p-6">
<h1 className="text-3xl font-bold text-center text-gray-800 mb-6">Replay Analyzer</h1>

<div className="bg-white shadow-md rounded-lg p-6">
<form className="mb-4">
<label htmlFor="file-upload" className="block text-gray-700 mb-2">Upload Replay File:</label>
<input type="file" id="file-upload" className="block w-full text-gray-700 border border-gray-300 rounded p-2" accept=".replay"/>

<button type="submit" className="mt-4 w-full bg-blue-500 text-white font-semibold py-2 rounded hover:bg-blue-600">Analyze Replay</button>
</form>

<div id="analysis-result" className="hidden mt-4 p-4 bg-green-100 border-l-4 border-green-500 text-green-700">
<p>Results of the replay analysis will appear here...</p>
</div>
</div>

<footer className="mt-6 text-center">
<p className="text-gray-500">&copy; 2023 Replay Analyzer. All rights reserved.</p>
</footer>
</div>
);
}


function replay_analyzer(req: Request) {
const replay_html = renderToString(<ReplayAnalyzer />)


return new Response(replay_html, {
headers: {
"Content-Type": "text/html",
},
});
}


const CgiRoutesHandlers = Object.fromEntries(
Object.entries(CgiRoutes).map(([key, value]) => [`/cgi-tools${key}`, value])
);
Expand All @@ -167,7 +243,8 @@ const llamaRoutesHandlers = Object.fromEntries(
Object.entries(llamaRoutes).map(([key, value]) => [`/llama-tools${key}`, value])
);
const routes = {
"/livekit_connect": (req: Request) => livekit_connect(req),
"/api/livekit_connect": (req: Request) => livekit_connect(req),
"/api/replay_analyzer": (req: Request) => replay_analyzer(req),
///"/os/*": (req: Request) => os_automation(req),
"/docs": (req: Request) => docs_response(routes),
"/": (req: Request) => serveBlag(req),
Expand Down Expand Up @@ -262,9 +339,9 @@ async function fetch(req: Request) {


async function livekit_connect(req: Request) {
const jsonData = await req.json();
console.log('Received JSON data:', jsonData);

//const jsonData = await req.json();
//console.log('Received JSON data:', jsonData);
const jsonData = {identity: 'voice to prompt?' + Date.now()}
const identity = jsonData.identity;
if (!identity) {
return new Response("Identity parameter is missing", { status: 400 });
Expand Down Expand Up @@ -432,3 +509,4 @@ function makeReactApp(component_name) {




42 changes: 22 additions & 20 deletions web-ui/js/bun_handlers/bun-livekit-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,24 +72,26 @@ import { spawn } from "bun";
// const apiKey = process.env.LIVEKIT_API_KEY
// const apiSecret = process.env.LIVEKIT_API_SECRET

// const egressClient = new EgressClient(livekitHost, apiKey, apiSecret);
// // https://dev.twitch.tv/docs/api/
// //microbox + microsaur -
// //localhost -> connects to tailscale serve / funnel -> auto symlink to mothership - 4pb desktopx4
// async function startEgress() {
// const request = RoomCompositeEgressRequest.fromPartial({
// roomName: 'example-room',
// layout: 'speaker-dark',
// audioOnly: true,
// fileOutputs: [
// {
// fileType: 'OGG', // LiveKit supports OGG for audio-only recordings
// filepath: '/audio.ogg',
// },
// ],
// });
const egressClient = new EgressClient(wsUrl, apiKey, apiSecret);
// https://dev.twitch.tv/docs/api/
//microbox + lamasaur - homeage to nanosaur.ai (nanosaur w/ pi)
//localhost -> connects to tailscale serve / funnel -> auto symlink to mothership - 4pb desktopx4
async function startEgress() {
const request = RoomCompositeEgressRequest.fromPartial({
roomName: 'example-room',
layout: 'speaker-dark',
audioOnly: true,
fileOutputs: [
{
fileType: 'OGG', // LiveKit supports OGG for audio-only recordings
filepath: '/audio.ogg',
},
],
});

const response = await egressClient.startRoomCompositeEgress(request);
console.log('Egress started with egress ID:', response.egressId);
return response.egressId
}

// const response = await egressClient.startRoomCompositeEgress(request);
// console.log('Egress started with egress ID:', response.egressId);
// return response.egressId
// }
export { startEgress }
76 changes: 75 additions & 1 deletion web-ui/js/bun_main_server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,55 @@ const port = 3333;
////then youge tto read papers not write app code ---- vp of eng not a junir odev.

Bun.serve({
websocket: {
open(ws) {
console.log("WebSocket connection opened");
},
message(ws, message) {
console.log("Received message:", message);
// Handle the WebSocket message here
// You might want to forward this to your Vite server if needed
},
close(ws, code, message) {
console.log("WebSocket connection closed");
},
},
port, // The port your proxy server will listen on
async fetch(req) {
const url = new URL(req.url);
url.port = "8001"; // Forward to Vite server's port
url.hostname = "localhost"; // Assuming Vite is running locally

if (url.pathname === '/ollama') {
return new Response(JSON.stringify({ message: 'ok' }), {
headers: { 'Content-Type': 'application/json' },
});
}

if (url.pathname.startsWith('/api')) {
// return new Response(JSON.stringify({ message: 'ok' }), {
// headers: { 'Content-Type': 'application/json' },
// });
// Proxy the entire request to port 8080
url.port = "8003"; // Forward to the server running on port 8080
url.hostname = "localhost"; // Assuming the server is running locally

try {
// Forward the request to the server running on port 8080
const response = await fetch(url.toString(), {
method: req.method,
headers: req.headers,
body: req.body,
duplex: 'half', // Necessary for streaming request bodies
});

return response; // Return the server's response to the client
} catch (error) {
console.error('Error proxying request:', error);
return new Response('Internal Server Error', { status: 500 });
}
}

try {
// Forward the request to the Vite server
const response = await fetch(url.toString(), {
Expand All @@ -31,5 +74,36 @@ Bun.serve({
return new Response('Internal Server Error', { status: 500 });
}
},

});
console.log("server running on port", port);
console.log("server running on port", port);



import { spawn } from 'child_process';

function startBunHelperServer() {
const bunHelperServer = spawn('bun', ['js/bun-helper-server.tsx'], {
stdio: 'inherit',
});

bunHelperServer.on('close', (code) => {
console.log(`bun-helper-server.tsx process exited with code ${code}`);
});

bunHelperServer.on('error', (err) => {
console.error('Failed to start bun-helper-server.tsx:', err);
});

const fs = require('fs');

fs.watch('js', { recursive: true }, (eventType, filename) => {
if (filename) {
console.log(`File changed: ${filename}. Restarting bun-helper-server...`);
bunHelperServer.kill();
startBunHelperServer();
}
});
}

startBunHelperServer();
Loading

0 comments on commit e1858bf

Please sign in to comment.