Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵月辉
/
fastgpt-migrated
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
Unverified
Commit
36a0ea7e
authored
Jun 12, 2023
by
archer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: sensitive check
parent
71dd7f3e
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
38 additions
and
40 deletions
+38
-40
client/src/pages/api/chat/chat.ts
+1
-1
client/src/pages/api/chat/shareChat/chat.ts
+1
-1
client/src/pages/api/openapi/chat/chat.ts
+1
-1
client/src/pages/api/openapi/text/sensitiveCheck.ts
+35
-28
client/src/service/api/text.ts
+0
-5
client/src/types/plugin.d.ts
+0
-4
No files found.
client/src/pages/api/chat/chat.ts
View file @
36a0ea7e
...
@@ -10,7 +10,7 @@ import { resStreamResponse } from '@/service/utils/chat';
...
@@ -10,7 +10,7 @@ import { resStreamResponse } from '@/service/utils/chat';
import
{
appKbSearch
}
from
'../openapi/kb/appKbSearch'
;
import
{
appKbSearch
}
from
'../openapi/kb/appKbSearch'
;
import
{
ChatRoleEnum
,
QUOTE_LEN_HEADER
,
GUIDE_PROMPT_HEADER
}
from
'@/constants/chat'
;
import
{
ChatRoleEnum
,
QUOTE_LEN_HEADER
,
GUIDE_PROMPT_HEADER
}
from
'@/constants/chat'
;
import
{
BillTypeEnum
}
from
'@/constants/user'
;
import
{
BillTypeEnum
}
from
'@/constants/user'
;
import
{
sensitiveCheck
}
from
'
@/service/api/text
'
;
import
{
sensitiveCheck
}
from
'
../openapi/text/sensitiveCheck
'
;
import
{
NEW_CHATID_HEADER
}
from
'@/constants/chat'
;
import
{
NEW_CHATID_HEADER
}
from
'@/constants/chat'
;
import
{
saveChat
}
from
'./saveChat'
;
import
{
saveChat
}
from
'./saveChat'
;
import
{
Types
}
from
'mongoose'
;
import
{
Types
}
from
'mongoose'
;
...
...
client/src/pages/api/chat/shareChat/chat.ts
View file @
36a0ea7e
...
@@ -9,7 +9,7 @@ import { pushChatBill, updateShareChatBill } from '@/service/events/pushBill';
...
@@ -9,7 +9,7 @@ import { pushChatBill, updateShareChatBill } from '@/service/events/pushBill';
import
{
resStreamResponse
}
from
'@/service/utils/chat'
;
import
{
resStreamResponse
}
from
'@/service/utils/chat'
;
import
{
ChatRoleEnum
}
from
'@/constants/chat'
;
import
{
ChatRoleEnum
}
from
'@/constants/chat'
;
import
{
BillTypeEnum
}
from
'@/constants/user'
;
import
{
BillTypeEnum
}
from
'@/constants/user'
;
import
{
sensitiveCheck
}
from
'
@/service/api/text
'
;
import
{
sensitiveCheck
}
from
'
../../openapi/text/sensitiveCheck
'
;
import
{
appKbSearch
}
from
'../../openapi/kb/appKbSearch'
;
import
{
appKbSearch
}
from
'../../openapi/kb/appKbSearch'
;
/* 发送提示词 */
/* 发送提示词 */
...
...
client/src/pages/api/openapi/chat/chat.ts
View file @
36a0ea7e
...
@@ -9,7 +9,7 @@ import { pushChatBill } from '@/service/events/pushBill';
...
@@ -9,7 +9,7 @@ import { pushChatBill } from '@/service/events/pushBill';
import
{
ChatRoleEnum
}
from
'@/constants/chat'
;
import
{
ChatRoleEnum
}
from
'@/constants/chat'
;
import
{
withNextCors
}
from
'@/service/utils/tools'
;
import
{
withNextCors
}
from
'@/service/utils/tools'
;
import
{
BillTypeEnum
}
from
'@/constants/user'
;
import
{
BillTypeEnum
}
from
'@/constants/user'
;
import
{
sensitiveCheck
}
from
'
@/service/api/text
'
;
import
{
sensitiveCheck
}
from
'
../../openapi/text/sensitiveCheck
'
;
import
{
NEW_CHATID_HEADER
}
from
'@/constants/chat'
;
import
{
NEW_CHATID_HEADER
}
from
'@/constants/chat'
;
import
{
Types
}
from
'mongoose'
;
import
{
Types
}
from
'mongoose'
;
import
{
appKbSearch
}
from
'../kb/appKbSearch'
;
import
{
appKbSearch
}
from
'../kb/appKbSearch'
;
...
...
client/src/pages/api/openapi/text/sensitiveCheck.ts
View file @
36a0ea7e
...
@@ -2,43 +2,23 @@
...
@@ -2,43 +2,23 @@
import
type
{
NextApiRequest
,
NextApiResponse
}
from
'next'
;
import
type
{
NextApiRequest
,
NextApiResponse
}
from
'next'
;
import
{
jsonRes
}
from
'@/service/response'
;
import
{
jsonRes
}
from
'@/service/response'
;
import
{
authUser
,
getSystemOpenAiKey
}
from
'@/service/utils/auth'
;
import
{
authUser
,
getSystemOpenAiKey
}
from
'@/service/utils/auth'
;
import
type
{
TextPluginRequestParams
}
from
'@/types/plugin'
;
import
axios
from
'axios'
;
import
axios
from
'axios'
;
import
{
axiosConfig
}
from
'@/service/utils/tools'
;
import
{
axiosConfig
}
from
'@/service/utils/tools'
;
export
type
Props
=
{
input
:
string
;
};
export
default
async
function
handler
(
req
:
NextApiRequest
,
res
:
NextApiResponse
)
{
export
default
async
function
handler
(
req
:
NextApiRequest
,
res
:
NextApiResponse
)
{
try
{
try
{
if
(
!
global
.
systemEnv
.
sensitiveCheck
)
{
return
jsonRes
(
res
);
}
await
authUser
({
req
});
await
authUser
({
req
});
const
{
input
}
=
req
.
body
as
TextPluginRequestParams
;
const
result
=
await
sensitiveCheck
(
req
.
body
)
;
const
response
=
await
axios
({
jsonRes
(
res
,
{
...
axiosConfig
(
getSystemOpenAiKey
(
'chat'
)),
data
:
result
,
method
:
'POST'
,
message
:
result
url
:
`/moderations`
,
data
:
{
input
}
});
});
const
data
=
(
response
.
data
.
results
?.[
0
]?.
category_scores
as
Record
<
string
,
number
>
)
||
{};
const
values
=
Object
.
values
(
data
);
for
(
const
val
of
values
)
{
if
(
val
>
0.2
)
{
return
jsonRes
(
res
,
{
code
:
500
,
message
:
'您的内容不合规'
});
}
}
jsonRes
(
res
);
}
catch
(
err
)
{
}
catch
(
err
)
{
jsonRes
(
res
,
{
jsonRes
(
res
,
{
code
:
500
,
code
:
500
,
...
@@ -46,3 +26,30 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
...
@@ -46,3 +26,30 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
});
});
}
}
}
}
export
async
function
sensitiveCheck
({
input
}:
Props
)
{
if
(
!
global
.
systemEnv
.
sensitiveCheck
)
{
return
Promise
.
resolve
(
''
);
}
const
response
=
await
axios
({
...
axiosConfig
(
getSystemOpenAiKey
(
'chat'
)),
method
:
'POST'
,
url
:
`/moderations`
,
data
:
{
input
}
});
const
data
=
(
response
.
data
.
results
?.[
0
]?.
category_scores
as
Record
<
string
,
number
>
)
||
{};
const
values
=
Object
.
values
(
data
);
for
(
const
val
of
values
)
{
if
(
val
>
0.2
)
{
return
Promise
.
reject
(
'您的内容不合规'
);
}
}
return
''
;
}
client/src/service/api/text.ts
deleted
100644 → 0
View file @
71dd7f3e
import
{
POST
}
from
'./request'
;
import
type
{
TextPluginRequestParams
}
from
'@/types/plugin'
;
export
const
sensitiveCheck
=
(
data
:
TextPluginRequestParams
)
=>
POST
(
'/openapi/text/sensitiveCheck'
,
data
);
client/src/types/plugin.d.ts
View file @
36a0ea7e
...
@@ -19,7 +19,3 @@ export type KbTestItemType = {
...
@@ -19,7 +19,3 @@ export type KbTestItemType = {
time
:
Date
;
time
:
Date
;
results
:
(
KbDataItemType
&
{
score
:
number
})[];
results
:
(
KbDataItemType
&
{
score
:
number
})[];
};
};
export
type
TextPluginRequestParams
=
{
input
:
string
;
};
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