Add try-it page on Gateway usage example modal#21077
Add try-it page on Gateway usage example modal#21077PattaraS merged 50 commits intomlflow:masterfrom
Conversation
🛠 DevTools 🛠
Install mlflow from this PRFor Databricks, use the following command: |
|
/autoformat |
There was a problem hiding this comment.
Pull request overview
This pull request adds an interactive "Try it" tab to the Endpoint Usage Modal in the MLflow Gateway UI, allowing users to test API endpoints directly from the browser without writing code.
Changes:
- Adds a new "Try it" tab with interactive request/response interface for testing gateway endpoints
- Supports both Unified (MLflow Invocations) and Passthrough (provider-specific) API modes
- Includes provider selection (OpenAI, Anthropic, Google Gemini) for passthrough requests
mlflow/server/js/src/gateway/components/endpoints/EndpointUsageModal.tsx
Outdated
Show resolved
Hide resolved
| {activeTab === 'try-it' && ( | ||
| <div css={{ display: 'flex', flexDirection: 'column', gap: theme.spacing.md }}> | ||
| <Typography.Text color="secondary"> | ||
| <FormattedMessage | ||
| defaultMessage='Edit the request body below and click Send request to call the endpoint. Choose Unified for the MLflow Invocations API, or Passthrough for provider-specific APIs (OpenAI, Anthropic, Gemini).' | ||
| description="Try it tab description" | ||
| /> | ||
| </Typography.Text> | ||
| <div> | ||
| <Typography.Text bold css={{ display: 'block', marginBottom: theme.spacing.xs }}> | ||
| <FormattedMessage defaultMessage="API" description="API type selector label" /> | ||
| </Typography.Text> | ||
| <SegmentedControlGroup | ||
| name="try-it-api-type" | ||
| componentId="mlflow.gateway.usage-modal.try-it.api-type" | ||
| value={tryItApiType} | ||
| onChange={({ target: { value } }) => { | ||
| setTryItApiType(value as 'unified' | 'passthrough'); | ||
| setRequestBody( | ||
| value === 'unified' ? DEFAULT_REQUEST_BODY_UNIFIED : getPassthroughDefaultBody(tryItProvider, endpointName), | ||
| ); | ||
| }} | ||
| css={{ marginBottom: theme.spacing.sm }} | ||
| > | ||
| <SegmentedControlButton value="unified"> | ||
| <FormattedMessage defaultMessage="Unified (MLflow Invocations)" description="Unified API option" /> | ||
| </SegmentedControlButton> | ||
| <SegmentedControlButton value="passthrough"> | ||
| <FormattedMessage defaultMessage="Passthrough" description="Passthrough API option" /> | ||
| </SegmentedControlButton> | ||
| </SegmentedControlGroup> | ||
| </div> | ||
| {tryItApiType === 'passthrough' && ( | ||
| <div> | ||
| <Typography.Text bold css={{ display: 'block', marginBottom: theme.spacing.xs }}> | ||
| <FormattedMessage defaultMessage="Provider" description="Provider selector label" /> | ||
| </Typography.Text> | ||
| <SegmentedControlGroup | ||
| name="try-it-provider" | ||
| componentId="mlflow.gateway.usage-modal.try-it.provider" | ||
| value={tryItProvider} | ||
| onChange={({ target: { value } }) => { | ||
| const provider = value as Provider; | ||
| setTryItProvider(provider); | ||
| setRequestBody(getPassthroughDefaultBody(provider, endpointName)); | ||
| }} | ||
| css={{ marginBottom: theme.spacing.sm }} | ||
| > | ||
| <SegmentedControlButton value="openai">OpenAI</SegmentedControlButton> | ||
| <SegmentedControlButton value="anthropic">Anthropic</SegmentedControlButton> | ||
| <SegmentedControlButton value="gemini">Google Gemini</SegmentedControlButton> | ||
| </SegmentedControlGroup> | ||
| </div> | ||
| )} | ||
| <div | ||
| css={{ | ||
| display: 'flex', | ||
| gap: theme.spacing.md, | ||
| minHeight: 0, | ||
| flex: 1, | ||
| }} | ||
| > | ||
| <div css={{ flex: 1, minWidth: 0, display: 'flex', flexDirection: 'column' }}> | ||
| <div css={{ display: 'flex', alignItems: 'center', gap: theme.spacing.xs, marginBottom: theme.spacing.xs }}> | ||
| <Typography.Text bold> | ||
| <FormattedMessage defaultMessage="Request" description="Request body label" /> | ||
| </Typography.Text> | ||
| <Tooltip | ||
| content={ | ||
| <FormattedMessage | ||
| defaultMessage='JSON body for the MLflow Invocations API. Use "messages" for chat or "input" for embeddings.' | ||
| description="Request body tooltip" | ||
| /> | ||
| } | ||
| > | ||
| <span css={{ cursor: 'help', color: theme.colors.textSecondary }} aria-label="Request help"> | ||
| ? | ||
| </span> | ||
| </Tooltip> | ||
| </div> | ||
| <Input.TextArea | ||
| componentId="mlflow.gateway.usage-modal.try-it.request" | ||
| value={requestBody} | ||
| onChange={(e) => setRequestBody(e.target.value)} | ||
| disabled={isSending} | ||
| rows={10} | ||
| css={{ | ||
| fontFamily: 'monospace', | ||
| fontSize: theme.typography.fontSizeSm, | ||
| }} | ||
| /> | ||
| </div> | ||
| <div css={{ flex: 1, minWidth: 0, display: 'flex', flexDirection: 'column' }}> | ||
| <div css={{ display: 'flex', alignItems: 'center', gap: theme.spacing.xs, marginBottom: theme.spacing.xs }}> | ||
| <Typography.Text bold> | ||
| <FormattedMessage defaultMessage="Response" description="Response body label" /> | ||
| </Typography.Text> | ||
| <Tooltip | ||
| content={ | ||
| <FormattedMessage | ||
| defaultMessage="Response from the endpoint after clicking Send request." | ||
| description="Response body tooltip" | ||
| /> | ||
| } | ||
| > | ||
| <span css={{ cursor: 'help', color: theme.colors.textSecondary }} aria-label="Response help"> | ||
| ? | ||
| </span> | ||
| </Tooltip> | ||
| </div> | ||
| <Input.TextArea | ||
| componentId="mlflow.gateway.usage-modal.try-it.response" | ||
| value={responseBody} | ||
| readOnly | ||
| rows={10} | ||
| placeholder={ | ||
| sendError | ||
| ? undefined | ||
| : isSending | ||
| ? undefined | ||
| : 'Click "Send request" to see the response here.' | ||
| } | ||
| css={{ | ||
| fontFamily: 'monospace', | ||
| fontSize: theme.typography.fontSizeSm, | ||
| backgroundColor: theme.colors.backgroundSecondary, | ||
| }} | ||
| /> | ||
| {sendError && ( | ||
| <Typography.Text color="danger" css={{ marginTop: theme.spacing.xs }}> | ||
| {sendError} | ||
| </Typography.Text> | ||
| )} | ||
| </div> | ||
| </div> | ||
| <div css={{ display: 'flex', gap: theme.spacing.sm }}> | ||
| <Button | ||
| componentId="mlflow.gateway.usage-modal.try-it.send" | ||
| type="primary" | ||
| onClick={handleSendRequest} | ||
| disabled={isSending} | ||
| > | ||
| <FormattedMessage defaultMessage="Send request" description="Send request button" /> | ||
| </Button> | ||
| <Button | ||
| componentId="mlflow.gateway.usage-modal.try-it.reset" | ||
| onClick={handleResetExample} | ||
| disabled={isSending} | ||
| > | ||
| <FormattedMessage defaultMessage="Reset example" description="Reset example button" /> | ||
| </Button> | ||
| </div> | ||
| </div> | ||
| )} |
There was a problem hiding this comment.
🔴 CRITICAL: No test coverage exists for the new Try it tab functionality. The existing tests only cover the Unified and Passthrough tabs. Tests should be added to verify: request sending, error handling, API type switching, provider selection, response display, and state reset behavior.
mlflow/server/js/src/gateway/components/endpoints/EndpointUsageModal.tsx
Outdated
Show resolved
Hide resolved
mlflow/server/js/src/gateway/components/endpoints/EndpointUsageModal.tsx
Outdated
Show resolved
Hide resolved
mlflow/server/js/src/gateway/components/endpoints/EndpointUsageModal.tsx
Outdated
Show resolved
Hide resolved
mlflow/server/js/src/gateway/components/endpoints/EndpointUsageModal.tsx
Outdated
Show resolved
Hide resolved
mlflow/server/js/src/gateway/components/endpoints/EndpointUsageModal.tsx
Outdated
Show resolved
Hide resolved
mlflow/server/js/src/gateway/components/endpoints/EndpointUsageModal.tsx
Outdated
Show resolved
Hide resolved
| ? undefined | ||
| : isSending | ||
| ? undefined | ||
| : 'Click "Send request" to see the response here.' |
There was a problem hiding this comment.
🟢 NIT: The hardcoded placeholder text "Click 'Send request' to see the response here." doesn't match the actual button text "Send request" in the code (without quotes around "Send request"). For consistency, either add quotes in the button FormattedMessage or remove them from the placeholder.
| : 'Click "Send request" to see the response here.' | |
| : 'Click Send request to see the response here.' |
|
Documentation preview for 188815c is available at: Changed Pages (1) More info
|
|
@copilot open a new pull request to apply changes based on the comments in this thread |
|
/autoformat |
1 similar comment
|
/autoformat |
|
|
||
| const tryItRequestUrl = useMemo(() => { | ||
| if (tryItApiType === 'unified') { | ||
| return `${base}/gateway/${endpointName}/mlflow/invocations`; |
There was a problem hiding this comment.
Why we don't allow users to try unified chat completion?
There was a problem hiding this comment.
I missed that! Adding it now.
| } | ||
| }, [open]); | ||
|
|
||
| const tryItRequestUrl = useMemo(() => { |
There was a problem hiding this comment.
We already show urls for each endpoint type in the curl example, can we consolidate the mapping util?
| [tryItApiType, tryItProvider, endpointName], | ||
| ); | ||
|
|
||
| const handleSendRequest = useCallback(async () => { |
There was a problem hiding this comment.
Can we extract the main logic to a util that calls the invocation api and returns the response or raise an exception?
There was a problem hiding this comment.
Updated the PR with some refactor.
|
Can we test if the test it functionality works even when auth is enabled? |
|
UI Preview for this PR has been removed. |
I did that (also added a test) |
|
@PattaraS sorry for the back and forth, but I started to think it's semantically clearer if we locate the "try it" tab in the same level as curl or python. So the information structure would be |
I think that makes sense. Will make a code change accordingly. |
Signed-off-by: Pat Sukprasert <pattara.sk127@gmail.com>
Signed-off-by: Pat Sukprasert <pattara.sk127@gmail.com>
Signed-off-by: Pat Sukprasert <pattara.sk127@gmail.com>
Signed-off-by: Pat Sukprasert <pattara.sk127@gmail.com>
Signed-off-by: Pat Sukprasert <pattara.sk127@gmail.com>
Signed-off-by: Pat Sukprasert <pattara.sk127@gmail.com>
Signed-off-by: Pat Sukprasert <pattara.sk127@gmail.com>
Signed-off-by: Pat Sukprasert <pattara.sk127@gmail.com>
Signed-off-by: Pat Sukprasert <pattara.sk127@gmail.com>
Signed-off-by: Pat Sukprasert <pattara.sk127@gmail.com>
Signed-off-by: Pat Sukprasert <pattara.sk127@gmail.com>
Signed-off-by: Pat Sukprasert <pattara.sk127@gmail.com>
…ic-dangerous-direct-browser-access Signed-off-by: Pat Sukprasert <pattara.sk127@gmail.com>
Signed-off-by: Pat Sukprasert <pattara.sk127@gmail.com>
Signed-off-by: Pat Sukprasert <pattara.sk127@gmail.com>
a1cc759 to
188815c
Compare
Signed-off-by: Pat Sukprasert <pattara.sk127@gmail.com> Signed-off-by: mlflow-app[bot] <mlflow-app[bot]@users.noreply.github.com> Co-authored-by: mlflow-app[bot] <mlflow-app[bot]@users.noreply.github.com>
Signed-off-by: Pat Sukprasert <pattara.sk127@gmail.com> Signed-off-by: mlflow-app[bot] <mlflow-app[bot]@users.noreply.github.com> Co-authored-by: mlflow-app[bot] <mlflow-app[bot]@users.noreply.github.com>
Signed-off-by: Pat Sukprasert <pattara.sk127@gmail.com> Signed-off-by: mlflow-app[bot] <mlflow-app[bot]@users.noreply.github.com> Co-authored-by: mlflow-app[bot] <mlflow-app[bot]@users.noreply.github.com>
Related Issues/PRs
#xxxWhat changes are proposed in this pull request?
Adds an interactive "Try it" tab to the AI Gateway endpoint usage modal, letting users send requests directly to an endpoint from the UI.
How is this PR tested?
Does this PR require documentation update?
Does this PR require updating the MLflow Skills repository?
Release Notes
Is this a user-facing change?
AI Gateway endpoint usage modal now includes a "Try it" tab for sending requests interactively from the UI, with support for both Unified (MLflow Invocations) and Passthrough (OpenAI, Anthropic, Gemini) APIs.
What component(s), interfaces, languages, and integrations does this PR affect?
Components
area/tracking: Tracking Service, tracking client APIs, autologgingarea/models: MLmodel format, model serialization/deserialization, flavorsarea/model-registry: Model Registry service, APIs, and the fluent client calls for Model Registryarea/scoring: MLflow Model server, model deployment tools, Spark UDFsarea/evaluation: MLflow model evaluation features, evaluation metrics, and evaluation workflowsarea/gateway: MLflow AI Gateway client APIs, server, and third-party integrationsarea/prompts: MLflow prompt engineering features, prompt templates, and prompt managementarea/tracing: MLflow Tracing features, tracing APIs, and LLM tracing functionalityarea/projects: MLproject format, project running backendsarea/uiux: Front-end, user experience, plotting, JavaScript, JavaScript dev serverarea/build: Build and test infrastructure for MLflowarea/docs: MLflow documentation pagesHow should the PR be classified in the release notes? Choose one:
rn/none- No description will be included. The PR will be mentioned only by the PR number in the "Small Bugfixes and Documentation Updates" sectionrn/breaking-change- The PR will be mentioned in the "Breaking Changes" sectionrn/feature- A new user-facing feature worth mentioning in the release notesrn/bug-fix- A user-facing bug fix worth mentioning in the release notesrn/documentation- A user-facing documentation change worth mentioning in the release notesShould this PR be included in the next patch release?
Yesshould be selected for bug fixes, documentation updates, and other small changes.Noshould be selected for new features and larger changes. If you're unsure about the release classification of this PR, leave this unchecked to let the maintainers decide.What is a minor/patch release?
Bug fixes, doc updates and new features usually go into minor releases.
Bug fixes and doc updates usually go into patch releases.