Skip to content

Adding support to Azure API #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 78 commits into from
Jun 24, 2024
Merged

Adding support to Azure API #8

merged 78 commits into from
Jun 24, 2024

Conversation

AngelVegaAlvarez
Copy link

@AngelVegaAlvarez AngelVegaAlvarez commented Feb 9, 2024

Closes #5

@ccreutzi ccreutzi marked this pull request as draft May 24, 2024 06:37
@codecov-commenter
Copy link

codecov-commenter commented May 24, 2024

Codecov Report

Attention: Patch coverage is 97.39336% with 11 lines in your changes missing coverage. Please review.

Project coverage is 96.78%. Comparing base (38edd99) to head (1ac24ff).
Report is 160 commits behind head on main.

Files Patch % Lines
azureChat.m 94.33% 6 Missing ⚠️
ollamaChat.m 96.92% 2 Missing ⚠️
+llms/+internal/callAzureChatAPI.m 97.14% 1 Missing ⚠️
+llms/+internal/callOllamaChatAPI.m 96.96% 1 Missing ⚠️
messageHistory.m 98.85% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main       #8       +/-   ##
===========================================
+ Coverage   60.98%   96.78%   +35.80%     
===========================================
  Files          33       38        +5     
  Lines        2048     1246      -802     
===========================================
- Hits         1249     1206       -43     
+ Misses        799       40      -759     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@vpapanasta
Copy link
Member

  1. In case of a wrong YOUR_DEPLOYMENT_NAME, I think it is probably better to throw an error, rather than returning an empty string from generate. Would that be possible?

chat = azureChat(YOUR_RESOURCE_NAME, "fooooo", systemPrompt);
txt = generate(chat,"The BBQ today was amazing but too spicy for my taste so I ate part of my food!")

txt =

""
  1. When we have an invalid YOUR_DEPLOYMENT_NAME we throw an ugly error. I think it would be a good idea to trim this error or throw custom error that the deployment name is invalid.

chat = azureChat("https://myFoo.com", "gpt35-azure", systemPrompt);
txt = generate(chat,"The BBQ today was amazing but too spicy for my taste so I ate part of my food!")

Error using [matlab.net.http.RequestMessage/sendOneRequest](matlab:matlab.lang.internal.introspective.errorDocCallback('matlab.net.http.RequestMessage/sendOneRequest', 'E:\jobarchive\Bdeepcore\2024_05_30_h08m36s03_job2628741_pass\matlab\toolbox\matlab\external\interfaces\webservices\http+matlab+net+http\RequestMessage.m', 1348)) ([line 1348](matlab: opentoline('E:\jobarchive\Bdeepcore\2024_05_30_h08m36s03_job2628741_pass\matlab\toolbox\matlab\external\interfaces\webservices\http+matlab+net+http\RequestMessage.m',1348,0)))
Could not access server. https://myFoo.comopenai/deployments/gpt35-azure/chat/completions?api-version=2023-05-15.

Error in [matlab.net.http.RequestMessage/sendAfterChallenge](matlab:matlab.lang.internal.introspective.errorDocCallback('matlab.net.http.RequestMessage/sendAfterChallenge', 'E:\jobarchive\Bdeepcore\2024_05_30_h08m36s03_job2628741_pass\matlab\toolbox\matlab\external\interfaces\webservices\http+matlab+net+http\RequestMessage.m', 1681)) ([line 1681](matlab: opentoline('E:\jobarchive\Bdeepcore\2024_05_30_h08m36s03_job2628741_pass\matlab\toolbox\matlab\external\interfaces\webservices\http+matlab+net+http\RequestMessage.m',1681,0)))
[response, request, history] = obj.sendOneRequest(connector, options, ...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in [matlab.net.http.RequestMessage/sendAndAuthenticate](matlab:matlab.lang.internal.introspective.errorDocCallback('matlab.net.http.RequestMessage/sendAndAuthenticate', 'E:\jobarchive\Bdeepcore\2024_05_30_h08m36s03_job2628741_pass\matlab\toolbox\matlab\external\interfaces\webservices\http+matlab+net+http\RequestMessage.m', 1130)) ([line 1130](matlab: opentoline('E:\jobarchive\Bdeepcore\2024_05_30_h08m36s03_job2628741_pass\matlab\toolbox\matlab\external\interfaces\webservices\http+matlab+net+http\RequestMessage.m',1130,0)))
obj.sendAfterChallenge(response, connector, ...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Copy link
Member

@vpapanasta vpapanasta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our +llms/internal functions have quite low coverage. I would be great to add more tests:
https://app.codecov.io/gh/matlab-deep-learning/llms-with-matlab/tree/AzureAPI/%2Bllms%2F%2Binternal

ccreutzi added 3 commits June 5, 2024 13:45
ollama sends a (correct) header of Content-Type: application/ndjson, so we
need to switch from StreamConsumer to BinaryConsumer, or the response will
never get dispatched.

ollama uses a slightly different JSON format, need to branch based on presence
of fields.

Azure sends JSON broken up in several packets. We remember incomplete lines in
the object and reassemble when the next response comes in.

Azure sends "choices":[]. Handle by ignoring that line.
ccreutzi added 7 commits June 20, 2024 09:04
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`.
URL = "http://localhost:11434/api/chat"; % TODO: model parameter

% The JSON for StopSequences must have an array, and cannot say "stop": "foo".
% The easiest way to ensure that is to never pass in a scalar …
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about: "To ensure that the JSON for StopSequences has a non-scalar array (is a non-scalar array?), create a two-element array if a scalar is passed."

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, in JSON, a one-element array is still an array and would be fine. MATLAB's jsonencode just doesn't create "stop": ["foo"] as we need it to. But we can make it produce "stop": ["foo","foo"] instead.


```matlab
mdl = openAIImages(ModelName="dall-e-3");
images = generate(mdl,"Create a 3D avatar of a whimsical sushi on the beach. He is decorated with various sushi elements and is playfully interacting with the beach environment.");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is delightful.

ccreutzi added 4 commits June 21, 2024 12:12
Having the test points in alphabetic order makes it easier to visually compare with the file system and verify all example files are being tested.
ollamaChat.m Outdated
@@ -61,11 +61,6 @@
%
% SystemPrompt - System prompt.

% Ollama model properties not exposed:
% repeat_last_n, repeat_penalty - could not find an example where they made a difference
% mirostat, mirostat_eta, mirostat_tau - looking for the best API design
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we document this somewhere internal so we don't forget about it?

ccreutzi added 4 commits June 24, 2024 07:25
We had CI-only problems with the tfs_z=0 test files. Log the installed Ollama version to help locate differences between dev environment and CI run.
Ollama fixed reacting to Seed in 0.1.43, add a test point.
It is not yet clear what causes Ollama to not be reliable in these situations, but we do see differences. Will need to analyse separately and report upstream.
@ccreutzi ccreutzi merged commit 05c861b into main Jun 24, 2024
1 check passed
@ccreutzi ccreutzi deleted the AzureAPI branch June 24, 2024 13:23
@adulai adulai removed their request for review June 24, 2024 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Azure OpenAI API
7 participants