Fix Brain Cloud documentation and clarify it's a service, not a package
Critical corrections: - Brain Cloud is NOT a separate npm package (@soulcraft/brain-cloud doesn't exist) - It's a managed service at soulcraft.com that auto-loads augmentations - Fixed all incorrect import statements and package references - Clarified that brainy cloud auth configures features based on subscription - Removed problematic modelLoader.ts (had TypeScript compilation errors) Documentation updates: - README: Corrected Brain Cloud setup instructions - BRAINY_VS_BRAIN_CLOUD: Clarified service vs package distinction - CLI: Updated messages to reflect Brain Cloud is not an npm package This is a documentation fix only - no functional changes to the core library.
This commit is contained in:
parent
79bfcb8528
commit
09631feada
3 changed files with 15 additions and 110 deletions
|
|
@ -1,93 +0,0 @@
|
|||
/**
|
||||
* Smart Model Loader - Zero Configuration ML Models
|
||||
* Downloads models on-demand, caches intelligently
|
||||
*/
|
||||
|
||||
export class SmartModelLoader {
|
||||
private static readonly MODEL_SOURCES = [
|
||||
// 1. Check if bundled locally
|
||||
'./models',
|
||||
'../models',
|
||||
|
||||
// 2. Check user's cache
|
||||
'~/.brainy/models',
|
||||
|
||||
// 3. Check CDN (fast, free)
|
||||
'https://cdn.jsdelivr.net/npm/@brainy/models@latest',
|
||||
'https://unpkg.com/@brainy/models',
|
||||
|
||||
// 4. Check Hugging Face (original source)
|
||||
'https://huggingface.co/Xenova/all-MiniLM-L6-v2/resolve/main'
|
||||
]
|
||||
|
||||
static async loadModel(modelName: string): Promise<ArrayBuffer> {
|
||||
// Try each source in order
|
||||
for (const source of this.MODEL_SOURCES) {
|
||||
try {
|
||||
const model = await this.tryLoadFrom(source, modelName)
|
||||
if (model) {
|
||||
await this.cacheLocally(model, modelName)
|
||||
return model
|
||||
}
|
||||
} catch {
|
||||
continue // Try next source
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback: Generate lightweight random embeddings
|
||||
console.warn('Using fallback embeddings (reduced accuracy)')
|
||||
return this.generateFallbackModel(modelName)
|
||||
}
|
||||
|
||||
private static async tryLoadFrom(source: string, model: string): Promise<ArrayBuffer | null> {
|
||||
if (source.startsWith('http')) {
|
||||
// Download from CDN
|
||||
const response = await fetch(`${source}/${model}`)
|
||||
if (response.ok) {
|
||||
return await response.arrayBuffer()
|
||||
}
|
||||
} else {
|
||||
// Check local filesystem
|
||||
try {
|
||||
const fs = await import('fs')
|
||||
return fs.readFileSync(`${source}/${model}`)
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
private static async cacheLocally(model: ArrayBuffer, name: string): Promise<void> {
|
||||
// Cache in best available location
|
||||
if (typeof window !== 'undefined' && 'caches' in window) {
|
||||
// Browser: Use Cache API
|
||||
const cache = await caches.open('brainy-models')
|
||||
await cache.put(name, new Response(model))
|
||||
} else if (typeof process !== 'undefined') {
|
||||
// Node: Use filesystem cache
|
||||
const fs = await import('fs')
|
||||
const path = await import('path')
|
||||
const cacheDir = path.join(process.env.HOME || '', '.brainy', 'models')
|
||||
fs.mkdirSync(cacheDir, { recursive: true })
|
||||
fs.writeFileSync(path.join(cacheDir, name), Buffer.from(model))
|
||||
}
|
||||
}
|
||||
|
||||
private static generateFallbackModel(name: string): ArrayBuffer {
|
||||
// Deterministic "random" embeddings based on input
|
||||
// Good enough for development/testing
|
||||
const seed = name.split('').reduce((a, b) => a + b.charCodeAt(0), 0)
|
||||
const model = new Float32Array(384) // Standard embedding size
|
||||
for (let i = 0; i < model.length; i++) {
|
||||
model[i] = Math.sin(seed * (i + 1)) * 0.1
|
||||
}
|
||||
return model.buffer
|
||||
}
|
||||
}
|
||||
|
||||
// Usage - Zero configuration required!
|
||||
export async function getEmbedding(text: string): Promise<Float32Array> {
|
||||
const model = await SmartModelLoader.loadModel('encoder.onnx')
|
||||
// ... use model
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue