Merge pull request #1176 from RedwindA/feat/tagMode-channelModelList
feat: 标签聚合模式编辑渠道时复用渠道模型列表
This commit is contained in:
@@ -623,3 +623,44 @@ func BatchSetChannelTag(c *gin.Context) {
|
|||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetTagModels(c *gin.Context) {
|
||||||
|
tag := c.Query("tag")
|
||||||
|
if tag == "" {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{
|
||||||
|
"success": false,
|
||||||
|
"message": "tag不能为空",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
channels, err := model.GetChannelsByTag(tag, false) // Assuming false for idSort is fine here
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||||||
|
"success": false,
|
||||||
|
"message": err.Error(),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var longestModels string
|
||||||
|
maxLength := 0
|
||||||
|
|
||||||
|
// Find the longest models string among all channels with the given tag
|
||||||
|
for _, channel := range channels {
|
||||||
|
if channel.Models != "" {
|
||||||
|
currentModels := strings.Split(channel.Models, ",")
|
||||||
|
if len(currentModels) > maxLength {
|
||||||
|
maxLength = len(currentModels)
|
||||||
|
longestModels = channel.Models
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"success": true,
|
||||||
|
"message": "",
|
||||||
|
"data": longestModels,
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|||||||
@@ -105,6 +105,7 @@ func SetApiRouter(router *gin.Engine) {
|
|||||||
channelRoute.GET("/fetch_models/:id", controller.FetchUpstreamModels)
|
channelRoute.GET("/fetch_models/:id", controller.FetchUpstreamModels)
|
||||||
channelRoute.POST("/fetch_models", controller.FetchModels)
|
channelRoute.POST("/fetch_models", controller.FetchModels)
|
||||||
channelRoute.POST("/batch/tag", controller.BatchSetChannelTag)
|
channelRoute.POST("/batch/tag", controller.BatchSetChannelTag)
|
||||||
|
channelRoute.GET("/tag/models", controller.GetTagModels)
|
||||||
}
|
}
|
||||||
tokenRoute := apiRouter.Group("/token")
|
tokenRoute := apiRouter.Group("/token")
|
||||||
tokenRoute.Use(middleware.UserAuth())
|
tokenRoute.Use(middleware.UserAuth())
|
||||||
|
|||||||
@@ -194,6 +194,24 @@ const EditTagModal = (props) => {
|
|||||||
}, [originModelOptions, inputs.models]);
|
}, [originModelOptions, inputs.models]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
const fetchTagModels = async () => {
|
||||||
|
if (!tag) return;
|
||||||
|
setLoading(true);
|
||||||
|
try {
|
||||||
|
const res = await API.get(`/api/channel/tag/models?tag=${tag}`);
|
||||||
|
if (res?.data?.success) {
|
||||||
|
const models = res.data.data ? res.data.data.split(',') : [];
|
||||||
|
setInputs((inputs) => ({ ...inputs, models: models }));
|
||||||
|
} else {
|
||||||
|
showError(res.data.message);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
showError(error.message);
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
setInputs({
|
setInputs({
|
||||||
...originInputs,
|
...originInputs,
|
||||||
tag: tag,
|
tag: tag,
|
||||||
@@ -201,7 +219,8 @@ const EditTagModal = (props) => {
|
|||||||
});
|
});
|
||||||
fetchModels().then();
|
fetchModels().then();
|
||||||
fetchGroups().then();
|
fetchGroups().then();
|
||||||
}, [visible]);
|
fetchTagModels().then(); // Call the new function
|
||||||
|
}, [visible, tag]); // Add tag to dependency array
|
||||||
|
|
||||||
const addCustomModels = () => {
|
const addCustomModels = () => {
|
||||||
if (customModel.trim() === '') return;
|
if (customModel.trim() === '') return;
|
||||||
@@ -347,6 +366,11 @@ const EditTagModal = (props) => {
|
|||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
<div>
|
<div>
|
||||||
<Text strong className="block mb-2">{t('模型')}</Text>
|
<Text strong className="block mb-2">{t('模型')}</Text>
|
||||||
|
<Banner
|
||||||
|
type="info"
|
||||||
|
description={t('当前模型列表为该标签下所有渠道模型列表最长的一个,并非所有渠道的并集,请注意可能导致某些渠道模型丢失。')}
|
||||||
|
className="!rounded-lg mb-4"
|
||||||
|
/>
|
||||||
<Select
|
<Select
|
||||||
placeholder={t('请选择该渠道所支持的模型,留空则不更改')}
|
placeholder={t('请选择该渠道所支持的模型,留空则不更改')}
|
||||||
name='models'
|
name='models'
|
||||||
|
|||||||
Reference in New Issue
Block a user