Skip to content

Do not expose providers api #84

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 6 commits into from
Jun 5, 2025

Conversation

brichet
Copy link
Collaborator

@brichet brichet commented May 23, 2025

This PR avoids exposing the chat or LLM model API, to avoid exposing API keys or other secrets that are exposed in langchain model (e.g. https://github.com/langchain-ai/langchainjs/blob/1846bdbb0fbe88c0981d11bfc5e302d2756565f2/libs/langchain-mistralai/src/chat_models.ts#L911).

The chat model only expose a stream() wrapper, and the completer model expose a fetch() wrapper.

cc. @trungleduc who first catches this issue and suggest a workaround.

@brichet brichet added the enhancement New feature or request label May 23, 2025
@brichet brichet requested review from jtpio and trungleduc May 26, 2025 07:07
@brichet brichet marked this pull request as ready for review May 26, 2025 07:08
Copy link
Member

@trungleduc trungleduc left a comment

Choose a reason for hiding this comment

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

Neat!

@trungleduc
Copy link
Member

And you are tagging the wrong person 😸

@brichet
Copy link
Collaborator Author

brichet commented May 26, 2025

And you are tagging the wrong person 😸

Oups

@jtpio
Copy link
Member

jtpio commented May 26, 2025

to avoid exposing API keys or other secrets that are exposed in langchain model

That wouldn't prevent a plugin to access _completer directly in JavaScript, or with provider['_completer']?

@trungleduc
Copy link
Member

to avoid exposing API keys or other secrets that are exposed in langchain model

That wouldn't prevent a plugin to access _completer directly in JavaScript, or with provider['_completer']?

you don't have access to the provider

@brichet
Copy link
Collaborator Author

brichet commented May 26, 2025

to avoid exposing API keys or other secrets that are exposed in langchain model

That wouldn't prevent a plugin to access _completer directly in JavaScript, or with provider['_completer']?

The _currentProvider exposed in AIProviderRegistry is only the description of the provider, but the models are not instantiated.
After this PR, the currentCompleter and currentChatModel are only objects wrapping the required functions.

@brichet
Copy link
Collaborator Author

brichet commented May 26, 2025

Actually I wonder if it won't break the WebLLM provider, since some of its methods may not be available anymore.

@brichet brichet marked this pull request as draft May 26, 2025 14:38
@brichet brichet force-pushed the do_not_expose_providers_API branch from 7b5a19f to bf01624 Compare June 5, 2025 10:22
@brichet brichet marked this pull request as ready for review June 5, 2025 10:22
@brichet
Copy link
Collaborator Author

brichet commented Jun 5, 2025

@trungleduc @jtpio there is now a flag to allow exposing the whole model API when registering the provider.
This flag is used for WebLLM, which needs some custom API functions (there is no sensitive information available in its API)

void model.initialize(report => {

To prevents being able to modify this flag, the AIProviders, _currentProvider are not exposed anymore in the the registry.
The _name attribute has also been moved in a private namespace, to prevent inconsistency between the name and the models. It could also lead to expose the chat model while not expected.

Co-authored-by: Duc Trung Le <leductrungxf@gmail.com>
@jtpio
Copy link
Member

jtpio commented Jun 5, 2025

Thanks @brichet! Yes exposing less things sounds good.

@brichet brichet merged commit 3281507 into jupyterlite:main Jun 5, 2025
8 checks passed
@brichet brichet deleted the do_not_expose_providers_API branch June 5, 2025 15:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants