forked from ChatGPTNextWeb/NextChat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: close ChatGPTNextWeb#3187 use CUSTOM_MODELS to control model list
- Loading branch information
1 parent
3b9dd3e
commit 6f05da2
Showing
11 changed files
with
112 additions
and
42 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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,16 @@ | ||
import { useMemo } from "react"; | ||
import { useAccessStore, useAppConfig } from "../store"; | ||
import { collectModels } from "./model"; | ||
|
||
export function useAllModels() { | ||
const accessStore = useAccessStore(); | ||
const configStore = useAppConfig(); | ||
const models = useMemo(() => { | ||
return collectModels( | ||
configStore.models, | ||
[accessStore.customModels, configStore.customModels].join(","), | ||
); | ||
}, [accessStore.customModels, configStore.customModels, configStore.models]); | ||
|
||
return models; | ||
} |
This file contains 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,40 @@ | ||
import { LLMModel } from "../client/api"; | ||
|
||
export function collectModelTable( | ||
models: readonly LLMModel[], | ||
customModels: string, | ||
) { | ||
const modelTable: Record<string, boolean> = {}; | ||
|
||
// default models | ||
models.forEach((m) => (modelTable[m.name] = m.available)); | ||
|
||
// server custom models | ||
customModels | ||
.split(",") | ||
.filter((v) => !!v && v.length > 0) | ||
.map((m) => { | ||
if (m.startsWith("+")) { | ||
modelTable[m.slice(1)] = true; | ||
} else if (m.startsWith("-")) { | ||
modelTable[m.slice(1)] = false; | ||
} else modelTable[m] = true; | ||
}); | ||
return modelTable; | ||
} | ||
|
||
/** | ||
* Generate full model table. | ||
*/ | ||
export function collectModels( | ||
models: readonly LLMModel[], | ||
customModels: string, | ||
) { | ||
const modelTable = collectModelTable(models, customModels); | ||
const allModels = Object.keys(modelTable).map((m) => ({ | ||
name: m, | ||
available: modelTable[m], | ||
})); | ||
|
||
return allModels; | ||
} |