mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-20 14:41:05 +08:00
Go: add balance command (#14262)
### What problem does this PR solve? ``` RAGFlow(user)> list supported models from 'moonshot' 'test'; +---------------------------------+ | model_name | +---------------------------------+ | moonshot-v1-32k-vision-preview | | kimi-k2.6 | | moonshot-v1-8k | | moonshot-v1-auto | | moonshot-v1-128k | | moonshot-v1-32k | | kimi-k2.5 | | moonshot-v1-8k-vision-preview | | moonshot-v1-128k-vision-preview | +---------------------------------+ RAGFlow(user)> show balance from 'moonshot' 'test'; +---------+----------+ | balance | currency | +---------+----------+ | 0 | CNY | +---------+----------+ ``` ### Type of change - [x] New Feature (non-breaking change which adds functionality) --------- Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
@@ -355,6 +355,44 @@ func (h *ProviderHandler) ShowProviderInstance(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
func (h *ProviderHandler) ShowInstanceBalance(c *gin.Context) {
|
||||
providerName := c.Param("provider_name")
|
||||
if providerName == "" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"code": 400,
|
||||
"message": "Provider name is required",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
instanceName := c.Param("instance_name")
|
||||
if instanceName == "" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"code": 400,
|
||||
"message": "Instance name is required",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
userID := c.GetString("user_id")
|
||||
|
||||
// Get tenant ID from user
|
||||
balance, errorCode, err := h.modelProviderService.ShowInstanceBalance(providerName, instanceName, userID)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": errorCode,
|
||||
"message": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 0,
|
||||
"message": "success",
|
||||
"data": balance,
|
||||
})
|
||||
}
|
||||
|
||||
type AlterProviderInstanceRequest struct {
|
||||
LLMName string `json:"llm_name" binding:"required"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user