Skip to content

Commit

Permalink
🐛fix: fix condition on client fetch (#2519)
Browse files Browse the repository at this point in the history
* 🐛fix: wrong client fetch judgement

* ✅ test: add test for `isProviderFetchOnClient`

* 🔧 fix: make azure request sent from server

* 🔧 refactor: show client fetch for azure
  • Loading branch information
cy948 committed May 20, 2024
1 parent 6638c70 commit 5fc90a9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/app/(main)/settings/llm/Azure/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ const AzureOpenAIProvider = memo(() => {
placeholder: t('azure.modelListPlaceholder'),
}}
provider={providerKey}
showBrowserRequest
title={
<Flexbox align={'center'} gap={8} horizontal>
<Azure.Combine size={22} type={'color'}></Azure.Combine>
Expand Down
30 changes: 29 additions & 1 deletion src/store/user/slices/settings/selectors/modelConfig.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { describe, expect, it } from 'vitest';

import { UserStore } from '@/store/user';
import { merge } from '@/utils/merge';

import { UserStore, useUserStore } from '../../../store';
import { UserSettingsState, initialSettingsState } from '../initialState';
import { modelConfigSelectors } from './modelConfig';

Expand Down Expand Up @@ -33,6 +33,34 @@ describe('modelConfigSelectors', () => {
});
});

describe('isProviderFetchOnClient', () => {
it('client fetch should disabled on default', () => {
const s = merge(initialSettingsState, {
settings: {
languageModel: {
azure: {
endpoint: 'endpoint',
apiKey: 'apikey',
},
},
},
} as UserSettingsState) as unknown as UserStore;

expect(modelConfigSelectors.isProviderFetchOnClient('azure')(s)).toBe(false);
});

it('client fetch should enabled if user set it enabled', () => {
const s = merge(initialSettingsState, {
settings: {
languageModel: {
azure: { fetchOnClient: true },
},
},
} as UserSettingsState) as unknown as UserStore;
expect(modelConfigSelectors.isProviderFetchOnClient('azure')(s)).toBe(true);
});
});

describe('getCustomModelCardById', () => {
it('should return the custom model card with the given id and provider', () => {
const s = merge(initialSettingsState, {
Expand Down
2 changes: 1 addition & 1 deletion src/store/user/slices/settings/selectors/modelConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const isProviderFetchOnClient = (provider: GlobalLLMProviderKey | string) => (s:
const config = getProviderConfigById(provider)(s);
if (typeof config?.fetchOnClient !== 'undefined') return config?.fetchOnClient;

return isProviderEndpointNotEmpty(provider)(s);
return false;
};

const getCustomModelCard =
Expand Down

0 comments on commit 5fc90a9

Please sign in to comment.