8000 🐛 fix: fix some ai provider known issues (#5361) · lobehub/lobe-chat@b2775b5 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit b2775b5

Browse files
authored
🐛 fix: fix some ai provider known issues (#5361)
* fix provider url * improve fetch model list issue * fix builtin model sort and displayName * fix user enabled models * fix model name * fix mo 10000 del displayName name
1 parent 4a49bc7 commit b2775b5

File tree

4 files changed

+26
-53
lines changed

4 files changed

+26
-53
lines changed

src/app/(main)/discover/(detail)/provider/[slug]/features/ProviderConfig.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { memo } from 'react';
1010
import { useTranslation } from 'react-i18next';
1111
import { FlexboxProps } from 'react-layout-kit';
1212

13+
import { isServerMode } from '@/const/version';
1314
import { DiscoverProviderItem } from '@/types/discover';
1415

1516
const useStyles = createStyles(({ css }) => ({
@@ -25,13 +26,13 @@ interface ProviderConfigProps extends FlexboxProps {
2526
identifier: string;
2627
}
2728

28-
const ProviderConfig = memo<ProviderConfigProps>(({ data }) => {
29+
const ProviderConfig = memo<ProviderConfigProps>(({ data, identifier }) => {
2930
const { styles } = useStyles();
3031
const { t } = useTranslation('discover');
3132

3233
const router = useRouter();
3334
const openSettings = () => {
34-
router.push('/settings/llm');
35+
router.push(!isServerMode ? '/settings/llm' : `/settings/provider/${identifier}`);
3536
};
3637

3738
const icon = <Icon icon={SquareArrowOutUpRight} size={{ fontSize: 16 }} />;

src/database/repositories/aiInfra/index.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,16 @@ export class AiInfraRepos {
8181
.map<EnabledAiModel & { enabled?: boolean | null }>((item) => {
8282
const user = allModels.find((m) => m.id === item.id && m.providerId === provider.id);
8383

84-
const enabled = !!user ? user.enabled : item.enabled;
85-
8684
return {
87-
...item,
88-
abilities: item.abilities || {},
89-
enabled,
85+
abilities: !!user ? user.abilities : item.abilities || {},
86+
config: !!user ? user.config : item.config,
87+
contextWindowTokens: !!user ? user.contextWindowTokens : item.contextWindowTokens,
88+
displayName: user?.displayName || item.displayName,
89+
enabled: !!user ? user.enabled : item.enabled,
90+
id: item.id,
9091
providerId: provider.id,
92+
sort: !!user ? user.sort : undefined,
93+
type: item.type,
9194
};
9295
})
9396
.filter((i) => i.enabled);

src/database/server/models/__tests__/aiModel.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ describe('AiModelModel', () => {
248248

249249
const allModels = await aiProviderModel.query();
250250
expect(allModels).toHaveLength(2);
251-
expect(allModels.find((m) => m.id === 'existing-model')?.displayName).toBe('Updated Name');
251+
expect(allModels.find((m) => m.id === 'existing-model')?.displayName).toBe('Old Name');
252252
expect(allModels.find((m) => m.id === 'new-model')?.displayName).toBe('New Model');
253253
});
254254
});

src/database/server/models/aiModel.ts

Lines changed: 14 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { and, asc, desc, eq, inArray } from 'drizzle-orm/expressions';
2-
import pMap from 'p-map';
32

43
import { LobeChatDatabase } from '@/database/type';
54
import {
@@ -131,51 +130,21 @@ export class AiModelModel {
131130
};
132131

133132
batchUpdateAiModels = async (providerId: string, models: AiProviderModelListItem[]) => {
134-
return this.db.transaction(async (trx) => {
135-
const records = models.map(({ id, ...model }) => ({
136-
...model,
137-
id,
138-
providerId,
139-
updatedAt: new Date(),
140-
userId: this.userId,
141-
}));
133+
const records = models.map(({ id, ...model }) => ({
134+
...model,
135+
id,
136+
providerId,
137+
updatedAt: new Date(),
138+
userId: this.userId,
139+
}));
142140

143-
// 第一步:尝试插入所有记录,忽略冲突
144-
const insertedRecords = await trx
145-
.insert(aiModels)
146-
.values(records)
147-
.onConflictDoNothing({
148-
target: [aiModels.id, aiModels.userId, aiModels.providerId],
149-
})
150-
.returning();
151-
// 第二步:找出需要更新的记录(即插入时发生冲突的记录)
152-
// 找出未能插入的记录(需要更新的记录)
153-
const insertedIds = new Set(insertedRecords.map((r) => r.id));
154-
const recordsToUpdate = records.filter((r) => !insertedIds.has(r.id));
155-
156-
// 第三步:更新已存在的记录
157-
if (recordsToUpdate.length > 0) {
158-
await pMap(
159-
recordsToUpdate,
160-
async (record) => {
161-
await trx
162-
.update(aiModels)
163-
.set({
164-
...record,
165-
updatedAt: new Date(),
166-
})
167-
.where(
168-
and(
169-
eq(aiModels.id, record.id),
170-
eq(aiModels.userId, this.userId),
171-
eq(aiModels.providerId, providerId),
172-
),
173-
);
174-
},
175-
{ concurrency: 10 }, // 限制并发数为 10
176-
);
177-
}
178-
});
141+
return this.db
142+
.insert(aiModels)
143+
.values(records)
144+
.onConflictDoNothing({
145+
target: [aiModels.id, aiModels.userId, aiModels.providerId],
146+
})
147+
.returning();
179148
};
180149

181150
batchToggleAiModels = async (providerId: string, models: string[], enabled: boolean) => {

0 commit comments

Comments
 (0)
0