UNPKG

huggingface-chat

Version:

A lightweight and powerful Node.js API client for Hugging Face Chat. Interact with open-source LLMs like Llama 3, Mixtral, and Gemma for conversational AI, text generation, and more. Supports ESM and CJS modules.

91 lines 3.48 kB
/** * Login class for managing authentication and user sessions. */ export default class Login { private email; private password; private headers; private cookies; /** * Constructs a new instance of the Login class. * @param {string} email - huggingface email address. * @param {string} password - huggingface password. */ constructor(email: string, password: string); /** * Parses cookies into a formatted string. * @returns {string} A formatted string containing parsed cookies. */ private parseCookies; /** * Sends an HTTP GET request. * @param {string} url - The URL to send the GET request to. * @param {Record<string, any>} _params - Optional query parameters for the request. * @returns {Promise<{ status: number, headers: Headers, data: string }>} A Promise that resolves to the HTTP response. */ get(url: string, _params?: Record<string, any>): Promise<{ status: number; headers: Headers; data: string; }>; /** * Sends an HTTP POST request. * @param {string} url - The URL to send the POST request to. * @param {Record<string, any>} data - Data to include in the request body. * @param {Record<string, any>} _headers - Optional additional headers for the request. * @returns {Promise<{ status: number, headers: Headers, data: string }>} A Promise that resolves to the HTTP response. */ post(url: string, data?: Record<string, any>, _headers?: Record<string, any>): Promise<{ status: number; headers: Headers; data: string; }>; /** * Refreshes cookies based on the response headers. * @param {Headers} headers - The HTTP response headers. */ private refreshCookies; /** * Attempts to sign in with the provided email and password. * @throws {Error} If the sign-in fails. */ private signinWithEmail; /** * Retrieves the authentication URL for a chat. * @returns {Promise<string>} A Promise that resolves to the authentication URL. * @throws {Error} If the URL retrieval fails. */ private getAuthUrl; /** * Extracts CSRF token from a string. * @param {string} input - The input string containing CSRF information. * @returns {string | null} The extracted CSRF token or null if not found. */ private getCrpf; /** * Grants authorization by following redirects. * @param {string} url - The URL to grant authorization for. * @returns {Promise<number>} A Promise that resolves to a status code. * @throws {Error} If the authorization process fails. */ private grantAuth; /** * Initiates the login process. * @param {string} cache_path - Optional path for caching login data. * @returns {Promise<string>} A Promise that resolves to the parsed cookies. * @throws {Error} If the login process fails. */ login(cache_path?: string, force?: boolean): Promise<string>; /** * Caches login data to a file. * @param {string} path - The path where login data will be cached. */ private cacheLogin; /** * Loads cached login data from a file. * @param {string} path - The path to the cached login data file. * @returns {Promise<string>} A Promise that resolves to the cached login data. */ loadLoginCache(path: string): Promise<string>; } //# sourceMappingURL=login.d.ts.map