Skip to content

Commit

Permalink
👷 build: support to ignore \n with XXX_MODEL_LIST env (lobehub#4660)
Browse files Browse the repository at this point in the history
* chore: 解析自定义模型时兼容模型名称为空的情况

* chore: supplementary single test code
  • Loading branch information
coulsontl authored Nov 12, 2024
1 parent 780a2a9 commit 6af7b52
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/utils/__snapshots__/parseModels.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,23 @@ exports[`parseModelString > duplicate naming model 1`] = `
}
`;

exports[`parseModelString > empty string model 1`] = `
{
"add": [
{
"displayName": "gpt-4-turbo",
"id": "gpt-4-1106-preview",
},
{
"displayName": undefined,
"id": "claude-2",
},
],
"removeAll": false,
"removed": [],
}
`;

exports[`parseModelString > only add the model 1`] = `
{
"add": [
Expand Down
5 changes: 5 additions & 0 deletions src/utils/parseModels.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ describe('parseModelString', () => {
expect(result).toMatchSnapshot();
});

it('empty string model', () => {
const result = parseModelString('gpt-4-1106-preview=gpt-4-turbo,, ,\n ,+claude-2');
expect(result).toMatchSnapshot();
});

describe('extension capabilities', () => {
it('with token', () => {
const result = parseModelString('chatglm-6b=ChatGLM 6B<4096>');
Expand Down
5 changes: 5 additions & 0 deletions src/utils/parseModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ export const parseModelString = (modelString: string = '', withDeploymentName =
continue;
}

// remove empty model name
if (!item.trim().length) {
continue;
}

// Remove duplicate model entries.
const existingIndex = models.findIndex(({ id: n }) => n === id);
if (existingIndex !== -1) {
Expand Down

0 comments on commit 6af7b52

Please sign in to comment.