Skip to content

toshiakit/MatGPT

Repository files navigation

MatGPT - MATLAB® app to access ChatGPT API from OpenAI™

View MatGPT on File Exchange Open in MATLAB Online

MatGPT Logo

MatGPT is a MATLAB app that allows you to easily access OpenAI's ChatGPT API. With the app, you can load a list of prompts for specific use cases and engage in conversations with ease. If you're new to ChatGPT and prompt engineering, MatGPT is a great way to learn.

The app simply serves as an interface to the ChatGPT API. You should be familiar with the limitations and risks associated with using this technology as well as withOpenAI terms and policies.You are responsible for any fees OpenAI may charge for the use of their API.

MatGPT requires 'Large Language Models (LLMs) with MATLAB' library maintained by MathWorks.

MATLAB AI Chat Playgroundis a great alternative to MatGPT on MATLAB Central.

What's New

  • MatGPT supports GPT-4o mini as the default model, which delivers higher performance at a lower cost than GPT-3.5 Turbo.
  • MatGPT loads 'LLMs with MATLAB' library as a submodule.
  • MatGPT stores your API in MATLAB Vault on R2024a or later. The stored API will persist from session to session. (Not supported on MATLAB Online).
  • MatGPT supports streaming API where response tokens are displayed as they come in.
  • MatGPT detects a URL included in a prompt, and retrieves its web content into the chat.
  • MatGPT lets you import a.m,.mlx,.csv or.txt file into the chat. PDF files are also supported if Text Analytics Toolbox is available.
  • MatGPT supports GPT-4 Turbo with Vision. You can pass the URL to an image, or a local image file path ask questions about the image.
  • MatGPT lets you generate an image via DALL·E 3 API.
  • MatGPT supports voice chat via Whisper API.

Please note that:

  • If you have a previous version of MatGPT, you may need to reinstall it in order to get the updated submodule required for GPT-4o mini support.
  • imported content will be truncated if it exceeds the context window limit.
  • Streaming must be disabled to use image generation via DALL·E 3.

Requirements

Installation

MATLAB Online

To use MatGPT on MATLAB Online, simply clickOpen in MATLAB OnlineMATLAB Online pulls the content of this repo, including "LLMS with MATLAB" submodule.

Please note that "Open in MATLAB Online" button on the File Exchange doesn't pull the submodule. You will need to pull LLMs with MATLAB separately and add it to the 'LLMs with MATLAB' folder in the helpers folder.

MATLAB Desktop

Use Git commands to clone the repo to your local directory, and then clone the submodules. This will ensure you get the 'LLMs with MATLAB' library.

git clone https://github /toshiakit/MatGPT.git
git submodule update --init

If you download MatGPT as a Zip file, the zip file will not contain the submodule. You need to download 'LLMs with MATLAB' separately and unzip into the 'LLMs with MATLAB' folder in the helpers folder.

How to use: MatGPT app

MatGPT Chat Tab

  1. Click on+ New Chatin the left nav to add a new chat. This opens theSettingstab.
  2. In theSettingstab, either choose a preset to populate the settings or customize on your own. Once you have completed the settings, clickStart New Chatto initiate a chat. This will take you back to theMaintab.
  • Presets are loaded fromPresets.csv- feel free to customize your prompts.
  1. In theMaintab, a sample prompt is already provided based on the preset you selected, but feel free to replace it with your own. When you clickSendbutton, the response will be shown in the 'Chat' tab.
  • The paperclip button lets you include the content of a m-file, live script file or csv file in the chat.
  • If the prompt contains a URL, MatGPT ask you to confirm that you want to open the page.
  • TheSendbutton and Paperclip button are disabled until a chat is configured in theSettingstab.
  • If you want suggestion for follow-up questions in the response, checkSuggest follow-up questionscheckbox. Suggested questions appear as clickable buttons. You can copy a suggested question to the prompt box by clicking it.
  • If your prompt is intended to generate MATLAB code, checkTest Generated MATLAB Codecheckbox to test the returned code.
  • TheUsagetab shows the number of tokens used in the current chat session.
  • Add stop sequences inAdvancedtab to specify the sequences where the API will stop generating further tokens.
  1. Continue the conversation by keep adding more prompts and clickingSend.
  2. You can right-click or double-click a chat in the left navigation panel to rename, delete, or save the chat to a text file.
  3. When you close the app, the chat will be saved and will be reloaded into the left nav when you relaunch the app.

Note:

  • You can increase the connection timeout in theSettings.You can add proxy viaWeb Preferencesin MATLAB.
  • Streaming is enabled by default, but you can turn it off in theSettingstab. Usage data is not available in streaming mode.

What happened to chatGPT class?

chatGPT class was replaced by the framework provided via the 'Large Language Models (LLMs) with MATLAB' repo. The new framework supports function calling and other latest features. Please refer to the documentation in the repo to learn how to use it.

Acknowledgements

This code is adapted fromthis MATLAB Answers commentbyHans Scharlerand usesBrian Buechel'sCodeCheckerand other great contributions. The video shown above was created byAngel Gonzalez Llacer.

License

The license for MatGPT is available in theLICENSE.txtfile in this GitHub repository.