Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
89298bde
authored
Nov 15, 2023
by
Calcium-Ion
Committed by
GitHub
Nov 15, 2023
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5 from luxlzz6/main
令牌搜索适配MySQL,MJ日志增加图生文 图生图
parents
e25da168
d721ea1d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
28 deletions
+51
-28
model/token.go
+1
-1
web/src/components/MjLogsTable.js
+50
-27
No files found.
model/token.go
View file @
89298bde
...
@@ -33,7 +33,7 @@ func SearchUserTokens(userId int, keyword string, token string) (tokens []*Token
...
@@ -33,7 +33,7 @@ func SearchUserTokens(userId int, keyword string, token string) (tokens []*Token
if
token
!=
""
{
if
token
!=
""
{
token
=
strings
.
Trim
(
token
,
"sk-"
)
token
=
strings
.
Trim
(
token
,
"sk-"
)
}
}
err
=
DB
.
Where
(
"user_id = ?"
,
userId
)
.
Where
(
"name LIKE ?"
,
keyword
+
"%"
)
.
Where
(
"
key
LIKE ?"
,
token
+
"%"
)
.
Find
(
&
tokens
)
.
Error
err
=
DB
.
Where
(
"user_id = ?"
,
userId
)
.
Where
(
"name LIKE ?"
,
keyword
+
"%"
)
.
Where
(
"
`key`
LIKE ?"
,
token
+
"%"
)
.
Find
(
&
tokens
)
.
Error
return
tokens
,
err
return
tokens
,
err
}
}
...
...
web/src/components/MjLogsTable.js
View file @
89298bde
import
React
,
{
useEffect
,
useState
}
from
'react'
;
import
React
,
{
useEffect
,
useState
}
from
'react'
;
import
{
Button
,
Form
,
Header
,
Label
,
Pagination
,
Segment
,
Select
,
Table
}
from
'semantic-ui-react'
;
import
{
Button
,
Form
,
Header
,
Label
,
Pagination
,
Segment
,
Select
,
Table
,
Modal
}
from
'semantic-ui-react'
;
import
{
API
,
isAdmin
,
showError
,
timestamp2string
}
from
'../helpers'
;
import
{
API
,
isAdmin
,
showError
,
timestamp2string
}
from
'../helpers'
;
import
{
ITEMS_PER_PAGE
}
from
'../constants'
;
import
{
ITEMS_PER_PAGE
}
from
'../constants'
;
...
@@ -85,6 +85,8 @@ const LogsTable = () => {
...
@@ -85,6 +85,8 @@ const LogsTable = () => {
const
[
searching
,
setSearching
]
=
useState
(
false
);
const
[
searching
,
setSearching
]
=
useState
(
false
);
const
[
logType
,
setLogType
]
=
useState
(
0
);
const
[
logType
,
setLogType
]
=
useState
(
0
);
const
isAdminUser
=
isAdmin
();
const
isAdminUser
=
isAdmin
();
let
now
=
new
Date
();
let
now
=
new
Date
();
const
[
inputs
,
setInputs
]
=
useState
({
const
[
inputs
,
setInputs
]
=
useState
({
username
:
''
,
username
:
''
,
...
@@ -100,33 +102,14 @@ const LogsTable = () => {
...
@@ -100,33 +102,14 @@ const LogsTable = () => {
token
:
0
token
:
0
});
});
const
handleInputChange
=
(
e
,
{
name
,
value
})
=>
{
const
[
modalContent
,
setModalContent
]
=
useState
(
''
);
setInputs
((
inputs
)
=>
({
...
inputs
,
[
name
]:
value
}));
const
[
showModal
,
setShowModal
]
=
useState
(
false
);
};
const
getLogSelfStat
=
async
()
=>
{
const
showFullContent
=
(
content
)
=>
{
let
localStartTimestamp
=
Date
.
parse
(
start_timestamp
)
/
1000
;
setModalContent
(
content
);
let
localEndTimestamp
=
Date
.
parse
(
end_timestamp
)
/
1000
;
setShowModal
(
true
);
let
res
=
await
API
.
get
(
`/api/log/self/stat?type=
${
logType
}
&token_name=
${
token_name
}
&model_name=
${
model_name
}
&start_timestamp=
${
localStartTimestamp
}
&end_timestamp=
${
localEndTimestamp
}
`
);
const
{
success
,
message
,
data
}
=
res
.
data
;
if
(
success
)
{
setStat
(
data
);
}
else
{
showError
(
message
);
}
};
};
const
getLogStat
=
async
()
=>
{
let
localStartTimestamp
=
Date
.
parse
(
start_timestamp
)
/
1000
;
let
localEndTimestamp
=
Date
.
parse
(
end_timestamp
)
/
1000
;
let
res
=
await
API
.
get
(
`/api/log/stat?type=
${
logType
}
&username=
${
username
}
&token_name=
${
token_name
}
&model_name=
${
model_name
}
&start_timestamp=
${
localStartTimestamp
}
&end_timestamp=
${
localEndTimestamp
}
`
);
const
{
success
,
message
,
data
}
=
res
.
data
;
if
(
success
)
{
setStat
(
data
);
}
else
{
showError
(
message
);
}
};
const
loadLogs
=
async
(
startIdx
)
=>
{
const
loadLogs
=
async
(
startIdx
)
=>
{
let
url
=
''
;
let
url
=
''
;
...
@@ -304,6 +287,15 @@ const LogsTable = () => {
...
@@ -304,6 +287,15 @@ const LogsTable = () => {
<
Table
.
HeaderCell
<
Table
.
HeaderCell
style
=
{{
cursor
:
'pointer'
}}
style
=
{{
cursor
:
'pointer'
}}
onClick
=
{()
=>
{
onClick
=
{()
=>
{
sortLog
(
'prompt_en'
);
}}
width
=
{
3
}
>
PromptEn
<
/Table.HeaderCell
>
<
Table
.
HeaderCell
style
=
{{
cursor
:
'pointer'
}}
onClick
=
{()
=>
{
sortLog
(
'fail_reason'
);
sortLog
(
'fail_reason'
);
}}
}}
width
=
{
1
}
width
=
{
1
}
...
@@ -342,8 +334,33 @@ const LogsTable = () => {
...
@@ -342,8 +334,33 @@ const LogsTable = () => {
)
:
'暂未生成图片'
)
:
'暂未生成图片'
}
}
<
/Table.Cell
>
<
/Table.Cell
>
<
Table
.
Cell
>
{
log
.
prompt
}
<
/Table.Cell
>
<
Table
.
Cell
>
<
Table
.
Cell
>
{
log
.
fail_reason
?
log
.
fail_reason
:
'无'
}
<
/Table.Cell
>
{
log
.
prompt
.
length
>
10
?
<
div
>
{
log
.
prompt
.
slice
(
0
,
10
)}
<
a
style
=
{{
cursor
:
"pointer"
}}
onClick
=
{()
=>
showFullContent
(
log
.
prompt
)}
>
查看全部
<
/a
>
<
/div
>
:
log
.
prompt
}
<
/Table.Cell
>
<
Table
.
Cell
>
{
log
.
prompt_en
.
length
>
10
?
<
div
>
{
log
.
prompt_en
.
slice
(
0
,
10
)}
<
a
style
=
{{
cursor
:
"pointer"
}}
onClick
=
{()
=>
showFullContent
(
log
.
prompt_en
)}
>
查看全部
<
/a
>
<
/div
>
:
log
.
prompt_en
}
<
/Table.Cell
>
<
Table
.
Cell
>
{
log
.
fail_reason
&&
log
.
fail_reason
.
length
>
10
?
<
div
>
{
log
.
fail_reason
.
slice
(
0
,
10
)}
<
a
style
=
{{
cursor
:
"pointer"
}}
onClick
=
{()
=>
showFullContent
(
log
.
fail_reason
)}
>
查看全部
<
/a
>
<
/div
>
:
log
.
fail_reason
||
'无'
}
<
/Table.Cell
>
<
/Table.Row
>
<
/Table.Row
>
);
);
})}
})}
...
@@ -379,6 +396,12 @@ const LogsTable = () => {
...
@@ -379,6 +396,12 @@ const LogsTable = () => {
<
/Table.Footer
>
<
/Table.Footer
>
<
/Table
>
<
/Table
>
<
/Segment
>
<
/Segment
>
{
/*Modal component goes here*/
}
<
Modal
open
=
{
showModal
}
onClose
=
{()
=>
setShowModal
(
false
)}
centered
>
<
Modal
.
Content
>
<
pre
style
=
{{
whiteSpace
:
"pre-wrap"
}}
>
{
modalContent
}
<
/pre
>
<
/Modal.Content
>
<
/Modal
>
<
/
>
<
/
>
);
);
};
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment