remcode
Version:
Turn your AI assistant into a codebase expert. Intelligent code analysis, semantic search, and software engineering guidance through MCP integration.
53 lines (52 loc) • 1.58 kB
TypeScript
/**
* HuggingFace MCP Handler
*
* Handles HuggingFace-related MCP requests, allowing AI assistants
* to generate embeddings for code vectorization.
*
* Fixed: Uses correct HuggingFace Inference API with working models
*/
import { Request, Response } from 'express';
export interface HuggingFaceMCPOptions {
token: string;
}
export declare class HuggingFaceMCPHandler {
private options;
private baseUrl;
private initialized;
private workingModel;
private healthCheckedModels;
constructor(options: HuggingFaceMCPOptions);
initialize(): Promise<void>;
/**
* Find a working embedding model from our hierarchy
*/
private findWorkingModel;
/**
* Check if a model is healthy and available
*/
private checkModelHealth;
handleRequest(req: Request, res: Response): Promise<void>;
handleToolRequest(req: Request, res: Response): Promise<void>;
private getEmbeddings;
/**
* Get embedding from model using correct HuggingFace Inference API format
* Uses the same patterns as the working EmbeddingManager
*/
private getEmbeddingFromModel;
/**
* Process embedding result from API (same logic as EmbeddingManager)
*/
private processEmbeddingResult;
/**
* Preprocess text for better embedding quality (same as EmbeddingManager)
*/
private preprocessText;
/**
* Average token embeddings to get a single vector
*/
private averageEmbeddings;
private handleEmbedCode;
private handleEmbedQuery;
private handleListModels;
}