### Default Configuration File Example Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md An example of the default configuration object for chatgpt.js. This can be used in a `.chatgpt.config.mjs` or `.chatgpt.config.js` file. ```javascript export default { // Param options provider: 'auto', // provider for chat API (or 'google' or 'openrouter') uiLang: 'en', // ISO 639-1 code of language to display UI in replyLang: '', // language for AI to reply in maxChars: 250, // char limit per msg maxTokens: null, // max tokens to use turnsToPreserve: 3, // # of turns to preserve (2 msgs/turn) // Flags copy: false, // copy CLI response to clipboard noSuggest: false, // don't auto-suggest next AI action at end of CLI response quietMode: false, // suppress all logging except errors autoClear: true // auto-clear msg chain cache on new terminal sessions } ``` -------------------------------- ### Install chatgpt.js via npm for Node.js Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/README.md Use this command to install the library as a project dependency in your Node.js applications. ```bash npm install @kudoai/chatgpt.js ``` -------------------------------- ### Install chatgpt.js CLI app globally for Node.js Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/README.md Use this command to install the chatgpt.js command-line interface globally, making its commands available system-wide. ```bash npm install -g @kudoai/chatgpt.js ``` -------------------------------- ### Start New Chat Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Initiates a new, empty chat session. This function is only available in the DOM environment. ```javascript chatgpt.startNewChat() ``` -------------------------------- ### get() Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Provides guidance on retrieving responses, directing users to specific methods based on whether the chat is new or previously created. ```APIDOC ## get() ### Description Retrieves a ChatGPT response. If it's a previously created chat, use `chatgpt.response.getFromDOM()`. If it's a new chat, use `chatgpt.response.getFromAPI()`. ### Method `chatgpt.response.get()` ### Endpoint N/A (Universal method) ### Parameters None ### Usage This method acts as a router to other `get` methods based on context. ``` -------------------------------- ### Get Login Button with chatgpt.js Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Returns the login button element. Clicking this button navigates the user to the login page. ```javascript const loginBtn = chatgpt.getLoginButton() loginBtn.click() // navs to login page ``` -------------------------------- ### Import and Use with ES Modules (ESM) Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/README.md Import the chatgpt.js library using ES Module syntax and send a message. Ensure the library is installed via npm. ```javascript import chatgpt from '@kudoai/chatgpt.js' console.log(await chatgpt.send('sup')) // e.g. => Hey! Not much—just here and ready to help. What's up with you? ``` -------------------------------- ### Focus Chatbar with chatgpt.js Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Use this function to bring focus to the chat input bar. This is useful for immediately starting to type a new message. ```javascript chatgpt.focusChatbar() ``` -------------------------------- ### Get Account Details Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Fetches specific account details like email, ID, name, or picture. Can return a single string or an object with multiple details. ```javascript (async () => { const accountName = await chatgpt.getAccountDetails('name') chatgpt.alert(accountName) // Example output: 'chatgpt.js' const accountData = await chatgpt.getAccountDetails('name', 'email') chatgpt.alert(accountData) /* Example output: { name: 'chatgpt.js', email: 'showcase@chatgptjs.org' } */ })() ``` -------------------------------- ### Ask ChatGPT and Get Reply Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Sends a message to ChatGPT and retrieves the response. This function is only available in a DOM environment. ```javascript (async () => { const response = await chatgpt.askAndGetReply('Hello, ChatGPT') chatgpt.alert(response) // Example output: 'Hello user, I'm ChatGPT!' })() ``` -------------------------------- ### Send Query via Terminal Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/README.md Interact with ChatGPT directly from the terminal by sending a query. This requires the chatgpt.js CLI to be installed and potentially an API key to be set. ```bash chatgpt --query "sup" # or gpt -q sup # e.g. => Hey there! What's up? ``` -------------------------------- ### Get Access Token Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Retrieves the user's account access token. This is useful for authenticated API requests. ```javascript (async () => { const token = await chatgpt.getAccessToken() chatgpt.alert(token) // Example output: 'abcdef[...]' })() ``` -------------------------------- ### Get Continue Generating Button with chatgpt.js Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Returns the 'Continue generating' button element. This can be used to programmatically trigger the continuation of a response. ```javascript const continueBtn = chatgpt.getContinueButton() continueBtn.click() ``` -------------------------------- ### Import chatgpt.js Locally in Chrome Extensions Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md For Chrome extensions, you must import the library locally after saving it and declaring it as a web accessible resource in manifest.json. This example shows how to import it within an async IIFE. ```json "web_accessible_resources": [{ "matches": [""], "resources": ["lib/chatgpt.min.js"] }], ``` ```javascript (async () => { await import(chrome.runtime.getURL('lib/chatgpt.min.js')) // Your code here... })() ``` -------------------------------- ### Get All Chat Details Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Retrieve all details for a specified chat. Defaults to the active chat if none is specified. Can also specify 'latest' or a chat identifier. ```javascript await chatgpt.getChatData() // or await chatgpt.getChatData('latest') // can also be 'active', 'title of the chat' or 'id of the chat' // or await chatgpt.getChatData('latest', 'all') ``` -------------------------------- ### Get Voice Mode Button with chatgpt.js Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Retrieves the button that activates Voice mode in the chatbar. Clicking this button enables voice input functionality. ```javascript const voiceBtn = chatgpt.getVoiceButton() getVoiceButton.click() // activates Voice mode ``` -------------------------------- ### Get New Chat Button with chatgpt.js Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Retrieves the sidebar button that initiates a new chat. This element can be manipulated, for example, to hide it. ```javascript const newChatBtn = chatgpt.getNewChatButton() newChatBtn.style.display = 'none' // hide New Chat button ``` -------------------------------- ### Get User's Language with ChatGPT.js Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Retrieve the user's current language setting using `getUserLanguage`. This is helpful for tailoring responses or UI elements to the user's locale. ```javascript const userLanguage = chatgpt.getUserLanguage() chatgpt.alert(userLanguage) // Example output: 'en-US' ``` -------------------------------- ### View CLI Help Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/README.md Display all available command-line interface options and their descriptions. This is useful for discovering the full range of CLI functionalities. ```bash chatgpt --help ``` -------------------------------- ### Initialize Configuration File Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/README.md Initialize a `.chatgpt.config.mjs` file for customizing the chatgpt.js provider and other settings. This command helps in setting up persistent configurations. ```bash chatgpt init # or gpt -i ``` -------------------------------- ### Command Line Options Overview Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Lists all available parameters, message chain options, flags, git commands, data commands, fun commands, and app commands for the chatgpt.js CLI. ```bash Parameter options: -p, --provider Provider for chat API ('auto', 'google', or 'openrouter') -u, --ui-lang ISO 639-1 code of language to display UI in. -L, --reply-lang Language for AI to reply in. -q, --query Query to send AI. -s, --summarize Path or URL to file or text to summarize. -c, --config Path or URL to custom config file to load. Msg chain options: -m, --max-chars Character limit per message. -k, --max-tokens Max tokens to use. -t, --turns Number of turns to preserve. -C, --clear Clear cached message chain. Flags: -x, --copy Copy CLI response to clipboard. -A, --no-suggest Don't auto-suggest next AI action at end of CLI response. -V, --quiet Suppress all logging except errors. git commands / options: -g, --commit-msg Generate git commit message from changes and copy to clipboard. -G, --commit-msg-example Example msg for --commit-msg to reference. -d, --diff Generate human-readable git diff and append to --commit-msg if passed. Data commands: -T, --sentiment Path or URL to file or text to analyze sentiment of. Fun commands: -P, --act-as Act as persona from https://cdn.jsdelivr.net/npm/@kudoai/ai-personas@1/dist/ai-personas.json -a, --ascii-art [subject] Render ASCII art of optional subject. -f, --fortune Tell your fortune. -j, --joke Tell a joke. -r, --random-answer Answer a random question. App commands: -i, --init Create config file (in project root). -I, --interactive Enter interactive REPL mode. -h, --help Display help screen. -v, --version Show version number. -S, --stats Show npm stats. --debug Show debug logs. ``` -------------------------------- ### Get Last ChatGPT Response Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Retrieves the last response generated by ChatGPT. This function is universal. ```javascript (async () => { const response = await chatgpt.getLastResponse() chatgpt.alert(response) // Example output: 'I am ChatGPT!' })() ``` -------------------------------- ### Get Header Element Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Retrieves the header div element. This can be used to modify the header's display properties. ```javascript const headerDiv = chatgpt.header.get() headerDiv.style.display = none // hide the header ``` -------------------------------- ### Turn On Custom Instructions - JavaScript Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Call this method to enable custom instructions. ```javascript (async () => { await chatgpt.instructions.turnOn() })() ``` -------------------------------- ### Get Footer Element Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Retrieves the footer div element. Use this to manipulate the footer's appearance or behavior. ```javascript const footerDiv = chatgpt.footer.get() footerDiv.style.padding = '15px' // make the footer taller ``` -------------------------------- ### Instructions API Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Manage custom instructions for ChatGPT and the user. ```APIDOC ## add() async ### Description Adds a custom instruction for either the user or ChatGPT. ### Parameters - **instruction** (string) - Required - The instruction to be added. - **target** (string) - Required - The target of the instruction. Can be either `user` or `chatgpt`. ### Request Example ```js (async () => { await chatgpt.instructions.add('Detailed and well-explained answers', 'chatgpt') })() ``` ``` ```APIDOC ## clear() async ### Description Clears the custom instructions of either the user or ChatGPT. ### Parameters - **target** (string) - Required - The target of the instruction. Can be either `user` or `chatgpt`. ### Request Example ```js (async () => { await chatgpt.instructions.clear('user') })() ``` ``` ```APIDOC ## turnOff() async ### Description Turns off custom instructions. ### Request Example ```js (async () => { await chatgpt.instructions.turnOff() })() ``` ``` ```APIDOC ## turnOn() async ### Description Turns on custom instructions. ### Request Example ```js (async () => { await chatgpt.instructions.turnOn() })() ``` ``` ```APIDOC ## toggle() async ### Description Toggles custom instructions on/off. ### Request Example ```js (async () => { await chatgpt.instructions.toggle() })() ``` ``` -------------------------------- ### startNewChat() Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Creates a new chat. This function is specific to the DOM environment. ```APIDOC ## startNewChat() ### Description Creates a new chat. ### Method None (synchronous) ### Parameters None ### Response None ### Request Example ```js chatgpt.startNewChat() ``` ``` -------------------------------- ### Get Current Timestamp Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Returns the current timestamp as a string in 12-hour format. Useful for logging or display purposes. ```javascript const timeStamp = chatgpt.autoRefresh.nowTimeStamp() chatgpt.alert(timeStamp) // Example output: '1:56:25 PM' ``` -------------------------------- ### General Methods Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md General utility methods for interacting with the ChatGPT environment. ```APIDOC ## actAs(persona) ### Description Allows the user to act as a specific persona. ### Method `async` ### Endpoint N/A (Library method) ### Parameters - **persona** (string) - The persona to act as. ### Response N/A ``` ```APIDOC ## detectLanguage(text) ### Description Detects the language of the provided text. ### Method `async` ### Endpoint N/A (Library method) ### Parameters - **text** (string) - The text to detect the language of. ### Response N/A ``` ```APIDOC ## dictate() ### Description Initiates voice dictation. ### Method N/A ### Endpoint N/A (DOM only) ### Parameters None ### Response N/A ``` ```APIDOC ## getFortune() ### Description Retrieves a fortune. ### Method `async` ### Endpoint N/A (DOM only) ### Parameters None ### Response N/A ``` ```APIDOC ## getRandomAnswer() ### Description Gets a random answer. ### Method `async` ### Endpoint N/A (Universal) ### Parameters None ### Response N/A ``` ```APIDOC ## getRelated(query) ### Description Retrieves related information for a given query. ### Method `async` ### Endpoint N/A (Universal) ### Parameters - **query** (string) - The query to find related information for. ### Response N/A ``` ```APIDOC ## getUserLanguage() ### Description Gets the user's current language setting. ### Method N/A ### Endpoint N/A (DOM only) ### Parameters None ### Response N/A ``` ```APIDOC ## isLoaded() ### Description Checks if the library is loaded. ### Method `async` ### Endpoint N/A (DOM only) ### Parameters None ### Response N/A ``` ```APIDOC ## isTempChat() ### Description Checks if the current chat is a temporary chat. ### Method N/A ### Endpoint N/A (DOM only) ### Parameters None ### Response N/A ``` ```APIDOC ## printAllFunctions() ### Description Prints all available functions to the console. ### Method N/A ### Endpoint N/A (Universal) ### Parameters None ### Response N/A ``` ```APIDOC ## sentiment(text, entity) ### Description Analyzes the sentiment of the provided text, optionally focusing on a specific entity. ### Method `async` ### Endpoint N/A (DOM only) ### Parameters - **text** (string) - The text to analyze. - **entity** (string, optional) - The entity to focus the sentiment analysis on. ### Response N/A ``` ```APIDOC ## suggest() ### Description Provides a suggestion. ### Method `async` ### Endpoint N/A (DOM only) ### Parameters None ### Response N/A ``` ```APIDOC ## summarize(text) ### Description Summarizes the provided text. ### Method `async` ### Endpoint N/A (DOM only) ### Parameters - **text** (string) - The text to summarize. ### Response N/A ``` ```APIDOC ## translate(text, outputLang) ### Description Translates the provided text to the specified output language. ### Method `async` ### Endpoint N/A (DOM only) ### Parameters - **text** (string) - The text to translate. - **outputLang** (string) - The target language for translation. ### Response N/A ``` ```APIDOC ## uuidv4() ### Description Generates a v4 UUID. ### Method N/A ### Endpoint N/A (Universal) ### Parameters None ### Response N/A ``` -------------------------------- ### Get Last User Prompt Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Retrieves the last message sent by the user. This function is universal and can be used in any environment. ```javascript (async () => { const message = await chatgpt.getLastPrompt() chatgpt.alert(message) // Example output: 'Hello from chatgpt.js!' })() ``` -------------------------------- ### Set Google AI API Key on Windows Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/README.md Configure the GOOGLE_API_KEY environment variable on Windows using the setx command. This is necessary for authenticating with Google AI services. ```bash setx GOOGLE_API_KEY "AIzaSyB..." ``` -------------------------------- ### Basic Command Line Usage Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md The fundamental command to invoke the chatgpt.js CLI. This can be aliased as 'cjs'. ```bash chatgpt # or cjs ``` -------------------------------- ### Get Chat Input Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Retrieves the current value of the chat input field. Useful for capturing user input before sending. ```javascript const chatInput = chatgpt.getChatInput() chatgpt.alert(chatInput) // Example output: 'Hello from chatgpt.js!' ``` -------------------------------- ### Toggle Custom Instructions - JavaScript Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Use this to toggle custom instructions on or off. ```javascript (async () => { await chatgpt.instructions.toggle() })() ``` -------------------------------- ### Response API Methods Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Methods for interacting with chat responses, including continuing, getting, and regenerating responses. Some methods are DOM-only. ```APIDOC ## Response API Methods ### Description Methods for interacting with chat responses. ### Methods - **continue()** (DOM only): Continues the current response generation. - **get()** (Universal): Retrieves a response. - **getFromAPI()** (Universal, Async): Retrieves a response from the API. - **getFromDOM()** (DOM only): Retrieves a response from the DOM. - **getLast()** (Universal, Async): Retrieves the last response. - **regenerate()** (DOM only): Regenerates the current response. - **stopGenerating()** (DOM only): Stops the current response generation. ``` -------------------------------- ### write Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Asks ChatGPT to write code given a prompt. It takes a prompt describing the code and the desired output language. ```APIDOC ## write(prompt, outputLang, { parameters }) ### Description Asks ChatGPT to write code given a prompt. ### Parameters - `prompt` (string) - A string describing the code to generate. - `outputLang` (string) - A string representing the code language to generate the prompt with. - `verbose` (boolean) - Optional. Show console logging (default: `false`). ### Example ```javascript (async () => { const code = await chatgpt.code.write('Repeat a task every 10 seconds', 'javascript') chatgpt.alert(code) /* Alerts: setInterval(function() { // Your task code here }, 10000) */ })() ``` ``` -------------------------------- ### Print All Available Functions Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Call `printAllFunctions` to log a list of all available functions in the ChatGPT.js library to the console. This is useful for exploration and debugging. ```javascript chatgpt.printAllFunctions() ``` -------------------------------- ### printAllFunctions() Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Prints all the library functions to the console. This function is available universally. ```APIDOC ## printAllFunctions() ### Description Prints all the library functions to the console. ### Request Example ```js chatgpt.printAllFunctions() ``` ``` -------------------------------- ### Get Last Error Message Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Retrieves the error message from the last generation attempt. This is useful for debugging or informing the user about failures. ```javascript const chatErrorMsg = chatgpt.getErrorMsg() chatgpt.alert(chatErrorMsg) // Example output: 'Conversation not found' ``` -------------------------------- ### Get a Fortune from ChatGPT.js Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Call `getFortune` to have ChatGPT tell your fortune. This function is suitable for lighthearted interactions or adding an element of surprise. -------------------------------- ### login() Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Navigates the user to the login page. This function is only available in a DOM environment. ```APIDOC ## login() ### Description Navigates to the login page. ### Method N/A (JavaScript function) ### Endpoint N/A (JavaScript function) ### Parameters None ### Request Example ```javascript chatgpt.login() ``` ### Response None ``` -------------------------------- ### suggest() Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Asks ChatGPT to suggest ideas based on a given type and optional details. ```APIDOC ## suggest() ### Description Asks ChatGPT to suggest ideas. ### Method `async` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None #### Function Parameters - **ideaType** (string) - Required - The type of idea to suggest. - **details** (string) - Optional - Details to fine-tune the suggestion. ### Request Example ```javascript (async () => { const suggestions = await chatgpt.suggest('names', 'baby boy') chatgpt.alert(suggestions) })() ``` ### Response #### Success Response Returns a list of suggestions. #### Response Example ``` 1. Liam 2. Noah 3. Ethan ... ``` ``` -------------------------------- ### Get Stop Generation Button with chatgpt.js Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Returns the button that stops the current response generation. This is useful for interrupting long or unwanted outputs. ```javascript const stopBtn = chatgpt.getStopButton() stopBtn.click() ``` -------------------------------- ### Get Send Message Button with chatgpt.js Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Retrieves the button element responsible for sending messages in the chat. This can be used to programmatically send a message. ```javascript const sendBtn = chatgpt.getSendButton() sendBtn.click() ``` -------------------------------- ### Add Custom Instruction - JavaScript Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Use this to add a custom instruction for either the user or ChatGPT. Ensure the target is either 'user' or 'chatgpt'. ```javascript (async () => { await chatgpt.instructions.add('Detailed and well-explained answers', 'chatgpt') })() ``` -------------------------------- ### Get Scroll to Bottom Button with chatgpt.js Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Returns the button that scrolls the chat interface to the bottom. This is useful for quickly viewing the latest messages. ```javascript const scrollToBottomBtn = chatgpt.getScrollToBottomButton() scrollToBottomBtn.click() ``` -------------------------------- ### Get New Chat Link with chatgpt.js Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Returns the sidebar link that creates a new chat. Similar to the button, this link can be programmatically hidden. ```javascript const newChatLink = chatgpt.getNewChatLink() newChatLink.style.display = 'none' // hide New Chat link ``` -------------------------------- ### Set OpenRouter API Key on Windows Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/README.md Configure the OPENROUTER_API_KEY environment variable on Windows using the setx command. This is necessary for authenticating with the OpenRouter API. ```bash setx OPENROUTER_API_KEY "sk-or-v1-8a69..." ``` -------------------------------- ### review(code, { parameters }) Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Asks ChatGPT to review the provided code. It accepts the code string and an optional verbose parameter. ```APIDOC ## review(code, { parameters }) ### Description Asks ChatGPT to review given code. ### Parameters - `code` (string) - Required - The code to review. - `verbose` (boolean) - Optional - Show console logging (default: `false`). ### Request Example ```javascript (async () => { chatgpt.alert(await chatgpt.code.review('btoa("Hello World")')) /* Example output: The code appears to be correct. It uses the `btoa` function to encode the string "Hello World" in base64. */ })() ``` ``` -------------------------------- ### Get Response from DOM Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Retrieves a specific response generated by ChatGPT directly from the DOM. It accepts positional arguments as strings or integers. This is a DOM-only operation. ```javascript var fifthResp fifthResp = chatgpt.response.getFromDOM(5) // Returns the 5th response fifthResp = chatgpt.response.getFromDOM('fifth') // Also returns the 5th response fifthResp = chatgpt.response.getFromDOM('five') // Returns the 5th response too chatgpt.alert(fifthResp) // Example output: 'Hello from ChatGPT!' ``` -------------------------------- ### execute(code, { parameters }) Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Asks ChatGPT to execute the given code. It accepts the code string and an optional verbose parameter. ```APIDOC ## execute(code, { parameters }) ### Description Asks ChatGPT to execute the given code. ### Parameters - `code` (string) - Required - The code to execute. - `verbose` (boolean) - Optional - Show console logging (default: `false`). ### Request Example ```javascript (async () => { chatgpt.alert(await chatgpt.code.execute('return 6 + 5')) // logs '11' })() ``` ``` -------------------------------- ### Settings API Methods Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Methods for managing library settings, specifically the scheme. ```APIDOC ## Settings API Methods ### Description Methods for managing library settings. ### Methods - **scheme**: API subset for scheme settings, including activating dark/light modes. ``` -------------------------------- ### Write Code with ChatGPT.js Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Use this function to ask ChatGPT to write code based on a prompt and specified output language. It takes a prompt string and an output language string. ```javascript (async () => { const code = await chatgpt.code.write('Repeat a task every 10 seconds', 'javascript') chatgpt.alert(code) /* Alerts: setInterval(function() { // Your task code here }, 10000) */ })() ``` -------------------------------- ### Get Regenerate Response Button with chatgpt.js Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Retrieves the button used to regenerate ChatGPT's response. This allows for programmatic re-generation of the last output. ```javascript const regenBtn = chatgpt.getRegenerateButton() regenBtn.click() ``` -------------------------------- ### Get Chat Input Element with chatgpt.js Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Retrieves the HTML element representing the chat input box. This allows for direct manipulation or reading of its content. ```javascript const chatbox = chatgpt.getChatBox() chatgpt.alert(chatbox.value) // Example output: 'Hello from chatgpt.js!' ``` -------------------------------- ### Set Theme - ChatGPT.js Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Sets the website theme to 'light', 'dark', or 'system'. Requires a string parameter for the desired theme. This function is for DOM manipulation only. ```javascript chatgpt.settings.scheme.set('dark') ``` -------------------------------- ### askAndGetReply() Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Sends a message to ChatGPT and returns the response. This function is only available in a DOM environment. ```APIDOC ## askAndGetReply(message) ### Description Sends a given message to ChatGPT and returns the response as a string. ### Method `async` ### Endpoint N/A (JavaScript function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None #### Parameters - **message** (string) - Required - The message to send to ChatGPT. ### Request Example ```javascript (async () => { const response = await chatgpt.askAndGetReply('Hello, ChatGPT') chatgpt.alert(response) })() ``` ### Response #### Success Response - **reply** (string) - The response from ChatGPT. ``` -------------------------------- ### scheme.set() Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Sets the website theme to 'light', 'dark', or 'system'. This function is only available in a DOM environment. ```APIDOC ## scheme.set() ### Description Sets the theme to `light`, `dark` or `system`. ### Method JavaScript ### Endpoint chatgpt.settings.scheme.set(value) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **value** (string) - Required - A string being the value to set the theme to. Accepted values are 'light', 'dark', or 'system'. ### Request Example ```javascript chatgpt.settings.scheme.set('dark') ``` ### Response None ### Success Response None ``` -------------------------------- ### Get Response from API Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Retrieves a specific response from a specific chat generated by the ChatGPT API. Defaults to the latest response in the latest chat. This is a universal operation. ```javascript (async () => { const response = chatgpt.response.getFromAPI() chatgpt.alert(response) // Example output: 'Hello from ChatGPT!' })() ``` -------------------------------- ### Execute Code with ChatGPT Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Asks ChatGPT to execute a given piece of code. The code to be executed must be provided as a string. ```javascript (async () => { chatgpt.alert(await chatgpt.code.execute('return 6 + 5')) // logs '11' })() ``` -------------------------------- ### Get Dictate Input Button with chatgpt.js Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Retrieves the button element used for voice dictation input. Clicking this button activates the voice input feature. ```javascript const dictateBtn = chatgpt.getDictateButton() dictateBtn.click() ``` -------------------------------- ### scheme.activateLight() Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Changes the website theme to light mode. This function is only available in a DOM environment. ```APIDOC ## scheme.activateLight() ### Description Changes the website theme to light mode. ### Method JavaScript ### Endpoint chatgpt.scheme.activateLight() ### Parameters None ### Request Example ```javascript chatgpt.scheme.activateLight() ``` ### Response None ### Success Response None ``` -------------------------------- ### Set Google AI API Key on Mac/Linux Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/README.md Configure the GOOGLE_API_KEY environment variable on Mac or Linux using the export command. This is necessary for authenticating with Google AI services. ```bash export GOOGLE_API_KEY="AIzaSyB..." ``` -------------------------------- ### Clear Custom Instructions - JavaScript Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Use this to clear custom instructions for either the user or ChatGPT. Specify the target as 'user' or 'chatgpt'. ```javascript (async () => { await chatgpt.instructions.clear('user') })() ``` -------------------------------- ### Get All Messages (Both Participants) Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Retrieve all messages from both the user and ChatGPT for a specified chat. Defaults to the active chat if none is specified. Can also specify 'latest' or a chat identifier. ```javascript await chatgpt.getChatData('latest', 'msg') // or await chatgpt.getChatData('latest', 'msg', 'all') // all/both // or await chatgpt.getChatData('latest', 'msg', 'all', 'all') ``` -------------------------------- ### Show Header Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Shows the header div if it is currently hidden. Use this to make the header visible again. ```javascript chatgpt.header.show() ``` -------------------------------- ### Configure manifest.json for Chrome Extension Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/README.md Add the chatgpt.js library to the web_accessible_resources in your Chrome extension's manifest.json file. This makes the library file accessible to your extension's scripts. ```json "web_accessible_resources": [{ "matches": [""], "resources": ["lib/chatgpt.min.js"] }], ``` -------------------------------- ### Get Related Queries with ChatGPT.js Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md The `getRelated` function returns an array of queries related to a given input query. Use the `qty` parameter to control the number of results and `verbose` for logging. ```javascript console.log(await chatgpt.getRelated('Who is obama?', { verbose: true })) /* e.g. => getRelated() > Getting related queries... getRelated() > Arrayifying related queries... [ 'What is Barack Obama’s current occupation?', 'How many terms did Barack Obama serve as U.S. President?', 'What political party does Barack Obama belong to?', 'What are some of Barack Obama’s major policy achievements?', 'Where was Barack Obama born?' ] */ ``` -------------------------------- ### Load and Use in Chrome Extensions Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/README.md Load the chatgpt.js library within a Chrome extension context using `chrome.runtime.getURL` and confirm it's ready. This method is specific to browser extension environments. ```javascript (async () => { await import(chrome.runtime.getURL('lib/chatgpt.min.js')) await chatgpt.isLoaded() console.log('ChatGPT is ready!') })() ``` -------------------------------- ### Get All Messages (Specific Participant) Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Retrieve all messages from a specific participant (user or chatgpt) for a specified chat. Defaults to the active chat if none is specified. Can also specify 'latest' or a chat identifier. ```javascript await chatgpt.getChatData('latest', 'msg') // or await chatgpt.getChatData('latest', 'msg', 'chatgpt') // user/chatgpt // or await chatgpt.getChatData('latest', 'msg', 'chatgpt', 'all') ``` -------------------------------- ### continue() Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Continues the generation of ChatGPT's response if it was cut off. ```APIDOC ## continue() ### Description Continues the generation of ChatGPT's cut-off response. ### Method `chatgpt.response.continue()` ### Endpoint N/A (DOM only method) ### Parameters None ### Request Example ```js chatgpt.response.continue() ``` ### Response None ``` -------------------------------- ### Get Specific Chat Details Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Retrieve specific details (e.g., 'id', 'title') from a specified chat. Defaults to the active chat if none is specified. Can also specify 'latest' or a chat identifier. ```javascript await chatgpt.getChatData('latest', ['id', 'title']) ``` -------------------------------- ### Set OpenRouter API Key on Mac/Linux Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/README.md Configure the OPENROUTER_API_KEY environment variable on Mac or Linux using the export command. This is necessary for authenticating with the OpenRouter API. ```bash export OPENROUTER_API_KEY="sk-or-v1-8a69..." ``` -------------------------------- ### Get Latest Message (Both Participants) Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Retrieve the latest message from both participants for a specified chat. Defaults to the active chat if none is specified. Can also specify 'latest' or a chat identifier. The message index can also be specified. ```javascript await chatgpt.getChatData('latest', 'msg', 'all', 2) // can also be 'latest' message ``` -------------------------------- ### summarize() Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Asks ChatGPT to summarize the provided text. ```APIDOC ## summarize(text, { parameters }) ### Description Asks ChatGPT to summarize given text. ### Method `async` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None #### Function Parameters - **text** (string) - Required - The text to be summarized. - **verbose** (boolean) - Optional - Show console logging (default: `false`). ### Request Example ```javascript (async () => { const summary = await chatgpt.summarize('A very long text...') chatgpt.alert(summary) })() ``` ### Response #### Success Response Returns the summarized text. #### Response Example ``` A very short text... ``` ``` -------------------------------- ### Get Latest Message (Specific Participant) Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Retrieve the latest message from a specific participant (user or chatgpt) for a specified chat. Defaults to the active chat if none is specified. Can also specify 'latest' or a chat identifier. The message index can also be specified. ```javascript await chatgpt.getChatData('latest', 'msg', 'chatgpt', 2) ``` -------------------------------- ### Navigate to Login Page Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Redirects the user to the ChatGPT login page. This function is only available in a DOM environment. ```javascript chatgpt.login() ``` -------------------------------- ### Generate ASCII Art via Terminal Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/README.md Use the chatgpt.js CLI to generate ASCII art from a given prompt. This command is useful for creative or decorative output. ```bash chatgpt --ascii-art "cat" # or gpt -a cat # e.g. => # # |\ _,,,---,, # ZZZzz /,`.-'`' -. ;-;;,_ # |,4- ) )-,_. , # '---''(_/--' `-'\_) ``` -------------------------------- ### Suggest Ideas with ChatGPT Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Use this function to ask ChatGPT for suggestions on a given topic. Provide the type of idea and optional details to refine the results. This function is DOM-only. ```javascript (async () => { const suggestions = await chatgpt.suggest('names', 'baby boy') chatgpt.alert(suggestions) /* Example output: 1. Liam 2. Noah 3. Ethan 4. Oliver 5. Jackson 6. Aiden 7. Lucas 8. Benjamin 9. Henry 10. Leo 11. Samuel 12. Caleb 13. Owen 14. Daniel 15. Elijah 16. Matthew 17. Alexander 18. James 19. Nathan 20. Gabriel */ })() ``` -------------------------------- ### minify(code, { parameters }) Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Asks ChatGPT to minify the given code. It accepts the code string and an optional verbose parameter. ```APIDOC ## minify(code, { parameters }) ### Description Asks ChatGPT to minify the given code. ### Parameters - `code` (string) - Required - The code to be minified. - `verbose` (boolean) - Optional - Show console logging (default: `false`). ### Request Example ```javascript (async () => { const minifiedCode = await chatgpt.code.minify(` function autosizeBox() { const newLength = replyBox.value.length if (newLength < prevLength) { // if deleting txt replyBox.style.height = 'auto' // ...auto-fit height if (parseInt(getComputedStyle(replyBox).height) < 55) { // if down to one line replyBox.style.height = '2.15rem' } // ...reset to original height } replyBox.style.height = replyBox.scrollHeight + 'px' prevLength = newLength }`) chatgpt.alert(minifiedCode) /* Alerts: 'function autosizeBox(){const n=replyBox.value.length;if(n { await chatgpt.isLoaded() chatgpt.alert('ChatGPT has finished loading.') })() ``` ``` -------------------------------- ### sidebar.show() Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Shows the sidebar. This function is only available in a DOM environment. ```APIDOC ## sidebar.show() ### Description Shows the sidebar. ### Method JavaScript ### Endpoint chatgpt.sidebar.show() ### Parameters None ### Request Example ```javascript chatgpt.sidebar.show() ``` ### Response None ### Success Response None ``` -------------------------------- ### sidebar.isLoaded() Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Resolves a promise when the ChatGPT sidebar has finished loading. This function is only available in a DOM environment. ```APIDOC ## sidebar.isLoaded() ### Description Resolves a promise when the ChatGPT sidebar has finished loading. ### Method JavaScript ### Endpoint chatgpt.sidebar.isLoaded(timeout) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **timeout** (integer) - Optional - An integer specifying the number of milliseconds to wait before resolving with `false`. If not provided, waits 5s or until New Chat link appears (since it is not always present). ### Request Example ```javascript (async () => { await chatgpt.sidebar.isLoaded() chatgpt.alert('ChatGPT sidebar has finished loading.') })() ``` ### Response Promise ### Success Response (200) - **isLoaded** (boolean) - `true` if the sidebar has finished loading within the timeout, `false` otherwise. ``` -------------------------------- ### browser.isFullScreen() Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Checks if the browser is currently in fullscreen mode. ```APIDOC ## isFullScreen() ### Description Returns a boolean value. `true` if the browser is fullscreen and `false` otherwise. ### Example ```js if (chatgpt.browser.isFullScreen()) { // Do something } ``` ``` -------------------------------- ### dictate() Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Opens dictation mode on ChatGPT. This function is only available in the DOM. ```APIDOC ## dictate() ### Description Opens dictation mode on ChatGPT. ### Request Example ```js chatgpt.dictate() ``` ``` -------------------------------- ### Review Code with ChatGPT Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Submits code to ChatGPT for review. The code to be reviewed must be provided as a string argument. ```javascript (async () => { chatgpt.alert(await chatgpt.code.review('btoa("Hello World")')) /* Example output: The code appears to be correct. It uses the `btoa` function to encode the string "Hello World" in base64. */ })() ``` -------------------------------- ### Wait for Sidebar Load - ChatGPT.js Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Asynchronously waits for the ChatGPT sidebar to finish loading. Optionally accepts a timeout in milliseconds. Resolves with `true` on successful load or `false` if timeout is reached. ```javascript (async () => { await chatgpt.sidebar.isLoaded() chatgpt.alert('ChatGPT sidebar has finished loading.') })() ``` -------------------------------- ### Import and Use with CommonJS (CJS) Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/README.md Import the chatgpt.js library using CommonJS syntax within an async IIFE and send a message. This is suitable for Node.js environments that do not support ES Modules directly. ```javascript (async () => { const chatgpt = require('@kudoai/chatgpt.js') console.log(await chatgpt.send('sup')) // e.g. => Hey! What's up? })() ``` -------------------------------- ### Activate Light Mode - ChatGPT.js Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Changes the website theme to light mode. This function is for DOM manipulation only. ```javascript chatgpt.scheme.activateLight() ``` -------------------------------- ### chatgpt.header.show() Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Shows the header div if it has been hidden. This makes the header visible again. ```APIDOC ## chatgpt.header.show() ### Description Shows the header div if hidden. ### Method JavaScript ### Endpoint N/A (JavaScript method) ### Parameters None ### Request Example ```javascript chatgpt.header.show() ``` ### Response None ``` -------------------------------- ### browser.isLightMode() Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Checks if the system or browser is set to light mode. ```APIDOC ## isLightMode() ### Description Returns a boolean value. `true` if system/browser scheme preference is set to light, `false` otherwise. ### Example ```js chatgpt.alert(chatgpt.browser.isLightMode()) // logs `true` or `false` ``` ``` -------------------------------- ### getAccountDetails() Source: https://github.com/kudoai/chatgpt.js/blob/main/docs/USERGUIDE.md Returns account details. Can fetch specific details like email, ID, name, or picture, or all details if none are specified. Available universally. ```APIDOC ## getAccountDetails(detail, ...) ### Description Returns a given account detail as a string or an object containing multiple details. ### Method `async` ### Endpoint N/A (JavaScript function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None #### Parameters - **detail** (string) - Required - A string representing the account detail(s) to be returned. Can be 'email', 'id', 'name', 'picture'. Multiple details can be passed as separate arguments. If no details are passed, an object with all available details is returned. ### Request Example ```javascript // Get a single detail const accountName = await chatgpt.getAccountDetails('name') chatgpt.alert(accountName) // Get multiple details const accountData = await chatgpt.getAccountDetails('name', 'email') chatgpt.alert(accountData) ``` ### Response #### Success Response - **detail** (string) - If a single detail is requested. - **details** (object) - If multiple details are requested, an object with the requested details. ```