Repository navigation
[FEAT] - Show native and converted gateway endpoints per model #96
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c32096f
[FEAT] - Show native and converted gateway endpoints per model
Henrik-3 f2e3463
[FEAT] - Prefill native endpoints for preconfigured providers
Henrik-3 e1822ce
[FEAT] - Run Mistral on the Responses adapter
Henrik-3 9d69916
[REFACTOR] - Generate chat protocol constants for the frontend
Henrik-3 5ddb7a0
[FIX] - Keep native protocols on custom providers and model sync
Henrik-3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| import type {Page} from '@playwright/test'; | ||
| import {test, expect} from './support/fixtures'; | ||
| import {createKeyViaApi, uniqueName, waitForLog} from './support/gateway'; | ||
| import {LLM} from './support/constants'; | ||
| import {KIND_CHAT_PROTOCOL} from '../../frontend/types/generated/protocols'; | ||
|
|
||
| const own = KIND_CHAT_PROTOCOL[LLM.kind]!; | ||
| const extra = own === 'messages' ? 'chat' : 'messages'; | ||
|
|
||
| async function openProvider(page: Page, t: (key: string) => string, providerName: string) { | ||
| await page.goto('/settings/providers'); | ||
| await expect(page.getByText(t('settings.providers.configured'), {exact: true}).first()).toBeVisible(); | ||
| const card = page | ||
| .locator('div') | ||
| .filter({has: page.getByRole('heading', {name: providerName, exact: true})}) | ||
| .filter({has: page.locator('.lucide-settings-2')}) | ||
| .last(); | ||
| await card.getByRole('button').filter({has: page.locator('.lucide-settings-2')}).click(); | ||
| await expect(page.getByTestId('provider-protocols')).toBeVisible(); | ||
| } | ||
|
|
||
| test.describe('native endpoints', () => { | ||
| test.afterEach(async ({api, seed}) => { | ||
| await api.put(`/api/v1/admin/providers/${seed.providerId}`, {protocols: []}); | ||
| }); | ||
|
|
||
| test('a provider lists the protocols it serves natively from its dialog', async ({page, t, api, seed}) => { | ||
| const provider = await api.get(`/api/v1/admin/providers/${seed.providerId}`); | ||
| await openProvider(page, t, provider.name); | ||
| await expect(page.getByTestId('provider-protocols')).toContainText(t(`developer.protocol.${own}`)); | ||
|
|
||
| await page.getByTestId('provider-protocols').click(); | ||
| await expect(page.getByTestId(`provider-protocol-${own}`)).toHaveAttribute('data-disabled', ''); | ||
| await expect(page.getByTestId(`provider-protocol-${extra}`)).toContainText(`${provider.base_url}/v1/`); | ||
| await page.getByTestId(`provider-protocol-${extra}`).click(); | ||
| await page.keyboard.press('Escape'); | ||
| await expect(page.getByTestId('provider-protocols')).toContainText(t(`developer.protocol.${extra}`)); | ||
|
|
||
| await page.getByRole('dialog').getByRole('button', {name: t('common.save'), exact: true}).click(); | ||
| await expect(page.getByText(t('settings.providers.save_success')).first()).toBeVisible(); | ||
| expect((await api.get(`/api/v1/admin/providers/${seed.providerId}`)).protocols).toEqual([extra]); | ||
| }); | ||
|
|
||
| test('developer models show which endpoints are passed through and which are converted', async ({page, t, api, seed}) => { | ||
| await createKeyViaApi(api, seed.teamId, uniqueName('routes-key')); | ||
| await api.put(`/api/v1/admin/providers/${seed.providerId}`, {protocols: [extra]}); | ||
| await page.goto('/developer/models'); | ||
| const row = page.getByTestId(`model-row-${seed.model.publicId}`); | ||
| await expect(row).toBeVisible(); | ||
|
|
||
| const native = row.getByTestId('model-routes-native'); | ||
| await expect(native).toHaveAttribute('aria-label', new RegExp(t('developer.models.routes_native'))); | ||
| await expect(native).toHaveAttribute('aria-label', extra === 'messages' ? /\/anthropic\/v1\/messages/ : /\/openai\/v1\/chat\/completions/); | ||
| await expect(native).toHaveAttribute('tabindex', '0'); | ||
| await native.hover(); | ||
| await expect(page.getByText(t('developer.models.routes_native'), {exact: true}).first()).toBeVisible(); | ||
| await expect(row.getByTestId('model-routes-converted')).toHaveAttribute('aria-label', new RegExp(t(`developer.protocol.${own}`))); | ||
|
|
||
| const third = ['chat', 'responses', 'messages'].find(protocol => protocol !== own && protocol !== extra)!; | ||
| await page.getByTestId('model-native-filter').click(); | ||
| await page.getByRole('option', {name: t('developer.models.native_filter').replace('{protocol}', t(`developer.protocol.${extra}`))}).click(); | ||
| await expect(row).toBeVisible(); | ||
| await page.getByTestId('model-native-filter').click(); | ||
| await page.getByRole('option', {name: t('developer.models.native_filter').replace('{protocol}', t(`developer.protocol.${third}`))}).click(); | ||
| await expect(row).toHaveCount(0); | ||
| }); | ||
|
|
||
| test('an Anthropic Messages request reaches a router that speaks Messages natively', async ({page, api, seed}) => { | ||
| test.skip(LLM.isMock || LLM.kind !== 'OPENROUTER', 'needs a real router that serves Anthropic Messages'); | ||
| await api.put(`/api/v1/admin/providers/${seed.providerId}`, {protocols: ['messages']}); | ||
| const key = await createKeyViaApi(api, seed.teamId, uniqueName('native-messages')); | ||
| try { | ||
| const response = await page.request.post('/anthropic/v1/messages', { | ||
| headers: {'x-api-key': key.token, 'anthropic-version': '2023-06-01'}, | ||
| data: {model: seed.model.publicId, max_tokens: 20, messages: [{role: 'user', content: 'Say hi'}]}, | ||
| failOnStatusCode: false, | ||
| }); | ||
| expect(response.status(), await response.text()).toBe(200); | ||
| expect((await response.json()).type).toBe('message'); | ||
| const log = await waitForLog(api, key.id, response.headers()['x-request-id']); | ||
| expect(Number(log.input_tokens)).toBeGreaterThan(0); | ||
| } finally { | ||
| await api.post(`/api/v1/developer/keys/${key.id}/revoke`); | ||
| } | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| <template> | ||
| <span v-if="groups.length" class="inline-flex items-center gap-1"> | ||
| <ShadTooltip v-for="group in groups" :key="group.id"> | ||
| <ShadTooltipTrigger as-child> | ||
| <span | ||
| class="inline-flex items-center rounded-full px-1.5 py-0.5" | ||
| :class="group.class" | ||
| tabindex="0" | ||
| :aria-label="[group.title, ...group.lines].join('. ')" | ||
| :data-testid="`model-routes-${group.id}`" | ||
| > | ||
| <component :is="group.icon" class="h-3.5 w-3.5" /> | ||
| </span> | ||
| </ShadTooltipTrigger> | ||
| <ShadTooltipContent class="max-w-md"> | ||
| <p class="mb-1 text-xs font-medium">{{ group.title }}</p> | ||
| <p v-for="line in group.lines" :key="line" class="whitespace-pre font-mono text-xs">{{ line }}</p> | ||
| </ShadTooltipContent> | ||
| </ShadTooltip> | ||
| </span> | ||
| </template> | ||
|
|
||
| <script setup lang="ts"> | ||
| import {ArrowRight, Shuffle} from 'lucide-vue-next'; | ||
| import {useMainStore} from '@/stores'; | ||
| import {gatewayRoute} from '~/utils/developer'; | ||
| import type {ChatRouteResponse} from '~/types/generated/ChatRouteResponse'; | ||
|
|
||
| const props = defineProps<{routes: ChatRouteResponse[]}>(); | ||
|
|
||
| const store = useMainStore(); | ||
|
|
||
| function target(route: ChatRouteResponse): string { | ||
| return route.outbound ? store.getTranslation(`developer.protocol.${route.outbound}`) : store.getTranslation('developer.models.route_own_api'); | ||
| } | ||
|
|
||
| const groups = computed(() => | ||
| [ | ||
| { | ||
| id: 'native', | ||
| icon: ArrowRight, | ||
| class: 'bg-primary/10 text-primary', | ||
| title: store.getTranslation('developer.models.routes_native'), | ||
| lines: props.routes.filter(route => route.native).map(route => gatewayRoute(route.inbound)), | ||
| }, | ||
| { | ||
| id: 'converted', | ||
| icon: Shuffle, | ||
| class: 'text-muted-foreground', | ||
| title: store.getTranslation('developer.models.routes_converted'), | ||
| lines: props.routes.filter(route => !route.native).map(route => `${gatewayRoute(route.inbound)} → ${target(route)}`), | ||
| }, | ||
| ].filter(group => group.lines.length > 0), | ||
| ); | ||
| </script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🔍 Messages test cannot distinguish conversion
The test checks the gateway response and token log, both of which the converted route also produces. It never observes which upstream endpoint handled the request.
Was this helpful? React with 👍 or 👎 to provide feedback.