Large Language Models (LLMs) with MATLAB lets you connect to large language model APIs using MATLAB®.
You can connect to:
- OpenAI® Chat Completions API — For example, connect to ChatGPT™.
- OpenAI Images API — For example, connect to DALL·E™.
- Azure® OpenAI Service — Connect to OpenAI models from Azure.
- Ollama™ — Connect to models locally or nonlocally.
Using this add-on, you can:
- Generate responses to natural language prompts.
- Manage chat history.
- Generate JSON-formatted and structured output.
- Use tool calling.
- Generate, edit, and describe images.
For more information about the features in this add-on, see the documentation in the doc directory.
Using this add-on requires MATLAB R2024a or newer.
You can use the add-on in MATLAB Online™ by clicking this link:
In MATLAB Online, you can connect to OpenAI and Azure. To connect to Ollama, use an installed version of MATLAB and install the add-on using the Add-On Explorer or by cloning the GitHub™ repository.
The recommended way of using the add-on on an installed version of MATLAB is to use the Add-On Explorer.
- In MATLAB, go to the Home tab, and in the Environment section, click the Add-Ons icon.
- In the Add-On Explorer, search for "Large Language Models (LLMs) with MATLAB".
- Select Install.
For more information about how to connect to the different APIs from MATLAB, including installation requirements, see:
- Process Generated Text in Real Time by Using ChatGPT in Streaming Mode
- Process Generated Text in Real Time by Using Ollama in Streaming Mode
- Summarize Large Documents Using ChatGPT and MATLAB (requires Text Analytics Toolbox™)
- Create Simple ChatBot (requires Text Analytics Toolbox)
- Create Simple Ollama ChatBot (requires Text Analytics Toolbox)
- Solve Simple Math Problem Using AI Agent
- Fit Polynomial to Data Using AI Agent (requires Curve Fitting Toolbox™)
- Analyze Scientific Papers Using ChatGPT Function Calls
- Analyze Text Data Using Parallel Function Calls with ChatGPT
- Analyze Text Data Using Parallel Function Calls with Ollama
- Retrieval-Augmented Generation Using ChatGPT and MATLAB (requires Text Analytics Toolbox)
- Retrieval-Augmented Generation Using Ollama and MATLAB (requires Text Analytics Toolbox)
| Function | Description |
|---|---|
| openAIChat | Connect to OpenAI Chat Completion API from MATLAB |
| azureChat | Connect to Azure OpenAI Services Chat Completion API from MATLAB |
| ollamaChat | Connect to Ollama Server from MATLAB |
| generate | Generate output from large language models |
| openAIFunction | Use Function Calls from MATLAB |
| addParameter | Add input argument to openAIFunction object |
| openAIImages | Connect to OpenAI Image Generation API from MATLAB |
| openAIImages.generate | Generate image using OpenAI image generation API |
| edit | Edit images using DALL·E 2 |
| createVariation | Generate image variations using DALL·E 2 |
| messageHistory | Manage and store messages in a conversation |
| addSystemMessage | Add system message to message history |
| addUserMessage | Add user message to message history |
| addUserMessageWithImages | Add user message with images to message history |
| addToolMessage | Add tool message to message history |
| addResponseMessage | Add response message to message history |
| removeMessage | Remove message from message history |
The license is available in the license.txt file in this GitHub repository.
Copyright 2023-2025 The MathWorks, Inc.