Skip to main content
Glama
local-adapter.js2.55 kB
/** * @fileoverview LocalAdapter - Qwen2.5-Coder-7B via vLLM * @module backends/local-adapter * * Wraps Smart AI Bridge's existing local backend implementation. * Created for Smart AI Bridge v1.3.0 */ import { BackendAdapter } from './backend-adapter.js'; class LocalAdapter extends BackendAdapter { /** * Create a LocalAdapter * @param {Object} [config] - Configuration overrides */ constructor(config = {}) { super({ name: 'local', type: 'local', url: process.env.VLLM_ENDPOINT || 'http://127.0.0.1:4141', maxTokens: config.maxTokens || 65536, timeout: config.timeout || 120000, streaming: false, ...config }); this.model = config.model || 'Qwen/Qwen2.5-Coder-7B-Instruct'; } /** * Make request to local vLLM endpoint * @param {string} prompt - The prompt to send * @param {Object} [options] - Request options * @returns {Promise<Object>} */ async makeRequest(prompt, options = {}) { const requestBody = { model: this.model, messages: [{ role: 'user', content: prompt }], max_tokens: options.maxTokens || this.config.maxTokens, temperature: options.temperature || 0.7, stream: false }; try { const response = await fetch(`${this.config.url}/v1/chat/completions`, { method: 'POST', headers: this.buildHeaders(), body: JSON.stringify(requestBody), signal: AbortSignal.timeout(this.config.timeout) }); if (!response.ok) { throw new Error(`Local backend error: ${response.status} ${response.statusText}`); } const data = await response.json(); return this.parseResponse(data); } catch (error) { throw new Error(`Local backend request failed: ${error.message}`); } } /** * Check health of local backend * @returns {Promise<Object>} */ async checkHealth() { const startTime = Date.now(); try { const response = await fetch(`${this.config.url}/health`, { method: 'GET', signal: AbortSignal.timeout(5000) }); const healthy = response.ok; const latency = Date.now() - startTime; this.lastHealth = { healthy, latency, checkedAt: new Date() }; return this.lastHealth; } catch (error) { this.lastHealth = { healthy: false, latency: Date.now() - startTime, error: error.message, checkedAt: new Date() }; return this.lastHealth; } } } export { LocalAdapter };

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Platano78/Smart-AI-Bridge'

If you have feedback or need assistance with the MCP directory API, please join our Discord server