Skip to content

Connect MATLAB to LLM APIs, including OpenAI® Chat Completions, Azure® OpenAI Services, and Ollama™

License

Notifications You must be signed in to change notification settings

matlab-deep-learning/llms-with-matlab

Repository files navigation

Large Language Models (LLMs) with MATLAB

Open in MATLAB Online View Large Language Models (LLMs) with MATLAB on File Exchange

Large Language Models (LLMs) with MATLAB lets you connect to large language model APIs using MATLAB®.

You can connect to:

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.

Installation

Using this add-on requires MATLAB R2024a or newer.

Use MATLAB Online

You can use the add-on in MATLAB Online™ by clicking this link: Open in MATLAB Online

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.

Install using Add-On Explorer

The recommended way of using the add-on on an installed version of MATLAB is to use the Add-On Explorer.

  1. In MATLAB, go to the Home tab, and in the Environment section, click the Add-Ons icon.
  2. In the Add-On Explorer, search for "Large Language Models (LLMs) with MATLAB".
  3. Select Install.

Install by Cloning GitHub Repository

Alternatively, to use the add-on on an installed version of MATLAB, you can clone the GitHub repository. In the MATLAB Command Window, run this command:

>> !git clone https://github.com/matlab-deep-learning/llms-with-matlab.git

To run code from the add-on outside of the installation directory, if you install the add-on by cloning the GitHub repository, then you must add the path to the installation directory.

>> addpath("path/to/llms-with-matlab")

Get Started with External APIs

For more information about how to connect to the different APIs from MATLAB, including installation requirements, see:

Examples

Functions

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

License

The license is available in the license.txt file in this GitHub repository.

Community Support

MATLAB Central

Copyright 2023-2025 The MathWorks, Inc.