Skip to content

Commit b5708ec

Browse files
authored
Merge pull request #1176 from RedwindA/feat/tagMode-channelModelList
feat: 标签聚合模式编辑渠道时复用渠道模型列表
2 parents 97a8219 + b47274b commit b5708ec

File tree

3 files changed

+67
-1
lines changed

3 files changed

+67
-1
lines changed

controller/channel.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,3 +623,44 @@ func BatchSetChannelTag(c *gin.Context) {
623623
})
624624
return
625625
}
626+
627+
func GetTagModels(c *gin.Context) {
628+
tag := c.Query("tag")
629+
if tag == "" {
630+
c.JSON(http.StatusBadRequest, gin.H{
631+
"success": false,
632+
"message": "tag不能为空",
633+
})
634+
return
635+
}
636+
637+
channels, err := model.GetChannelsByTag(tag, false) // Assuming false for idSort is fine here
638+
if err != nil {
639+
c.JSON(http.StatusInternalServerError, gin.H{
640+
"success": false,
641+
"message": err.Error(),
642+
})
643+
return
644+
}
645+
646+
var longestModels string
647+
maxLength := 0
648+
649+
// Find the longest models string among all channels with the given tag
650+
for _, channel := range channels {
651+
if channel.Models != "" {
652+
currentModels := strings.Split(channel.Models, ",")
653+
if len(currentModels) > maxLength {
654+
maxLength = len(currentModels)
655+
longestModels = channel.Models
656+
}
657+
}
658+
}
659+
660+
c.JSON(http.StatusOK, gin.H{
661+
"success": true,
662+
"message": "",
663+
"data": longestModels,
664+
})
665+
return
666+
}

router/api-router.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ func SetApiRouter(router *gin.Engine) {
105105
channelRoute.GET("/fetch_models/:id", controller.FetchUpstreamModels)
106106
channelRoute.POST("/fetch_models", controller.FetchModels)
107107
channelRoute.POST("/batch/tag", controller.BatchSetChannelTag)
108+
channelRoute.GET("/tag/models", controller.GetTagModels)
108109
}
109110
tokenRoute := apiRouter.Group("/token")
110111
tokenRoute.Use(middleware.UserAuth())

web/src/pages/Channel/EditTagModal.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,33 @@ const EditTagModal = (props) => {
194194
}, [originModelOptions, inputs.models]);
195195

196196
useEffect(() => {
197+
const fetchTagModels = async () => {
198+
if (!tag) return;
199+
setLoading(true);
200+
try {
201+
const res = await API.get(`/api/channel/tag/models?tag=${tag}`);
202+
if (res?.data?.success) {
203+
const models = res.data.data ? res.data.data.split(',') : [];
204+
setInputs((inputs) => ({ ...inputs, models: models }));
205+
} else {
206+
showError(res.data.message);
207+
}
208+
} catch (error) {
209+
showError(error.message);
210+
} finally {
211+
setLoading(false);
212+
}
213+
};
214+
197215
setInputs({
198216
...originInputs,
199217
tag: tag,
200218
new_tag: tag,
201219
});
202220
fetchModels().then();
203221
fetchGroups().then();
204-
}, [visible]);
222+
fetchTagModels().then(); // Call the new function
223+
}, [visible, tag]); // Add tag to dependency array
205224

206225
const addCustomModels = () => {
207226
if (customModel.trim() === '') return;
@@ -347,6 +366,11 @@ const EditTagModal = (props) => {
347366
<div className="space-y-4">
348367
<div>
349368
<Text strong className="block mb-2">{t('模型')}</Text>
369+
<Banner
370+
type="info"
371+
description={t('当前模型列表为该标签下所有渠道模型列表最长的一个,并非所有渠道的并集,请注意可能导致某些渠道模型丢失。')}
372+
className="!rounded-lg mb-4"
373+
/>
350374
<Select
351375
placeholder={t('请选择该渠道所支持的模型,留空则不更改')}
352376
name='models'

0 commit comments

Comments
 (0)