-
Notifications
You must be signed in to change notification settings - Fork 883
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
[BYOM] Support for Local, Private Endpoints #26475
Conversation
cd57346
to
3738d8b
Compare
b52b60a
to
3eeef3b
Compare
Total change C4 schemeC4Context
title Private IP Addresses for Custom Model Endpoints
Person(user, "User", "Brave browser user configuring custom AI models")
System_Boundary(brave, "Brave Browser") {
Container(ui, "Settings UI", "WebUI", "Handles model configuration and displays warnings")
Container(validator, "Model Validator", "C++", "Validates model endpoints and configurations")
Container(chat, "AI Chat Service", "C++", "Manages AI chat interactions and models")
Container(flags, "Feature Flags", "C++", "Controls private IP feature availability")
}
System_Ext(private_endpoint, "Private Network Endpoint", "Custom AI model endpoint on local network")
System_Ext(public_endpoint, "Public Endpoint", "Custom AI model endpoint on public internet")
Rel(user, ui, "Configures custom model", "HTTPS")
Rel(ui, validator, "Validates endpoint", "IPC")
Rel(validator, flags, "Checks if private IPs allowed")
Rel(chat, validator, "Validates model configuration")
Rel(chat, private_endpoint, "Connects when allowed", "HTTP/HTTPS")
Rel(chat, public_endpoint, "Connects", "HTTPS")
Model Endpoint Validation FlowsequenceDiagram
participant UI as Model Config UI
participant Handler as Settings Handler
participant Validator as Model Validator
participant Features as Feature Flags
UI->>Handler: validateModelEndpoint(url)
Handler->>Validator: IsValidEndpoint(url)
Validator->>Features: IsAllowPrivateIPsEnabled()
Features-->>Validator: feature_enabled
alt Is HTTPS or localhost
Validator-->>Handler: true
else Is private IP/hostname and feature enabled
Validator->>Validator: IsValidPrivateHost() or IsValidPrivateIPAddress()
Validator-->>Handler: true
else
Validator-->>Handler: false
end
Handler-->>UI: {isValid, isValidAsPrivateEndpoint, isValidDueToPrivateIPsFeature}
alt isValid
UI->>UI: Clear error state
else isValidAsPrivateEndpoint
UI->>UI: Show private IP warning modal
else
UI->>UI: Show invalid URL error
end
Model Activation FlowsequenceDiagram
participant UI as Chat UI
participant Handler as Conversation Handler
participant Validator as Model Validator
participant Features as Feature Flags
UI->>Handler: ChangeModel(model_key)
Handler->>Handler: GetModel(model_key)
alt Is Custom Model
Handler->>Validator: IsValidEndpoint(endpoint)
Validator->>Features: IsAllowPrivateIPsEnabled()
Features-->>Validator: feature_enabled
alt Endpoint Valid
Validator-->>Handler: true
Handler->>Handler: SetAPIError(None)
Handler->>Handler: InitEngine()
else Endpoint Invalid
Validator-->>Handler: false
Handler->>Handler: SetAPIError(InvalidEndpointURL)
end
else
Handler->>Handler: SetAPIError(None)
Handler->>Handler: InitEngine()
end
Handler-->>UI: Update UI state
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
strings
++
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably just remove the .local
check for the moment, or improve by resolving on the UI side and only storing the final IP
Moved some of the earlier endpoint tests into the newer param-based suite for better organization.
Current approach is to check the validity of the endpoint when the first human interaction takes place. If the model endpoint is invalid, an error is shown to the user. The displayed error invites the user to check their model's configuration.
Rather than waiting for the user to interact with the model, this change proactively notifies the user of an invalid model endpoint when the model is selected for use.
With the gap, there is an extra bit of padding above each model listing after the first. This gives the impression that the first model in the list is shorter (i.e., its bounding box size) than all that follow. Further, the gap causes asymmetry between the top and bottom padding on every model listing after the first.
We aim to provide an instructive error message to the user when they have provided an endpoint value that would only be valid with the enabling of optional private IPs.
This change introduces an alternative approach to endpoint validation. Some endpoints are only valid with the enabling of the optional brave-ai-chat-allow-private-ips flag. The new approach informs the user when their provided endpoint URL [would be] valid as a private IP address.
Upon saving a custom model, the URL may be deemed invalid. This change gives a more detailed message to the frontend regarding the endpoint validity, enabling us to present a more helpful error message to the user.
Switching to a model with an invalid endpoint results in an error message being displayed. This change causes the error message to be cleared when switching to another model.
If the user attempts to save a configuration with a private endpoint, and the optional flag has not been enabled, the user will be presented with a modal dialog informing them as much. If the optional flag has been enabled, and the user attempts to use a private endpoint, we will display a label warning them of the risk they're accepting.
Each condition checked `apiHasError`, so we can simplify by moving that to the top-most conditional, and turning the rest of the logic into a switch-case, dropping unnecessary parents around JSX items.
This method no longer queries the backend itself, and therefore no longer needs to be async.
To ease efforts for translators, more descriptive identifiers are provided.
Though not likely to happen, it's possible our method could be called with an invalid number and/or type of arguments. We'll make sure our expectations are clear, and that we reject early otherwise.
Giving proper support to .local domains requires adequate address resolution, which can be somewhat tricky across platforms. For now, we will defer adding support to a later date. Track brave/brave-browser#42367 for additional details and development.
f29cbd4
to
7c68536
Compare
Released in v1.75.43 |
Resolves brave/brave-browser#39627
Included Scenarios
Derived from July 8th and July 18th comments.
To satisfy this requirement, a modal will be displayed upon attempting to save a model configuration with a private endpoint, while the feature is disabled. The modal will give a brief explanation of the issue, and provide guidance on how to enable the feature.
This requirement is addressed with a 🔓 icon (and label) displayed prominently beneath the server endpoint input component. This warning element is only displayed when the server endpoint is valid only due to the optional feature having been enabled.
This pull request introduces a new error message for the chat context. If the model's server endpoint is invalid, the user will be informed. Furthermore, a "Configure" button is displayed to assist the user in reaching the model configuration UI.
Submitter Checklist:
QA/Yes
orQA/No
;release-notes/include
orrelease-notes/exclude
;OS/...
) to the associated issuenpm run test -- brave_browser_tests
,npm run test -- brave_unit_tests
wikinpm run presubmit
wiki,npm run gn_check
,npm run tslint
git rebase master
(if needed)Reviewer Checklist:
gn
After-merge Checklist:
changes has landed on
Test Plan:
Feature Disabled Scenario
brave://flags/#brave-ai-chat-allow-private-ips
http://10.198.1.12:11434/v1/chat/completions
) in a new or existing model configuration.Feature Enabled Scenario
Feature Disabled After Having Been Enabled