Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
MiriamScharnke authored and ccreutzi committed Feb 7, 2025
1 parent 1c9e534 commit ef2f01a
Showing 1 changed file with 76 additions and 41 deletions.
117 changes: 76 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,67 +1,102 @@

# Large Language Models (LLMs) with MATLAB

[![Open in MATLAB Online](https://www.mathworks.com/images/responsive/global/open-in-matlab-online.svg)](https://matlab.mathworks.com/open/github/v1?repo=matlab-deep-learning/llms-with-matlab) [![View Large Language Models (LLMs) with MATLAB on File Exchange](https://www.mathworks.com/matlabcentral/images/matlab-file-exchange.svg)](https://www.mathworks.com/matlabcentral/fileexchange/163796-large-language-models-llms-with-matlab)

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.
Large Language Models (LLMs) with MATLAB lets you connect to large language model APIs using MATLAB®.


You can connect to:

## Requirements
- [OpenAI® Chat Completions API](https://platform.openai.com/docs/guides/text-generation/chat-completions-api) — For example, connect to ChatGPT™.
- [OpenAI Images API](https://platform.openai.com/docs/guides/images) — For example, connect to DALL·E™.
- [Azure® OpenAI Service](https://learn.microsoft.com/en-us/azure/ai-services/openai/) — Connect to OpenAI models from Azure.
- [Ollama™](https://ollama.com/) — Connect to models locally or nonlocally.

### MathWorks Products (https://www.mathworks.com)
Using this add-on, you can:

- Requires MATLAB release R2024a or newer.
- Some examples require Text Analytics Toolbox™.
- Generate responses to natural language prompts.
- Manage chat history.
- Generate JSON\-formatted and structured output.
- Use tool calling.
- Generate, edit, and describe images.

### 3rd Party Products:
For more information about the features in this add-on, see the documentation in the [`doc`](/doc) directory.

- 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: An Ollama installation.
# Installation

## Setup
Using this add-on requires MATLAB R2024a or newer.

See these pages for instructions specific to the 3rd party product selected:
## Use MATLAB Online

* [OpenAI](doc/OpenAI.md)
* [Azure](doc/Azure.md)
* [Ollama](doc/Ollama.md)
You can use the add-on in MATLAB Online™ by clicking this link: [![Open in MATLAB Online](https://www.mathworks.com/images/responsive/global/open-in-matlab-online.svg)](https://matlab.mathworks.com/open/github/v1?repo=matlab-deep-learning/llms-with-matlab)

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.

### MATLAB Online
## Install using Add\-On Explorer

To use this repository with MATLAB Online, click [![Open in MATLAB Online](https://www.mathworks.com/images/responsive/global/open-in-matlab-online.svg)](https://matlab.mathworks.com/open/github/v1?repo=matlab-deep-learning/llms-with-matlab)
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

### MATLAB Desktop
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:

To use this repository with a local installation of MATLAB, first clone the repository.
```
>> !git clone https://github.com/matlab-deep-learning/llms-with-matlab.git
```

1. In the system command prompt, run:
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.

```bash
git clone https://github.com/matlab-deep-learning/llms-with-matlab.git
```

2. Open MATLAB and navigate to the directory where you cloned the repository.
```
>> addpath("path/to/llms-with-matlab")
```
# Get Started with External APIs

3. Add the directory to the MATLAB path.
For more information about how to connect to the different APIs from MATLAB, including installation requirements, see:
- [OpenAI](/doc/OpenAI.md)
- [Azure OpenAI Service](/doc/Azure.md)
- [Ollama](/doc/Ollama.md)

```matlab
addpath('path/to/llms-with-matlab');
```
# Examples

## Examples
To learn how to use this in your workflows, see [Examples](/examples/).
- [Process Generated Text in Real Time by Using ChatGPT in Streaming Mode](/examples/ProcessGeneratedTextinRealTimebyUsingChatGPTinStreamingMode.md)
- [Process Generated Text in Real Time by Using Ollama in Streaming Mode](/examples/ProcessGeneratedTextinRealTimebyUsingOllamainStreamingMode.md)
- [Summarize Large Documents Using ChatGPT and MATLAB](/examples/SummarizeLargeDocumentsUsingChatGPTandMATLAB.md) (requires Text Analytics Toolbox™)
- [Create Simple ChatBot](/examples/CreateSimpleChatBot.md) (requires Text Analytics Toolbox)
- [Create Simple Ollama ChatBot](/examples/CreateSimpleOllamaChatBot.md)
- [Analyze Scientific Papers Using ChatGPT Function Calls](/examples/AnalyzeScientificPapersUsingFunctionCalls.md)
- [Analyze Sentiment in Text Using ChatGPT and Structured Output](/examples/AnalyzeSentimentinTextUsingChatGPTwithStructuredOutput.md)
- [Analyze Text Data Using Parallel Function Calls with ChatGPT](/examples/AnalyzeTextDataUsingParallelFunctionCallwithChatGPT.md)
- [Analyze Text Data Using Parallel Function Calls with Ollama](/examples/AnalyzeTextDataUsingParallelFunctionCallwithOllama.md)
- [Retrieval-Augmented Generation Using ChatGPT and MATLAB](/examples/RetrievalAugmentedGenerationUsingChatGPTandMATLAB.md) (requires Text Analytics Toolbox)
- [Retrieval-Augmented Generation Using Ollama and MATLAB](/examples/RetrievalAugmentedGenerationUsingOllamaAndMATLAB.md) (requires Text Analytics Toolbox)
- [Describe Images Using ChatGPT](/examples/DescribeImagesUsingChatGPT.md)
- [Using DALL·E To Edit Images](/examples/UsingDALLEToEditImages.md)
- [Using DALL·E To Generate Images](/examples/UsingDALLEToGenerateImages.md)

- [ProcessGeneratedTextinRealTimebyUsingChatGPTinStreamingMode.md](/examples/ProcessGeneratedTextinRealTimebyUsingChatGPTinStreamingMode.md): Learn to implement a simple chat that stream the response.
- [SummarizeLargeDocumentsUsingChatGPTandMATLAB.md](/examples/SummarizeLargeDocumentsUsingChatGPTandMATLAB.md): Learn to create concise summaries of long texts with ChatGPT. (Requires Text Analytics Toolbox™)
- [CreateSimpleChatBot.md](/examples/CreateSimpleChatBot.md): Build a conversational chatbot capable of handling various dialogue scenarios using ChatGPT. (Requires Text Analytics Toolbox)
- [AnalyzeScientificPapersUsingFunctionCalls.md](/examples/AnalyzeScientificPapersUsingFunctionCalls.md): Learn how to create agents capable of executing MATLAB functions.
- [AnalyzeTextDataUsingParallelFunctionCallwithChatGPT.md](/examples/AnalyzeTextDataUsingParallelFunctionCallwithChatGPT.md): Learn how to take advantage of parallel function calling.
- [RetrievalAugmentedGenerationUsingChatGPTandMATLAB.md](/examples/RetrievalAugmentedGenerationUsingChatGPTandMATLAB.md): Learn about retrieval augmented generation with a simple use case. (Requires Text Analytics Toolbox™)
- [DescribeImagesUsingChatGPT.md](/examples/DescribeImagesUsingChatGPT.md): Learn how to use GPT-4 Turbo with Vision to understand the content of an image.
- [AnalyzeSentimentinTextUsingChatGPTinJSONMode.md](/examples/AnalyzeSentimentinTextUsingChatGPTinJSONMode.md): Learn how to use JSON mode in chat completions
- [UsingDALLEToEditImages.md](/examples/UsingDALLEToEditImages.md): Learn how to generate images
- [UsingDALLEToGenerateImages.md](/examples/UsingDALLEToGenerateImages.md): Create variations of images and editimages.
# Functions
| **Function** | **Description** |
| :-- | :-- |
| [openAIChat](/doc/functions/openAIChat.md) | Connect to OpenAI Chat Completion API from MATLAB |
| [azureChat](/doc/functions/azureChat.md) | Connect to Azure OpenAI Services Chat Completion API from MATLAB |
| [ollamaChat](/doc/functions/ollamaChat.md) | Connect to Ollama Server from MATLAB |
| [generate](/doc/functions/generate.md) | Generate output from large language models |
| [openAIFunction](/doc/functions/openAIFunction.md) | Use Function Calls from MATLAB |
| [addParameter](/doc/functions/addParameter.md) | Add input argument to `openAIFunction` object |
| [openAIImages](/doc/functions/openAIImages.md) | Connect to OpenAI Image Generation API from MATLAB |
| [openAIImages.generate](/doc/functions/openAIImages.generate.md) | Generate image using OpenAI image generation API |
| [edit](/doc/functions/edit.md) | Edit images using DALL·E 2 |
| [createVariation](/doc/functions/createVariation.md) | Generate image variations using DALL·E 2 |
| [messageHistory](/doc/functions/messageHistory.md) | Manage and store messages in a conversation |
| [addSystemMessage](/doc/functions/addSystemMessage.md) | Add system message to message history |
| [addUserMessage](/doc/functions/addUserMessage.md) | Add user message to message history |
| [addUserMessageWithImages](/doc/functions/addUserMessageWithImages.md) | Add user message with images to message history |
| [addToolMessage](/doc/functions/addToolMessage.md) | Add tool message to message history |
| [addResponseMessage](/doc/functions/addResponseMessage.md) | Add response message to message history |
| [removeMessage](/doc/functions/removeMessage.md) | Remove message from message history |

## License

Expand All @@ -70,4 +105,4 @@ The license is available in the [license.txt](license.txt) file in this GitHub r
## Community Support
[MATLAB Central](https://www.mathworks.com/matlabcentral)

Copyright 2023-2024 The MathWorks, Inc.
Copyright 2023-2025 The MathWorks, Inc.

0 comments on commit ef2f01a

Please sign in to comment.