This repository contains code to connect MATLAB to the OpenAI™ Chat Completions API (which powers ChatGPT™), OpenAI Images API (which powers DALL·E™), Azure® OpenAI Service, and local Ollama® models. This allows you to leverage the natural language processing capabilities of large language models directly within your MATLAB environment.
MathWorks Products (https://www.mathworks.com)
- Requires MATLAB release R2024a or newer.
- Some examples require Text Analytics Toolbox™.
- For OpenAI connections: An active OpenAI API subscription and API key.
- For Azure OpenAI Services: An active Azure subscription with OpenAI access, deployment, and API key.
- For Ollama: A local Ollama installation. Currently, only connections on
localhost
are supported, i.e., Ollama and MATLAB must run on the same machine.
See these pages for instructions specific to the 3rd party product selected:
To use this repository with MATLAB Online, click
To use this repository with a local installation of MATLAB, first clone the repository.
-
In the system command prompt, run:
git clone https://github.com/matlab-deep-learning/llms-with-matlab.git
-
Open MATLAB and navigate to the directory where you cloned the repository.
-
Add the directory to the MATLAB path.
addpath('path/to/llms-with-matlab');
To learn how to use this in your workflows, see Examples.
- ProcessGeneratedTextinRealTimebyUsingChatGPTinStreamingMode.mlx: Learn to implement a simple chat that stream the response.
- SummarizeLargeDocumentsUsingChatGPTandMATLAB.mlx: Learn to create concise summaries of long texts with ChatGPT. (Requires Text Analytics Toolbox™)
- CreateSimpleChatBot.mlx: Build a conversational chatbot capable of handling various dialogue scenarios using ChatGPT. (Requires Text Analytics Toolbox)
- AnalyzeScientificPapersUsingFunctionCalls.mlx: Learn how to create agents capable of executing MATLAB functions.
- AnalyzeTextDataUsingParallelFunctionCallwithChatGPT.mlx: Learn how to take advantage of parallel function calling.
- RetrievalAugmentedGenerationUsingChatGPTandMATLAB.mlx: Learn about retrieval augmented generation with a simple use case. (Requires Text Analytics Toolbox™)
- DescribeImagesUsingChatGPT.mlx: Learn how to use GPT-4 Turbo with Vision to understand the content of an image.
- AnalyzeSentimentinTextUsingChatGPTinJSONMode.mlx: Learn how to use JSON mode in chat completions
- UsingDALLEToEditImages.mlx: Learn how to generate images
- UsingDALLEToGenerateImages.mlx: Create variations of images and editimages.
The license is available in the license.txt file in this GitHub repository.
Copyright 2023-2024 The MathWorks, Inc.