### Install LLM.js via npm Source: https://github.com/themaximalist/llm.js/blob/main/README.md Shows the command to install the LLM.js library using npm, the Node Package Manager. ```bash npm install @themaximalist/llm.js ``` -------------------------------- ### Install LLM.js via NPM Source: https://github.com/themaximalist/llm.js/blob/main/public/index.html This snippet shows the command to install the LLM.js library using npm, which is the standard package manager for Node.js. ```bash npm install @themaximalist/llm.js ``` -------------------------------- ### LLM.js Extended Response Example Source: https://github.com/themaximalist/llm.js/blob/main/public/index.html Illustrates how to get extended information from an LLM.js request, including content, token usage, the service provider, and the full conversation history. ```javascript const response = await LLM("what are the primary colors?", { extended: true }); console.log(response.content); // "The primary colors are red, blue, and yellow" console.log(response.usage); // { input_tokens: 6, output_tokens: 12, total_cost: 0.0001 } console.log(response.service); // "ollama" console.log(response.messages); // Full conversation history ``` -------------------------------- ### Basic LLM Initialization and Call (JavaScript) Source: https://github.com/themaximalist/llm.js/blob/main/README.md Provides a basic example of importing and using the LLM.js library as an async function for a single request, returning a string response. ```javascript import LLM from "@themaximalist/llm.js" await LLM("hello"); // Response: hi ``` -------------------------------- ### System Instruction Configuration Source: https://github.com/themaximalist/llm.js/blob/main/public/docs/interfaces/GoogleOptions.html Defines the configuration for system instructions, which include parts with text content. This is used to guide the model's behavior. ```typescript system_instruction?: { parts: { text: string }[] } ``` -------------------------------- ### Connection Verification Source: https://github.com/themaximalist/llm.js/blob/main/README.md Verify your setup and API keys with built-in connection verification. This performs a light check to ensure services and API keys are working correctly. ```APIDOC ## Connection Verification ### Description Tests your setup and API keys with built-in connection verification. This is a light check that doesn't perform a full LLM chat response; for non-local services, it detects if models can be fetched, and for local services, if an instance is running. ### Method N/A (Library Usage) ### Endpoint N/A (Library Usage) ### Parameters N/A ### Request Example ```javascript const llm = new LLM({ service: "openai" }); const isConnected = await llm.verifyConnection(); console.log(isConnected); // true if API key and service work ``` ``` -------------------------------- ### LLM.js Chat with System Prompt and Streaming Source: https://github.com/themaximalist/llm.js/blob/main/public/index.html Shows how to configure a system message for the LLM and then stream chat responses using LLM.js, illustrating a conversational AI setup. ```javascript const llm = new LLM({ stream: false }); llm.system("You are a friendly AI assistant"); const stream = await llm.chat("hello, how are you?", { stream: true }); for await (const chunk of stream) { process.stdout.write(chunk); } ``` -------------------------------- ### Streaming Response Example with LLM.js Source: https://github.com/themaximalist/llm.js/blob/main/public/index.html Illustrates how to handle streaming responses from an LLM using LLM.js. This allows for real-time display of the LLM's output as it's being generated. ```javascript import { LLM } from "@llm.js/core" const llm = new LLM({ provider: "openai", model: "gpt-3.5-turbo", apiKey: "YOUR_API_KEY" }) async function streamExample() { const stream = await llm.stream( "Tell me a short story." ) for await (const chunk of stream) { process.stdout.write(chunk) } console.log() } streamExample() ``` -------------------------------- ### Initialize Theme and Show Page (JavaScript) Source: https://github.com/themaximalist/llm.js/blob/main/public/docs/functions/parsers.markdown.html Sets the document theme based on local storage and displays the application page after a short delay. It handles cases where the 'app' object might not be immediately available. ```javascript document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os"; document.body.style.display="none"; setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500) ``` -------------------------------- ### Initialize Theme and Show App - JavaScript Source: https://github.com/themaximalist/llm.js/blob/main/public/docs/modules.html Sets the document theme from local storage and conditionally displays the application or removes a display style from the body after a short delay. This script likely handles initial UI setup and theme persistence. ```javascript document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os"; document.body.style.display="none"; setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500) ``` -------------------------------- ### Initialize Theme and Show App Source: https://github.com/themaximalist/llm.js/blob/main/public/docs/index.html This snippet initializes the document's theme based on local storage and conditionally shows the application page or removes the display style from the body. It waits for 500ms before executing. ```javascript document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os"; document.body.style.display="none"; setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500) ``` -------------------------------- ### Install LLM.js using npm Source: https://github.com/themaximalist/llm.js/blob/main/public/index.html This snippet shows the command to install the LLM.js library using npm, the Node Package Manager. It's the standard way to add LLM.js as a dependency to your JavaScript project. ```bash npm install @llm.js/core ``` -------------------------------- ### Initialize Theme and Show App Source: https://github.com/themaximalist/llm.js/blob/main/public/docs/interfaces/Options.html Sets the theme from local storage and controls the initial display of the application body. It delays the visibility of the app content until after a short timeout. ```javascript document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os"; document.body.style.display="none"; setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500) ``` -------------------------------- ### Get and Refresh All Models with LLM.js Source: https://github.com/themaximalist/llm.js/blob/main/README.md Demonstrates how to retrieve all cached language models and refresh the list from external sources using the ModelUsage class. It also shows how to get details for a specific model, such as its input cost per token and maximum input tokens. ```javascript import { ModelUsage } from "@themaximalist/llm.js"; // Get all cached models const allModels = ModelUsage.getAll(); console.log(allModels.length); // 100+ // Refresh from latest sources const refreshedModels = await ModelUsage.refresh(); console.log(refreshedModels.length); // Even more models // Get specific model info const gpt4 = ModelUsage.get("openai", "gpt-4o"); console.log(gpt4.input_cost_per_token); // 0.0000025 console.log(gpt4.max_input_tokens); // 128000 ``` -------------------------------- ### LLM Initialization with Options Source: https://github.com/themaximalist/llm.js/blob/main/README.md Shows how to instantiate and configure LLM.js with various options. These options control the LLM service provider, API key, model selection, response generation parameters, and more. ```javascript const llm = new LLM(input, { service: "openai", // LLM service provider apiKey: "sk-123" // apiKey model: "gpt-4o", // Specific model max_tokens: 1000, // Maximum response length temperature: 0.7, // "Creativity" (0-2) stream: true, // Enable streaming extended: true, // Extended responses with metadata messages: [], // message history think: true, // Enable thinking mode parser: LLM.parsers.json, // Content parser tools: [...], // Available tools max_thinking_tokens: 500, // Max tokens for thinking }); ``` -------------------------------- ### GET /models/customs Source: https://github.com/themaximalist/llm.js/blob/main/public/docs/classes/ModelUsage.html Retrieves all custom model configurations across all services and models. ```APIDOC ## GET /models/customs ### Description Retrieves all custom model configurations available in the system. ### Method GET ### Endpoint /models/customs ### Parameters No parameters required. ### Response #### Success Response (200) - **customModels** (Record) - An object where keys are service names and values are arrays of model usage types. #### Response Example ```json { "openai": [ { "service": "openai", "model": "gpt-3.5-turbo", "usage": 10000 } ], "anthropic": [ { "service": "anthropic", "model": "claude-2", "usage": 5000 } ] } ``` ``` -------------------------------- ### Initialize Theme and Show App Page Source: https://github.com/themaximalist/llm.js/blob/main/public/docs/classes/xAI.html This snippet initializes the document's theme from local storage and controls the display of the application page. It hides the body initially and then reveals the page content after a short delay, ensuring the app is ready. ```javascript document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os"; document.body.style.display="none"; setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500) ``` -------------------------------- ### Switching LLM Models and Providers Source: https://github.com/themaximalist/llm.js/blob/main/README.md Illustrates how to easily switch between different Large Language Models and providers using LLM.js. This includes examples for local providers like Ollama and remote services like OpenAI, Anthropic, Google, and xAI. ```javascript // Defaults to Ollama (local) await LLM("the color of the sky is"); // OpenAI await LLM("the color of the sky is", { model: "gpt-4o-mini", service: "openai" }); // Anthropic await LLM("the color of the sky is", { model: "claude-3-5-sonnet-latest", service: "anthropic" }); // Google await LLM("the color of the sky is", { model: "gemini-1.5-pro", service: "google" }); // xAI await LLM("the color of the sky is", { service: "xai", model: "grok-beta" }); // DeepSeek with thinking await LLM("solve this puzzle", { service: "deepseek", model: "deepseek-reasoner", think: true }); // Ollama (local) await LLM("the color of the sky is", { model: "llama3.2:3b", service: "ollama" }); ``` -------------------------------- ### URL Management API Source: https://github.com/themaximalist/llm.js/blob/main/public/docs/classes/Groq.html Provides endpoints to get URLs related to chat and model information. ```APIDOC ## GET /chat/url ### Description Retrieves the URL for chat-related operations. ### Method GET ### Endpoint /chat/url ### Parameters #### Path Parameters None #### Query Parameters - **opts** (Options) - Required - Options for the chat URL. ### Request Example ```json { "opts": {} } ``` ### Response #### Success Response (200) - **urls** (string[]) - An array of chat-related URLs. #### Response Example ```json { "urls": ["https://api.example.com/chat"] } ``` ``` ```APIDOC ## GET /models/url ### Description Retrieves the base URL for accessing model information. ### Method GET ### Endpoint /models/url ### Parameters None ### Response #### Success Response (200) - **urls** (string[]) - An array containing the model endpoint URL. #### Response Example ```json { "urls": ["https://api.example.com/models"] } ``` ``` -------------------------------- ### Set Theme and Show Page - JavaScript Source: https://github.com/themaximalist/llm.js/blob/main/public/docs/modules/parsers.html Initializes the document's theme from local storage and conditionally displays the application page after a short delay. If the application object 'app' is not available, it reverts to showing the body element. ```javascript document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os"; document.body.style.display="none"; setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500) ``` -------------------------------- ### Get Models URL Source: https://github.com/themaximalist/llm.js/blob/main/public/docs/classes/Google.html Retrieves the URL for fetching models. This function overrides the base LLM implementation. ```typescript getModelsUrl(): string ``` -------------------------------- ### Get Models URL from LLM.ts Source: https://github.com/themaximalist/llm.js/blob/main/public/docs/classes/APIv1.html Retrieves the URL for accessing model information. This function is inherited from the base LLM class. ```typescript getModelsUrl(): string ``` -------------------------------- ### Initialize ModelUsage and Theme Setting Source: https://github.com/themaximalist/llm.js/blob/main/public/docs/classes/ModelUsage.html Sets the document theme from local storage and prepares the application by initially hiding the body and then revealing the app's main page after a short delay. ```typescript document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os"; document.body.style.display="none"; setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500) ``` -------------------------------- ### GET /models/custom Source: https://github.com/themaximalist/llm.js/blob/main/public/docs/classes/ModelUsage.html Retrieves custom model configurations for a specific service and model. Returns null if no custom configuration is found. ```APIDOC ## GET /models/custom ### Description Retrieves custom model configurations based on service and model identifiers. ### Method GET ### Endpoint /models/custom ### Parameters #### Query Parameters - **service** (string) - Required - The service identifier for the model. - **model** (string) - Required - The model identifier. ### Response #### Success Response (200) - **usageData** (ModelUsageType[]) - An array of model usage types or null. #### Response Example ```json [ { "service": "openai", "model": "gpt-3.5-turbo", "usage": 10000 } ] ``` ``` -------------------------------- ### Get Models URL Source: https://github.com/themaximalist/llm.js/blob/main/public/docs/classes/LLM.html Retrieves the URL endpoint for fetching model information. This method returns the models URL as a string. ```typescript getModelsUrl(): string ``` -------------------------------- ### Basic Chat Example with LLM.js Source: https://github.com/themaximalist/llm.js/blob/main/public/index.html Demonstrates a simple chat interaction using LLM.js. It initializes the LLM, sends a user message, and receives a response. This requires setting up the LLM provider and model. ```javascript import { LLM } from "@llm.js/core" const llm = new LLM({ provider: "openai", model: "gpt-3.5-turbo", apiKey: "YOUR_API_KEY" }) async function chatExample() { const response = await llm.chat( "Hello, how are you?" ) console.log(response) } chatExample() ``` -------------------------------- ### Get LLM Options Source: https://github.com/themaximalist/llm.js/blob/main/public/docs/classes/LLM.html Retrieves the default options for LLM interactions. This accessor returns an object conforming to the 'Options' interface. ```typescript get llmOptions(): [Options](../interfaces/Options.html) ``` -------------------------------- ### Theme Setting and Initialization Source: https://github.com/themaximalist/llm.js/blob/main/public/docs/interfaces/Tool.html This JavaScript snippet sets the document's theme based on local storage or defaults to 'os'. It then hides the body content and uses a timeout to reveal it, potentially showing an application page if available. ```javascript document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os"; document.body.style.display="none"; setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500) ``` -------------------------------- ### Theme and Display Initialization Source: https://github.com/themaximalist/llm.js/blob/main/public/docs/interfaces/GoogleTool.html Initializes the theme based on local storage and sets up a delay for displaying the page content. This code snippet handles the initial loading state and theme persistence. ```javascript document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os"; document.body.style.display="none"; setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500) ``` -------------------------------- ### Get Models by Service Source: https://github.com/themaximalist/llm.js/blob/main/public/docs/classes/ModelUsage.html Retrieves a list of all models associated with a specific service, or all models if no service is provided. Returns an array of ModelUsageType. ```typescript getByService(service?: string): ModelUsageType[][] ``` -------------------------------- ### Get Models URL (TypeScript) Source: https://github.com/themaximalist/llm.js/blob/main/public/docs/classes/Groq.html Retrieves the URL endpoint for fetching model information. Returns a string representing the models URL. ```typescript getModelsUrl(): string ``` -------------------------------- ### Set Theme from Local Storage and Show App Source: https://github.com/themaximalist/llm.js/blob/main/public/docs/types/Input.html This snippet sets the document's theme based on local storage or defaults to 'os'. It then hides the body and shows the app page after a 500ms delay, or removes the display property if the app is not available. This is commonly used for initial theme setup on page load. ```javascript document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os"; document.body.style.display="none"; setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500) ``` -------------------------------- ### Get Default Model Usage (TypeScript) Source: https://github.com/themaximalist/llm.js/blob/main/public/docs/classes/Groq.html Retrieves the default usage type for a given model. Returns a ModelUsageType enum value. ```typescript getDefaultModelUsage(model: Model): ModelUsageType ``` -------------------------------- ### Initialize Theme and Application Display Source: https://github.com/themaximalist/llm.js/blob/main/public/docs/variables/default.html This script sets the document's theme based on local storage or defaults to 'os'. It then hides the body and reveals the application or the body after a 500ms delay to ensure proper loading. ```javascript document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os"; document.body.style.display="none"; setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500) ``` -------------------------------- ### Get Models URL (TypeScript) Source: https://github.com/themaximalist/llm.js/blob/main/public/docs/classes/xAI.html Retrieves the URL for fetching the list of available models. This function returns the URL as a string. ```TypeScript getModelsUrl(): string ``` -------------------------------- ### LLMInterface - Constructor Overloads Source: https://github.com/themaximalist/llm.js/blob/main/public/docs/interfaces/LLMInterface.html Provides different ways to instantiate the LLMInterface, with or without input and options. ```APIDOC ## Constructors ### new LLMInterface(input: Input, options?: Options): LLMServices **Description**: Initializes a new LLMInterface with input and optional configurations. **Parameters**: * `input` (Input): The input for the LLM service. * `options` (Options, optional): Additional options for configuring the LLM service. **Returns** (LLMServices): An instance of LLMServices. ### new LLMInterface(options: Options): LLMServices **Description**: Initializes a new LLMInterface with optional configurations. **Parameters**: * `options` (Options): Options for configuring the LLM service. **Returns** (LLMServices): An instance of LLMServices. ### new LLMInterface(): LLMServices **Description**: Initializes a new LLMInterface with default configurations. **Returns** (LLMServices): An instance of LLMServices. ``` -------------------------------- ### Get Quality Models Source: https://github.com/themaximalist/llm.js/blob/main/public/docs/classes/Google.html Fetches a list of models specifically filtered by quality. This function is inherited from the base LLM class. ```typescript getQualityModels(): Promise ``` -------------------------------- ### Apply Theme and Show Page Source: https://github.com/themaximalist/llm.js/blob/main/public/docs/functions/parsers.json.html This JavaScript snippet applies a theme from local storage to the document's root element and then shows the application page after a short delay. It handles cases where the 'app' object might not be immediately available. ```javascript document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os"; document.body.style.display="none"; setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500) ``` -------------------------------- ### Get LLM Parsers Source: https://github.com/themaximalist/llm.js/blob/main/public/docs/classes/LLM.html Retrieves the parsers used for processing LLM responses. This accessor returns an object conforming to the 'Parsers' interface. ```typescript get parsers(): [Parsers](../interfaces/Parsers.html) ``` -------------------------------- ### Set Theme and Show Page (JavaScript) Source: https://github.com/themaximalist/llm.js/blob/main/public/docs/functions/parsers.codeBlock.html Sets the theme based on local storage and controls the page's display after a delay, potentially showing the app page or removing display properties. This script is likely for initializing the UI. ```javascript document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os"; document.body.style.display="none"; setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500) ``` -------------------------------- ### Get LLM Headers Source: https://github.com/themaximalist/llm.js/blob/main/public/docs/classes/LLM.html Retrieves the headers required for LLM requests. This accessor returns a Record of string keys and string values. ```typescript get llmHeaders(): Record ``` -------------------------------- ### Set Theme and Initialize App Source: https://github.com/themaximalist/llm.js/blob/main/public/docs/types/ModelUsageType.html This JavaScript code snippet is responsible for initializing the application's theme based on local storage and then conditionally displaying the application's main page. It includes a delay to ensure the app is ready before showing the content. ```javascript document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os"; document.body.style.display="none"; setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500) ``` -------------------------------- ### Get LLM Chat URL Source: https://github.com/themaximalist/llm.js/blob/main/public/docs/classes/LLM.html Retrieves the URL endpoint for chat-related operations. This accessor returns a string representing the chat URL. ```typescript get chatUrl(): string ``` -------------------------------- ### Get Default Model Usage from LLM.ts Source: https://github.com/themaximalist/llm.js/blob/main/public/docs/classes/APIv1.html Retrieves the default usage type for a given model. This method is inherited from the base LLM class. ```typescript getDefaultModelUsage(model: Model): ModelUsageType ``` -------------------------------- ### Initialize Theme and Display Settings Source: https://github.com/themaximalist/llm.js/blob/main/public/docs/types/MessageContent.html This script sets the document theme based on local storage and controls the initial display of the body element, revealing the app content after a short delay. ```javascript document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os"; document.body.style.display="none"; setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500) ``` -------------------------------- ### LLMInterface Constructor Overloads Source: https://github.com/themaximalist/llm.js/blob/main/public/docs/interfaces/LLMInterface.html Demonstrates the multiple ways to construct an LLMInterface instance. It supports initialization with input and options, only options, or no arguments, returning LLMServices. These constructors are key for setting up LLM interactions with varying configurations. ```typescript new LLMInterface(input: [Input](../types/Input.html), options?: [Options](Options.html)): [LLMServices](../types/LLMServices.html); ``` ```typescript new LLMInterface(options: [Options](Options.html)): [LLMServices](../types/LLMServices.html); ``` ```typescript new LLMInterface(): [LLMServices](../types/LLMServices.html); ``` -------------------------------- ### Get Chat URL from LLM.ts Source: https://github.com/themaximalist/llm.js/blob/main/public/docs/classes/APIv1.html Generates a chat URL based on provided options. This function inherits its implementation from the base LLM class. ```typescript getChatUrl(opts: Options): string ``` -------------------------------- ### Set Document Theme and Show App (JavaScript) Source: https://github.com/themaximalist/llm.js/blob/main/public/docs/types/ParserResponse.html Sets the document's theme based on local storage and controls the initial display of the application. It waits for 500ms before showing the page or removing the display style. ```javascript document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os"; document.body.style.display="none"; setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500) ``` -------------------------------- ### Get Chat URL API Source: https://github.com/themaximalist/llm.js/blob/main/public/docs/classes/Anthropic.html Generates a URL for initiating a chat session. This method inherits its functionality from the base LLM class. ```APIDOC ## GET /api/chat/url ### Description Generates a URL to start a new chat session. ### Method GET ### Endpoint /api/chat/url ### Parameters #### Query Parameters - **opts** (Options) - Required - Configuration options for the chat session. ### Response #### Success Response (200) - **url** (string) - The generated URL for the chat session. #### Response Example ```json { "url": "https://chat.example.com/session/12345" } ``` ``` -------------------------------- ### LLM.js: Initialize Theme and Show Page Source: https://github.com/themaximalist/llm.js/blob/main/public/docs/classes/Attachment.html This snippet sets the document's theme based on local storage and controls the initial display of the page content. It hides the body and then reveals it after a short delay, either by showing a specific page via `window.app.showPage()` or by removing the display property. ```javascript document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os"; document.body.style.display="none"; setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500) ``` -------------------------------- ### Get Quality Models (TypeScript) Source: https://github.com/themaximalist/llm.js/blob/main/public/docs/classes/Groq.html Fetches a list of models specifically filtered for quality. Returns a promise that resolves to an array of Model objects. ```typescript getQualityModels(): Promise ``` -------------------------------- ### xAI Class Constructor Source: https://github.com/themaximalist/llm.js/blob/main/public/docs/classes/xAI.html Initializes a new instance of the xAI class. It can optionally accept initial options or input for configuring the language model interaction. ```APIDOC ## new xAI ### Description Initializes a new instance of the xAI class. It can optionally accept initial options or input for configuring the language model interaction. ### Method Constructor ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - **input** (Options | Input) - Optional. Initial configuration or input for the language model. - **options** (Options) - Optional. Additional options for configuring the xAI instance. Defaults to an empty object. ### Request Example ```json { "input": { "model": "gpt-4", "max_tokens": 1000 }, "options": { "apiKey": "YOUR_API_KEY" } } ``` ### Response #### Success Response (200) - N/A (Constructor does not return a value in the traditional sense, it creates an instance) #### Response Example ```json // Instance of xAI created ``` ``` -------------------------------- ### Get Models URL API Source: https://github.com/themaximalist/llm.js/blob/main/public/docs/classes/xAI.html Retrieves the URL for accessing model information. This method returns a string representing the models URL. ```APIDOC ## getModelsUrl ### Description Retrieves the URL for accessing model information. This method returns a string representing the models URL. ### Method GET ### Endpoint /getModelsUrl ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json {} ``` ### Response #### Success Response (200) - **modelsUrl** (string) - The URL to access model information. ``` -------------------------------- ### Set Theme and Initial Display Source: https://github.com/themaximalist/llm.js/blob/main/public/docs/types/ServiceName.html Sets the document theme based on local storage and manages the initial display of the application body. It waits for the app to be ready or a timeout to occur before showing the page content. ```javascript document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os"; document.body.style.display="none"; setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500) ``` -------------------------------- ### Get Models API Source: https://github.com/themaximalist/llm.js/blob/main/public/docs/classes/xAI.html Fetches a list of models, optionally filtering by quality. Returns a promise that resolves to an array of Model objects. ```APIDOC ## getModels ### Description Fetches a list of models, optionally filtering by quality. Returns a promise that resolves to an array of Model objects. ### Method GET ### Endpoint /getModels ### Parameters #### Path Parameters None #### Query Parameters - **quality_filter** (QualityFilter) - Optional - A filter to apply to the model list based on quality. #### Request Body None ### Request Example ```json { "quality_filter": { "minQuality": 0.8 } } ``` ### Response #### Success Response (200) - **models** (Model[]) - An array of Model objects matching the quality filter. ``` -------------------------------- ### Get Models with Quality Filter Source: https://github.com/themaximalist/llm.js/blob/main/public/docs/classes/Google.html Fetches a list of models, optionally filtering them by quality. This function is inherited from the base LLM class. ```typescript getModels(quality_filter?: QualityFilter): Promise ``` -------------------------------- ### LLM System Prompts for Specialization Source: https://github.com/themaximalist/llm.js/blob/main/README.md Explains how to use system prompts with LLM.js to specialize the model for specific tasks. This example sets a system prompt to make the LLM a friendly chat bot and then engages in a conversation. ```javascript const llm = new LLM(); llm.system("You are a friendly chat bot."); await llm.chat("what's the color of the sky in hex value?"); // Response: sky blue await llm.chat("what about at night time?"); // Response: darker value (uses previous context) ``` -------------------------------- ### Get Default Model Usage Source: https://github.com/themaximalist/llm.js/blob/main/public/docs/classes/Google.html Retrieves the default usage type for a given model. This function is inherited from the base LLM class. ```typescript getDefaultModelUsage(model: Model): ModelUsageType ``` -------------------------------- ### Setting API Keys in Environment (Node.js) Source: https://github.com/themaximalist/llm.js/blob/main/README.md Illustrates how to set API keys for various LLM services as environment variables in a Node.js environment for automatic detection by LLM.js. ```bash export OPENAI_API_KEY=... export ANTHROPIC_API_KEY=... export GOOGLE_API_KEY=... export GROQ_API_KEY=... export DEEPSEEK_API_KEY=... export XAI_API_KEY=... ``` -------------------------------- ### Get Chat URL Source: https://github.com/themaximalist/llm.js/blob/main/public/docs/classes/Google.html Generates a URL for chat interactions based on provided options. This function overrides the base LLM implementation. ```typescript getChatUrl(opts: Options): string ``` -------------------------------- ### Set Theme and Show Page Source: https://github.com/themaximalist/llm.js/blob/main/public/docs/types/LLMServices.html This JavaScript code snippet initializes the theme based on local storage and then dynamically displays the page content after a short delay, either by calling app.showPage() or removing the display:none property. ```javascript document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os"; document.body.style.display="none"; setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500) ``` -------------------------------- ### Get Quality Models Source: https://github.com/themaximalist/llm.js/blob/main/public/docs/classes/LLM.html Fetches a list of models that have passed a quality assessment. This method returns a Promise resolving to an array of 'Model' objects. ```typescript getQualityModels(): Promise<[Model](../types/Model.html)[]> ``` -------------------------------- ### Get LLM Models URL Source: https://github.com/themaximalist/llm.js/blob/main/public/docs/classes/LLM.html Retrieves the URL endpoint for fetching available models. This accessor returns a string representing the models URL. ```typescript get modelsUrl(): string ``` -------------------------------- ### Switch LLM Models Using LLM.js Source: https://github.com/themaximalist/llm.js/blob/main/public/index.html Demonstrates how to switch between various Large Language Models (LLMs) using the LLM.js library. It shows examples for default local models (Ollama), OpenAI, Anthropic, Google, xAI, DeepSeek, and specific Ollama models. The function call includes the prompt and an optional configuration object specifying the model and service provider. ```javascript await LLM("the color of the sky is"); await LLM("the color of the sky is", { model: "gpt-4o-mini", service: "openai" }); await LLM("the color of the sky is", { model: "claude-3-5-sonnet-latest", service: "anthropic" }); await LLM("the color of the sky is", { model: "gemini-1.5-pro", service: "google" }); await LLM("the color of the sky is", { service: "xai", model: "grok-beta" }); await LLM("solve this puzzle", { service: "deepseek", model: "deepseek-reasoner", think: true }); await LLM("the color of the sky is", { model: "llama3.2:3b", service: "ollama" }); ``` -------------------------------- ### Get Model by Service and Name Source: https://github.com/themaximalist/llm.js/blob/main/public/docs/classes/ModelUsage.html Retrieves a specific model based on its service and name, with an optional quality filter. Returns the model details or null. ```typescript get( service: string, model: string, quality_filter?: QualityFilter, ): null | ModelUsageType[] ``` -------------------------------- ### Setting System Prompts with LLM.js Source: https://github.com/themaximalist/llm.js/blob/main/public/index.html Explains how to use the `llm.system()` method in LLM.js to instruct the model to specialize in specific tasks, enhancing its behavior in subsequent interactions. ```javascript const llm = new LLM(); llm.system("You are a friendly chat bot."); await llm.chat("what's the color of the sky in hex value?"); await llm.chat("what about at night time?"); ``` -------------------------------- ### Get Specific Model Information Source: https://github.com/themaximalist/llm.js/blob/main/public/docs/classes/ModelUsage.html Retrieves information for a specific model, optionally filtering by quality. It returns the model usage details or null if not found. ```typescript getModel(model: string, quality_filter?: QualityFilter): null | ModelUsageType[] ``` -------------------------------- ### Get Models URL Source: https://github.com/themaximalist/llm.js/blob/main/public/docs/classes/DeepSeek.html Retrieves the URL endpoint for fetching model information. This function does not take any parameters and returns a string. Inherited from APIv1. ```typescript getModelsUrl(): string ``` -------------------------------- ### Fetch Latest LLM Models with LLM.js Source: https://github.com/themaximalist/llm.js/blob/main/public/index.html Demonstrates how to instantiate the LLM class and fetch a list of all available models from supported providers. It shows how to log the count of models and inspect the details of the first model in the list. ```javascript const llm = new LLM({ service: "openai" }); const models = await llm.fetchModels(); console.log(models.length); // 50+ models console.log(models[0]); // { name: "gpt-4o", created: Date, service: "openai", ... } ``` -------------------------------- ### Set Theme and Show Page - JavaScript Source: https://github.com/themaximalist/llm.js/blob/main/public/docs/types/Model.html This snippet sets the theme based on local storage and displays the page content after a short delay, potentially showing the app's main page or removing a display:none style. ```javascript document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os"; document.body.style.display="none"; setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500) ``` -------------------------------- ### Get Model Response Source: https://github.com/themaximalist/llm.js/blob/main/public/docs/classes/Anthropic.html Processes generic data to extract a string response from the model. This method is inherited from the LLM class and defined in LLM.ts. ```typescript response(data: any): string[] ``` -------------------------------- ### Get Models URL API Source: https://github.com/themaximalist/llm.js/blob/main/public/docs/classes/Anthropic.html Retrieves the URL endpoint for accessing model information. This method inherits its functionality from the base LLM class. ```APIDOC ## GET /api/models/url ### Description Retrieves the URL where model information can be accessed. ### Method GET ### Endpoint /api/models/url ### Response #### Success Response (200) - **url** (string) - The URL for model information. #### Response Example ```json { "url": "https://api.example.com/v1/models" } ``` ``` -------------------------------- ### Configure Custom Services with LLM.js Source: https://github.com/themaximalist/llm.js/blob/main/README.md Demonstrates how to configure and use custom LLM services by providing a custom service object with specific API details like `baseUrl`, `model`, and `apiKey`. It also shows how to extend the `LLM.APIv1` class for more complex custom service implementations. ```javascript const llm = new LLM({ service: "together", baseUrl: "https://api.together.xyz/v1", model: "meta-llama/Llama-3-70b-chat-hf", apiKey, }); ``` ```javascript class Together extends LLM.APIv1 { static readonly service: ServiceName = "together"; static DEFAULT_BASE_URL: string = "https://api.together.xyz/v1"; static DEFAULT_MODEL: string = "meta-llama/Llama-3-70b-chat-hf"; } const llm = new Together(); ``` ```javascript LLM.register(Together); const llm = new LLM({ service: "together" }); ``` -------------------------------- ### Get Models URL in LLM.ts Source: https://github.com/themaximalist/llm.js/blob/main/public/docs/classes/Anthropic.html Retrieves the base URL for accessing model information. This function returns a string and is inherited from the LLM class. ```typescript getModelsUrl(): string; ``` -------------------------------- ### LLM.js Configuration Options Source: https://github.com/themaximalist/llm.js/blob/main/public/index.html Provides an overview of the comprehensive configuration options available for the LLM.js constructor, including service providers, API keys, model selection, streaming, and more. ```javascript const llm = new LLM(input, { service: "openai", apiKey: "sk-123", model: "gpt-4o", max_tokens: 1000, temperature: 0.7, stream: true, extended: true, messages: [], think: true, parser: LLM.parsers.json, tools: [...], max_thinking_tokens: 500, }); // Key Options: // service: Provider (`openai`, `anthropic`, `google`, `xai`, `groq`, `deepseek`, `ollama`) // apiKey: API key for service, if not specified attempts to read from environment // model: Specific model name (auto-detected from service if not provided) // stream: Enable real-time streaming responses // extended: Return detailed response with usage, costs, and metadata // think: Enable reasoning mode for supported models // temperature: Controls randomness (0 = deterministic, 2 = very creative) ``` -------------------------------- ### Get the URL for models in LLM.js Source: https://github.com/themaximalist/llm.js/blob/main/public/docs/classes/OpenAI.html Retrieves the URL endpoint for fetching models. This function inherits from the base LLM class and returns a string. ```typescript getModelsUrl(): string ```