You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[](https://matlab.mathworks.com/open/github/v1?repo=matlab-deep-learning/llms-with-matlab)[](https://www.mathworks.com/matlabcentral/fileexchange/163796-large-language-models-llms-with-matlab)
4
5
5
-
This repository contains code to connect MATLAB® to the [OpenAI® Chat Completions API](https://platform.openai.com/docs/guides/text-generation/chat-completions-api) (which powers ChatGPT™), OpenAI Images API (which powers DALL·E™), [Azure® OpenAI Service](https://learn.microsoft.com/en-us/azure/ai-services/openai/), and both local and nonlocal [Ollama™](https://ollama.com/) models. This allows you to leverage the natural language processing capabilities of large language models directly within your MATLAB environment.
6
+
Large Language Models (LLMs) with MATLAB lets you connect to large language model APIs using MATLAB®.
7
+
8
+
9
+
You can connect to:
6
10
7
-
## Requirements
11
+
-[OpenAI® Chat Completions API](https://platform.openai.com/docs/guides/text-generation/chat-completions-api) — For example, connect to ChatGPT™.
12
+
-[OpenAI Images API](https://platform.openai.com/docs/guides/images) — For example, connect to DALL·E™.
13
+
-[Azure® OpenAI Service](https://learn.microsoft.com/en-us/azure/ai-services/openai/) — Connect to OpenAI models from Azure.
14
+
-[Ollama™](https://ollama.com/) — Connect to models locally or nonlocally.
For more information about the features in this add-on, see the documentation in the [`doc`](/doc) directory.
15
25
16
-
- For OpenAI connections: An active OpenAI API subscription and API key.
17
-
- For Azure OpenAI Services: An active Azure subscription with OpenAI access, deployment, and API key.
18
-
- For Ollama: An Ollama installation.
26
+
# Installation
19
27
20
-
## Setup
28
+
Using this add-on requires MATLAB R2024a or newer.
21
29
22
-
See these pages for instructions specific to the 3rd party product selected:
30
+
## Use MATLAB Online
23
31
24
-
*[OpenAI](doc/OpenAI.md)
25
-
*[Azure](doc/Azure.md)
26
-
*[Ollama](doc/Ollama.md)
32
+
You can use the add-on in MATLAB Online™ by clicking this link: [](https://matlab.mathworks.com/open/github/v1?repo=matlab-deep-learning/llms-with-matlab)
27
33
34
+
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.
28
35
29
-
### MATLAB Online
36
+
##Install using Add\-On Explorer
30
37
31
-
To use this repository with MATLAB Online, click [](https://matlab.mathworks.com/open/github/v1?repo=matlab-deep-learning/llms-with-matlab)
38
+
The recommended way of using the add-on on an installed version of MATLAB is to use the Add\-On Explorer.
32
39
40
+
1. In MATLAB, go to the **Home** tab, and in the **Environment** section, click the **Add\-Ons** icon.
41
+
2. In the Add\-On Explorer, search for "Large Language Models (LLMs) with MATLAB".
42
+
3. Select **Install**.
43
+
## Install by Cloning GitHub Repository
33
44
34
-
### MATLAB Desktop
45
+
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:
35
46
36
-
To use this repository with a local installation of MATLAB, first clone the repository.
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.
-[Analyze Scientific Papers Using ChatGPT Function Calls](/examples/AnalyzeScientificPapersUsingFunctionCalls.md)
71
+
-[Analyze Sentiment in Text Using ChatGPT and Structured Output](/examples/AnalyzeSentimentinTextUsingChatGPTwithStructuredOutput.md)
72
+
-[Analyze Text Data Using Parallel Function Calls with ChatGPT](/examples/AnalyzeTextDataUsingParallelFunctionCallwithChatGPT.md)
73
+
-[Analyze Text Data Using Parallel Function Calls with Ollama](/examples/AnalyzeTextDataUsingParallelFunctionCallwithOllama.md)
74
+
-[Retrieval-Augmented Generation Using ChatGPT and MATLAB](/examples/RetrievalAugmentedGenerationUsingChatGPTandMATLAB.md) (requires Text Analytics Toolbox)
75
+
-[Retrieval-Augmented Generation Using Ollama and MATLAB](/examples/RetrievalAugmentedGenerationUsingOllamaAndMATLAB.md) (requires Text Analytics Toolbox)
76
+
-[Describe Images Using ChatGPT](/examples/DescribeImagesUsingChatGPT.md)
77
+
-[Using DALL·E To Edit Images](/examples/UsingDALLEToEditImages.md)
78
+
-[Using DALL·E To Generate Images](/examples/UsingDALLEToGenerateImages.md)
54
79
55
-
- [ProcessGeneratedTextinRealTimebyUsingChatGPTinStreamingMode.md](/examples/ProcessGeneratedTextinRealTimebyUsingChatGPTinStreamingMode.md): Learn to implement a simple chat that stream the response.
56
-
- [SummarizeLargeDocumentsUsingChatGPTandMATLAB.md](/examples/SummarizeLargeDocumentsUsingChatGPTandMATLAB.md): Learn to create concise summaries of long texts with ChatGPT. (Requires Text Analytics Toolbox™)
57
-
- [CreateSimpleChatBot.md](/examples/CreateSimpleChatBot.md): Build a conversational chatbot capable of handling various dialogue scenarios using ChatGPT. (Requires Text Analytics Toolbox)
58
-
- [AnalyzeScientificPapersUsingFunctionCalls.md](/examples/AnalyzeScientificPapersUsingFunctionCalls.md): Learn how to create agents capable of executing MATLAB functions.
59
-
- [AnalyzeTextDataUsingParallelFunctionCallwithChatGPT.md](/examples/AnalyzeTextDataUsingParallelFunctionCallwithChatGPT.md): Learn how to take advantage of parallel functioncalling.
60
-
- [RetrievalAugmentedGenerationUsingChatGPTandMATLAB.md](/examples/RetrievalAugmentedGenerationUsingChatGPTandMATLAB.md): Learn about retrieval augmented generation with a simple use case. (Requires Text Analytics Toolbox™)
61
-
- [DescribeImagesUsingChatGPT.md](/examples/DescribeImagesUsingChatGPT.md): Learn how to use GPT-4 Turbo with Vision to understand the content of an image.
62
-
- [AnalyzeSentimentinTextUsingChatGPTinJSONMode.md](/examples/AnalyzeSentimentinTextUsingChatGPTinJSONMode.md): Learn how to use JSON mode in chat completions
63
-
- [UsingDALLEToEditImages.md](/examples/UsingDALLEToEditImages.md): Learn how to generate images
64
-
- [UsingDALLEToGenerateImages.md](/examples/UsingDALLEToGenerateImages.md): Create variations of images and editimages.
80
+
# Functions
81
+
|**Function**|**Description**|
82
+
| :-- | :-- |
83
+
|[openAIChat](/doc/functions/openAIChat.md)| Connect to OpenAI Chat Completion API from MATLAB |
84
+
|[azureChat](/doc/functions/azureChat.md)| Connect to Azure OpenAI Services Chat Completion API from MATLAB |
85
+
|[ollamaChat](/doc/functions/ollamaChat.md)| Connect to Ollama Server from MATLAB |
86
+
|[generate](/doc/functions/generate.md)| Generate output from large language models |
87
+
|[openAIFunction](/doc/functions/openAIFunction.md)| Use Function Calls from MATLAB |
88
+
|[addParameter](/doc/functions/addParameter.md)| Add input argument to `openAIFunction` object |
89
+
|[openAIImages](/doc/functions/openAIImages.md)| Connect to OpenAI Image Generation API from MATLAB |
90
+
|[openAIImages.generate](/doc/functions/openAIImages.generate.md)| Generate image using OpenAI image generation API |
91
+
|[edit](/doc/functions/edit.md)| Edit images using DALL·E 2 |
92
+
|[createVariation](/doc/functions/createVariation.md)| Generate image variations using DALL·E 2 |
93
+
|[messageHistory](/doc/functions/messageHistory.md)| Manage and store messages in a conversation |
94
+
|[addSystemMessage](/doc/functions/addSystemMessage.md)| Add system message to message history |
95
+
|[addUserMessage](/doc/functions/addUserMessage.md)| Add user message to message history |
96
+
|[addUserMessageWithImages](/doc/functions/addUserMessageWithImages.md)| Add user message with images to message history |
97
+
|[addToolMessage](/doc/functions/addToolMessage.md)| Add tool message to message history |
98
+
|[addResponseMessage](/doc/functions/addResponseMessage.md)| Add response message to message history |
99
+
|[removeMessage](/doc/functions/removeMessage.md)| Remove message from message history |
65
100
66
101
## License
67
102
@@ -70,4 +105,4 @@ The license is available in the [license.txt](license.txt) file in this GitHub r
0 commit comments