|
2 | 2 |
|
3 | 3 | This repository contains example code to demonstrate how to connect MATLAB to the OpenAI™ Chat Completions API (which powers ChatGPT™). This allows you to leverage the natural language processing capabilities of GPT models directly within your MATLAB environment. |
4 | 4 |
|
5 | | -The functionality shown here simply serve as an interface to the ChatGPT API. You should be familiar with the limitations and risks associated with using this technology as well as with [OpenAI terms and policies](https://openai.com/policies). You are responsible for any fees OpenAI may charge for the use of their API. |
| 5 | +The functionality shown here simply serves as an interface to the ChatGPT API. You should be familiar with the limitations and risks associated with using this technology as well as with [OpenAI terms and policies](https://openai.com/policies). You are responsible for any fees OpenAI may charge for the use of their API. |
6 | 6 |
|
7 | 7 | ## Setup |
8 | 8 | 1. Clone the repository to your local machine. |
@@ -43,22 +43,23 @@ To get started, you can either create an `openAIChat` object and use its methods |
43 | 43 |
|
44 | 44 | ### Simple call without preserving chat history |
45 | 45 |
|
46 | | -In some situations, you will want to use GPT models without preserving chat history. For example, when you want to perform independent queries in a programatic way. |
| 46 | +In some situations, you will want to use GPT models without preserving chat history. For example, when you want to perform independent queries in a programmatic way. |
47 | 47 |
|
48 | 48 | Here's a simple example of how to use the `openAIChat` for sentiment analysis: |
49 | 49 |
|
50 | 50 | ```matlab |
51 | 51 | % Initialize the OpenAI Chat object, passing a system prompt |
52 | 52 |
|
53 | 53 | % The system prompt tells the assistant how to behave, in this case, as a sentiment analyzer |
54 | | -systemPrompt = "You are a sentiment analyser, you will look at a sentence and output a single word that classifier that sentence (positive or negative)."+.... |
| 54 | +systemPrompt = "You are a sentiment analyser. You will look at a sentence and output"+... |
| 55 | + " a single word that classifies that sentence as either 'positive' or 'negative'."+.... |
55 | 56 | "Examples: \n"+... |
56 | | - "The project was a complete failure.\n"+... |
57 | | - "negative\n\n"+... |
| 57 | + "The project was a complete failure. \n"+... |
| 58 | + "negative \n\n"+... |
58 | 59 | "The team successfully completed the project ahead of schedule."+... |
59 | | - "positive\n\n"+... |
60 | | - "His attitude was terribly discouraging to the team.\n"+... |
61 | | - "negative\n\n"; |
| 60 | + "positive \n\n"+... |
| 61 | + "His attitude was terribly discouraging to the team. \n"+... |
| 62 | + "negative \n\n"; |
62 | 63 |
|
63 | 64 | chat = openAIChat(systemPrompt); |
64 | 65 |
|
@@ -90,7 +91,7 @@ history = addUserMessage(history, "What is an eigenvalue?"); |
90 | 91 | [text, response] = generate(chat, history) |
91 | 92 | ``` |
92 | 93 |
|
93 | | -The output `text` will contain the answer and `response` will contain the full response, which you need to include in the hystory as follows |
| 94 | +The output `text` will contain the answer and `response` will contain the full response, which you need to include in the history as follows |
94 | 95 | ```matlab |
95 | 96 | history = addResponseMessage(history, response); |
96 | 97 | ``` |
@@ -121,7 +122,7 @@ Then you can pass the functions to the chat API as follows: |
121 | 122 |
|
122 | 123 | ```matlab |
123 | 124 | chat = openAIChat("You are a helpful assistant", Functions=f); |
124 | | -```` |
| 125 | +``` |
125 | 126 |
|
126 | 127 | The model will automatically determine if the function should be called based on the user input: |
127 | 128 |
|
|
0 commit comments