修复渠道测试功能,修复日志页面根据渠道ID筛选功能,更新统计功能,改为自动更新
This commit is contained in:
parent
436ba6df72
commit
eb82fb79a2
@ -5,14 +5,14 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"one-api/common"
|
"one-api/common"
|
||||||
"one-api/model"
|
"one-api/model"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
"strings"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
func testChannel(channel *model.Channel, request ChatRequest) (err error, openaiErr *OpenAIError) {
|
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 {
|
} else {
|
||||||
if channel.GetBaseURL() != "" {
|
if channel.GetBaseURL() != "" {
|
||||||
requestURL = 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)
|
jsonData, err := json.Marshal(request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -94,7 +94,7 @@ func GetAllLogs(logType int, startTimestamp int64, endTimestamp int64, modelName
|
|||||||
tx = tx.Where("created_at <= ?", endTimestamp)
|
tx = tx.Where("created_at <= ?", endTimestamp)
|
||||||
}
|
}
|
||||||
if channel != 0 {
|
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
|
err = tx.Order("id desc").Limit(num).Offset(startIdx).Find(&logs).Error
|
||||||
return logs, err
|
return logs, err
|
||||||
@ -151,7 +151,7 @@ func SumUsedQuota(logType int, startTimestamp int64, endTimestamp int64, modelNa
|
|||||||
tx = tx.Where("model_name = ?", modelName)
|
tx = tx.Where("model_name = ?", modelName)
|
||||||
}
|
}
|
||||||
if channel != 0 {
|
if channel != 0 {
|
||||||
tx = tx.Where("channel = ?", channel)
|
tx = tx.Where("channel_id = ?", channel)
|
||||||
}
|
}
|
||||||
tx.Where("type = ?", LogTypeConsume).Scan("a)
|
tx.Where("type = ?", LogTypeConsume).Scan("a)
|
||||||
return quota
|
return quota
|
||||||
|
@ -95,14 +95,11 @@ const LogsTable = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleEyeClick = async () => {
|
const handleEyeClick = async () => {
|
||||||
if (!showStat) {
|
if (isAdminUser) {
|
||||||
if (isAdminUser) {
|
await getLogStat();
|
||||||
await getLogStat();
|
} else {
|
||||||
} else {
|
await getLogSelfStat();
|
||||||
await getLogSelfStat();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
setShowStat(!showStat);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const loadLogs = async (startIdx) => {
|
const loadLogs = async (startIdx) => {
|
||||||
@ -144,11 +141,12 @@ const LogsTable = () => {
|
|||||||
setLoading(true);
|
setLoading(true);
|
||||||
setActivePage(1);
|
setActivePage(1);
|
||||||
await loadLogs(0);
|
await loadLogs(0);
|
||||||
|
handleEyeClick();
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
refresh().then();
|
refresh().then();
|
||||||
}, [logType]);
|
}, [logType,username, token_name, model_name, channel]);
|
||||||
|
|
||||||
const searchLogs = async () => {
|
const searchLogs = async () => {
|
||||||
if (searchKeyword === '') {
|
if (searchKeyword === '') {
|
||||||
@ -199,35 +197,34 @@ const LogsTable = () => {
|
|||||||
<>
|
<>
|
||||||
<Segment>
|
<Segment>
|
||||||
<Header as='h3'>
|
<Header as='h3'>
|
||||||
使用明细(总消耗额度:
|
使用明细【消耗额度:
|
||||||
{showStat && renderQuota(stat.quota)}
|
{renderQuota(stat.quota)}】
|
||||||
{!showStat && <span onClick={handleEyeClick} style={{ cursor: 'pointer', color: 'gray' }}>点击查看</span>}
|
|
||||||
)
|
|
||||||
</Header>
|
</Header>
|
||||||
|
|
||||||
<Form>
|
<Form>
|
||||||
<Form.Group>
|
<Form.Group>
|
||||||
<Form.Input fluid label={'令牌名称'} width={3} value={token_name}
|
<Form.Input fluid label={'令牌名称'} width={3} value={token_name}
|
||||||
placeholder={'可选值'} name='token_name' onChange={handleInputChange} />
|
placeholder={'可选值'} name='token_name' onChange={handleInputChange} />
|
||||||
<Form.Input fluid label='模型名称' width={3} value={model_name} placeholder='可选值'
|
<Form.Input fluid label='模型名称' width={3} value={model_name} placeholder='可选值'
|
||||||
name='model_name'
|
name='model_name'
|
||||||
onChange={handleInputChange} />
|
onChange={handleInputChange} />
|
||||||
<Form.Input fluid label='起始时间' width={4} value={start_timestamp} type='datetime-local'
|
<Form.Input fluid label='起始时间' width={4} value={start_timestamp} type='datetime-local'
|
||||||
name='start_timestamp'
|
name='start_timestamp'
|
||||||
onChange={handleInputChange} />
|
onChange={handleInputChange} />
|
||||||
<Form.Input fluid label='结束时间' width={4} value={end_timestamp} type='datetime-local'
|
<Form.Input fluid label='结束时间' width={4} value={end_timestamp} type='datetime-local'
|
||||||
name='end_timestamp'
|
name='end_timestamp'
|
||||||
onChange={handleInputChange} />
|
onChange={handleInputChange} />
|
||||||
<Form.Button fluid label='操作' width={2} onClick={refresh}>查询</Form.Button>
|
<Form.Button fluid label='操作' width={2} onClick={refresh}>查询</Form.Button>
|
||||||
</Form.Group>
|
</Form.Group>
|
||||||
{
|
{
|
||||||
isAdminUser && <>
|
isAdminUser && <>
|
||||||
<Form.Group>
|
<Form.Group>
|
||||||
<Form.Input fluid label={'渠道 ID'} width={3} value={channel}
|
<Form.Input fluid label={'渠道 ID'} width={3} value={channel}
|
||||||
placeholder='可选值' name='channel'
|
placeholder='可选值' name='channel'
|
||||||
onChange={handleInputChange} />
|
onChange={handleInputChange} />
|
||||||
<Form.Input fluid label={'用户名称'} width={3} value={username}
|
<Form.Input fluid label={'用户名称'} width={3} value={username}
|
||||||
placeholder={'可选值'} name='username'
|
placeholder={'可选值'} name='username'
|
||||||
onChange={handleInputChange} />
|
onChange={handleInputChange} />
|
||||||
|
|
||||||
</Form.Group>
|
</Form.Group>
|
||||||
</>
|
</>
|
||||||
@ -321,15 +318,6 @@ const LogsTable = () => {
|
|||||||
>
|
>
|
||||||
额度
|
额度
|
||||||
</Table.HeaderCell>
|
</Table.HeaderCell>
|
||||||
{/* <Table.HeaderCell
|
|
||||||
style={{ cursor: 'pointer' }}
|
|
||||||
onClick={() => {
|
|
||||||
sortLog('content');
|
|
||||||
}}
|
|
||||||
width={isAdminUser ? 4 : 6}
|
|
||||||
>
|
|
||||||
详情
|
|
||||||
</Table.HeaderCell> */}
|
|
||||||
</Table.Row>
|
</Table.Row>
|
||||||
</Table.Header>
|
</Table.Header>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user