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
azureChat should get endpoint and deployment from env
Removed the positional arguments from `azureChat` constructor, and replaced with NVPs that default to reading from the environment instead.
Updated instructions to include those environment variables in `.env`.
Copy file name to clipboardExpand all lines: +llms/+utils/errorMessageCatalog.m
+2Lines changed: 2 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -43,6 +43,8 @@
43
43
catalog("llms:assistantMustHaveTextNameAndArguments") ="Fields 'name' and 'arguments' must be text with one or more characters.";
44
44
catalog("llms:mustBeValidIndex") ="Value is larger than the number of elements in Messages ({1}).";
45
45
catalog("llms:stopSequencesMustHaveMax4Elements") ="Number of elements must not be larger than 4.";
46
+
catalog("llms:endpointMustBeSpecified") ="Unable to find endpoint. Either set environment variable AZURE_OPENAI_ENDPOINT or specify name-value argument ""Endpoint"".";
47
+
catalog("llms:deploymentMustBeSpecified") ="Unable to find deployment name. Either set environment variable AZURE_OPENAI_DEPLOYMENT or specify name-value argument ""Deployment"".";
46
48
catalog("llms:keyMustBeSpecified") ="Unable to find API key. Either set environment variable {1} or specify name-value argument ""APIKey"".";
47
49
catalog("llms:mustHaveMessages") ="Value must contain at least one message in Messages.";
48
50
catalog("llms:mustSetFunctionsForCall") ="When no functions are defined, ToolChoice must not be specified.";
Copy file name to clipboardExpand all lines: doc/Azure.md
+10-10Lines changed: 10 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -16,6 +16,8 @@ Some of the [current LLMs supported on Azure](https://learn.microsoft.com/en-us/
16
16
Set up your [endpoint and deployment and retrieve one of the API keys](https://learn.microsoft.com/en-us/azure/ai-services/openai/chatgpt-quickstart?tabs=command-line%2Cpython-new&pivots=rest-api#retrieve-key-and-endpoint). Create a `.env` file in the project root directory with the following content.
17
17
18
18
```
19
+
AZURE_OPENAI_ENDPOINT=<your endpoint>
20
+
AZURE_OPENAI_DEPLOYMENT=<your deployment>
19
21
AZURE_OPENAI_API_KEY=<your key>
20
22
```
21
23
@@ -29,11 +31,11 @@ loadenv(".env")
29
31
30
32
## Establishing a connection to Chat Completions API using Azure
31
33
32
-
To connect MATLAB to Chat Completions API via Azure, you will have to create an `azureChat` object. See [the Azure documentation](https://learn.microsoft.com/en-us/azure/ai-services/openai/chatgpt-quickstart) for details on the setup required and where to find your key, endpoint, and deployment name. As explained above, the key should be in the environment variable `AZURE_OPENAI_API_KEY`, or provided as `APIKey=…` in the `azureChat` call below.
34
+
To connect MATLAB to Chat Completions API via Azure, you will have to create an `azureChat` object. See [the Azure documentation](https://learn.microsoft.com/en-us/azure/ai-services/openai/chatgpt-quickstart) for details on the setup required and where to find your key, endpoint, and deployment name. As explained above, the endpoint, deployment, and key should be in the environment variables `AZURE_OPENAI_ENDPOINT`, `AZURE_OPENAI_DEPLOYMENYT`, and `AZURE_OPENAI_API_KEY`, or provided as`Endpoint=…`, `Deployment=…`, and`APIKey=…` in the `azureChat` call below.
33
35
34
-
In order to create the chat assistant, specify your Azure OpenAI Resource and the LLM you want to use:
36
+
In order to create the chat assistant, use the `azureChat` function, optionally providing a system prompt:
35
37
```matlab
36
-
chat = azureChat(YOUR_ENDPOINT_NAME, YOUR_DEPLOYMENT_NAME, "You are a helpful AI assistant");
38
+
chat = azureChat("You are a helpful AI assistant");
37
39
```
38
40
39
41
The `azureChat` object also allows to specify additional options. Call `help azureChat` for more information.
@@ -60,7 +62,7 @@ systemPrompt = "You are a sentiment analyser. You will look at a sentence and ou
60
62
"His attitude was terribly discouraging to the team." + newline +...
txt = generate(chat,"What is Model-Based Design and how is it related to Digital Twin?")
113
115
% Should stream the response token by token
114
116
```
@@ -123,7 +125,7 @@ For example, if you want to use the API for mathematical operations such as `sin
123
125
```matlab
124
126
f = openAIFunction("sind","Sine of argument in degrees");
125
127
f = addParameter(f,"x",type="number",description="Angle in degrees.");
126
-
chat = azureChat(YOUR_ENDPOINT_NAME,YOUR_DEPLOYMENT_NAME,"You are a helpful assistant.",Tools=f);
128
+
chat = azureChat("You are a helpful assistant.",Tools=f);
127
129
```
128
130
129
131
When the model identifies that it could use the defined functions to answer a query, it will return a `tool_calls` request, instead of directly generating the response:
@@ -217,8 +219,7 @@ f = addParameter(f,"patientSymptoms",type="string",description="Symptoms that th
217
219
Note that this function does not need to exist, since it will only be used to extract the Name, Age and Symptoms of the patient and it does not need to be called:
@@ -35,22 +34,22 @@ function constructChatWithAllNVP(testCase)
35
34
36
35
function doGenerate(testCase,StringInputs)
37
36
testCase.assumeTrue(isenv("AZURE_OPENAI_API_KEY"),"end-to-end test requires environment variables AZURE_OPENAI_API_KEY, AZURE_OPENAI_ENDPOINT, and AZURE_OPENAI_DEPLOYMENT.");
testCase.assumeTrue(isenv("AZURE_OPENAI_API_KEY"),"end-to-end test requires environment variables AZURE_OPENAI_API_KEY, AZURE_OPENAI_ENDPOINT, and AZURE_OPENAI_DEPLOYMENT.");
% This input is considerably longer than accepted as input for
55
54
% GPT-3.5 (16385 tokens)
56
55
wayTooLong = string(repmat('a ',1,20000));
@@ -59,7 +58,7 @@ function doReturnErrors(testCase)
59
58
60
59
function seedFixesResult(testCase)
61
60
testCase.assumeTrue(isenv("AZURE_OPENAI_API_KEY"),"end-to-end test requires environment variables AZURE_OPENAI_API_KEY, AZURE_OPENAI_ENDPOINT, and AZURE_OPENAI_DEPLOYMENT.");
0 commit comments