diff --git a/controller/channel-test.go b/controller/channel-test.go index 0504b36e..6d05e1d1 100644 --- a/controller/channel-test.go +++ b/controller/channel-test.go @@ -5,14 +5,14 @@ import ( "encoding/json" "errors" "fmt" - "github.com/gin-gonic/gin" "net/http" "one-api/common" "one-api/model" "strconv" - "strings" "sync" "time" + "strings" + "github.com/gin-gonic/gin" ) func testChannel(channel *model.Channel, request ChatRequest) (err error, openaiErr *OpenAIError) { @@ -47,11 +47,12 @@ func testChannel(channel *model.Channel, request ChatRequest) (err error, openai } else { if channel.GetBaseURL() != "" { requestURL = channel.GetBaseURL() + if !strings.HasPrefix(requestURL, "https://gateway.ai.cloudflare.com") { + requestURL += "/v1" + } } - requestURL += "/v1/chat/completions" + requestURL += "/chat/completions" } - // for Cloudflare AI gateway: https://github.com/songquanpeng/one-api/pull/639 - requestURL = strings.Replace(requestURL, "/v1/v1", "/v1", 1) jsonData, err := json.Marshal(request) if err != nil { diff --git a/model/log.go b/model/log.go index d26da9a2..3d3ffae3 100644 --- a/model/log.go +++ b/model/log.go @@ -94,7 +94,7 @@ func GetAllLogs(logType int, startTimestamp int64, endTimestamp int64, modelName tx = tx.Where("created_at <= ?", endTimestamp) } if channel != 0 { - tx = tx.Where("channel = ?", channel) + tx = tx.Where("channel_id = ?", channel) } err = tx.Order("id desc").Limit(num).Offset(startIdx).Find(&logs).Error return logs, err @@ -151,7 +151,7 @@ func SumUsedQuota(logType int, startTimestamp int64, endTimestamp int64, modelNa tx = tx.Where("model_name = ?", modelName) } if channel != 0 { - tx = tx.Where("channel = ?", channel) + tx = tx.Where("channel_id = ?", channel) } tx.Where("type = ?", LogTypeConsume).Scan("a) return quota diff --git a/web/src/components/LogsTable.js b/web/src/components/LogsTable.js index 6e560072..b785851b 100644 --- a/web/src/components/LogsTable.js +++ b/web/src/components/LogsTable.js @@ -95,14 +95,11 @@ const LogsTable = () => { }; const handleEyeClick = async () => { - if (!showStat) { - if (isAdminUser) { - await getLogStat(); - } else { - await getLogSelfStat(); - } + if (isAdminUser) { + await getLogStat(); + } else { + await getLogSelfStat(); } - setShowStat(!showStat); }; const loadLogs = async (startIdx) => { @@ -144,11 +141,12 @@ const LogsTable = () => { setLoading(true); setActivePage(1); await loadLogs(0); + handleEyeClick(); }; useEffect(() => { refresh().then(); - }, [logType]); + }, [logType,username, token_name, model_name, channel]); const searchLogs = async () => { if (searchKeyword === '') { @@ -199,35 +197,34 @@ const LogsTable = () => { <>
- 使用明细(总消耗额度: - {showStat && renderQuota(stat.quota)} - {!showStat && 点击查看} - ) + 使用明细【消耗额度: + {renderQuota(stat.quota)}】
+
+ placeholder={'可选值'} name='token_name' onChange={handleInputChange} /> + name='model_name' + onChange={handleInputChange} /> + name='start_timestamp' + onChange={handleInputChange} /> + name='end_timestamp' + onChange={handleInputChange} /> 查询 { isAdminUser && <> + placeholder='可选值' name='channel' + onChange={handleInputChange} /> + placeholder={'可选值'} name='username' + onChange={handleInputChange} /> @@ -321,15 +318,6 @@ const LogsTable = () => { > 额度 - {/* { - sortLog('content'); - }} - width={isAdminUser ? 4 : 6} - > - 详情 - */}