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
088a90de
authored
Apr 19, 2023
by
archer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
perf: 过滤器
parent
a98c56f9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
4 deletions
+26
-4
src/pages/api/chat/vectorGpt.ts
+13
-2
src/pages/api/openapi/chat/vectorGpt.ts
+13
-2
No files found.
src/pages/api/chat/vectorGpt.ts
View file @
088a90de
...
...
@@ -7,7 +7,12 @@ import { ChatItemType } from '@/types/chat';
import
{
jsonRes
}
from
'@/service/response'
;
import
type
{
ModelSchema
}
from
'@/types/mongoSchema'
;
import
{
PassThrough
}
from
'stream'
;
import
{
modelList
,
ModelVectorSearchModeMap
,
ModelVectorSearchModeEnum
}
from
'@/constants/model'
;
import
{
modelList
,
ModelVectorSearchModeMap
,
ModelVectorSearchModeEnum
,
ModelDataStatusEnum
}
from
'@/constants/model'
;
import
{
pushChatBill
}
from
'@/service/events/pushBill'
;
import
{
openaiCreateEmbedding
,
gpt35StreamResponse
}
from
'@/service/utils/openai'
;
import
dayjs
from
'dayjs'
;
...
...
@@ -66,7 +71,13 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
const
similarity
=
ModelVectorSearchModeMap
[
model
.
search
.
mode
]?.
similarity
||
0.22
;
const
vectorSearch
=
await
PgClient
.
select
<
{
id
:
string
;
q
:
string
;
a
:
string
}
>
(
'modelData'
,
{
fields
:
[
'id'
,
'q'
,
'a'
],
where
:
[[
'model_id'
,
model
.
_id
],
'AND'
,
`vector <=> '[
${
promptVector
}
]' <
${
similarity
}
`
],
where
:
[
[
'status'
,
ModelDataStatusEnum
.
ready
],
'AND'
,
[
'model_id'
,
model
.
_id
],
'AND'
,
`vector <=> '[
${
promptVector
}
]' <
${
similarity
}
`
],
order
:
[{
field
:
'vector'
,
mode
:
`<=> '[
${
promptVector
}
]'`
}],
limit
:
30
});
...
...
src/pages/api/openapi/chat/vectorGpt.ts
View file @
088a90de
...
...
@@ -5,7 +5,12 @@ import { ChatCompletionRequestMessage, ChatCompletionRequestMessageRoleEnum } fr
import
{
ChatItemType
}
from
'@/types/chat'
;
import
{
jsonRes
}
from
'@/service/response'
;
import
{
PassThrough
}
from
'stream'
;
import
{
modelList
,
ModelVectorSearchModeMap
,
ModelVectorSearchModeEnum
}
from
'@/constants/model'
;
import
{
modelList
,
ModelVectorSearchModeMap
,
ModelVectorSearchModeEnum
,
ModelDataStatusEnum
}
from
'@/constants/model'
;
import
{
pushChatBill
}
from
'@/service/events/pushBill'
;
import
{
openaiCreateEmbedding
,
gpt35StreamResponse
}
from
'@/service/utils/openai'
;
import
dayjs
from
'dayjs'
;
...
...
@@ -80,7 +85,13 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
const
similarity
=
ModelVectorSearchModeMap
[
model
.
search
.
mode
]?.
similarity
||
0.22
;
const
vectorSearch
=
await
PgClient
.
select
<
{
id
:
string
;
q
:
string
;
a
:
string
}
>
(
'modelData'
,
{
fields
:
[
'id'
,
'q'
,
'a'
],
where
:
[[
'model_id'
,
model
.
_id
],
'AND'
,
`vector <=> '[
${
promptVector
}
]' <
${
similarity
}
`
],
where
:
[
[
'status'
,
ModelDataStatusEnum
.
ready
],
'AND'
,
[
'model_id'
,
model
.
_id
],
'AND'
,
`vector <=> '[
${
promptVector
}
]' <
${
similarity
}
`
],
order
:
[{
field
:
'vector'
,
mode
:
`<=> '[
${
promptVector
}
]'`
}],
limit
:
30
});
...
...
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