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
5876a47d
authored
Jan 09, 2024
by
Archer
Committed by
GitHub
Jan 09, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update rearanker code url. Add chat storage ip address (#717)
* save chat origin ip * reranker code url
parent
13eda404
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
23 additions
and
27 deletions
+23
-27
docSite/content/docs/development/custom-models/reranker.md
+1
-1
packages/global/core/chat/type.d.ts
+1
-0
packages/service/core/chat/chatSchema.ts
+0
-20
projects/app/src/pages/api/v1/chat/completions.ts
+7
-2
projects/app/src/service/utils/chat/saveChat.ts
+14
-4
No files found.
docSite/content/docs/development/custom-models/reranker.md
View file @
5876a47d
...
@@ -28,7 +28,7 @@ weight: 910
...
@@ -28,7 +28,7 @@ weight: 910
### 源码部署
### 源码部署
1.
根据上面的环境配置配置好环境,具体教程自行 GPT;
1.
根据上面的环境配置配置好环境,具体教程自行 GPT;
2.
下载
[
python 文件
](
app.py
)
2.
下载
[
python 文件
](
https://github.com/labring/FastGPT/tree/main/python/reranker/bge-reranker-base
)
3.
在命令行输入命令
`pip install -r requirments.txt`
;
3.
在命令行输入命令
`pip install -r requirments.txt`
;
4.
按照
[
https://huggingface.co/BAAI/bge-reranker-base
](
https://huggingface.co/BAAI/bge-reranker-base
)
下载模型仓库到app.py同级目录
4.
按照
[
https://huggingface.co/BAAI/bge-reranker-base
](
https://huggingface.co/BAAI/bge-reranker-base
)
下载模型仓库到app.py同级目录
5.
添加环境变量
`export ACCESS_TOKEN=XXXXXX`
配置 token,这里的 token 只是加一层验证,防止接口被人盗用,默认值为
`ACCESS_TOKEN`
;
5.
添加环境变量
`export ACCESS_TOKEN=XXXXXX`
配置 token,这里的 token 只是加一层验证,防止接口被人盗用,默认值为
`ACCESS_TOKEN`
;
...
...
packages/global/core/chat/type.d.ts
View file @
5876a47d
...
@@ -22,6 +22,7 @@ export type ChatSchema = {
...
@@ -22,6 +22,7 @@ export type ChatSchema = {
shareId
?:
string
;
shareId
?:
string
;
outLinkUid
?:
string
;
outLinkUid
?:
string
;
content
:
ChatItemType
[];
content
:
ChatItemType
[];
metadata
?:
Record
<
string
,
any
>
;
};
};
export
type
ChatWithAppSchema
=
Omit
<
ChatSchema
,
'appId'
>
&
{
export
type
ChatWithAppSchema
=
Omit
<
ChatSchema
,
'appId'
>
&
{
...
...
packages/service/core/chat/chatSchema.ts
View file @
5876a47d
...
@@ -69,26 +69,6 @@ const ChatSchema = new Schema({
...
@@ -69,26 +69,6 @@ const ChatSchema = new Schema({
//For special storage
//For special storage
type
:
Object
,
type
:
Object
,
default
:
{}
default
:
{}
},
content
:
{
type
:
[
{
obj
:
{
type
:
String
,
required
:
true
,
enum
:
Object
.
keys
(
ChatRoleMap
)
},
value
:
{
type
:
String
,
default
:
''
},
[
ModuleOutputKeyEnum
.
responseData
]:
{
type
:
Array
,
default
:
[]
}
}
],
default
:
[]
}
}
});
});
...
...
projects/app/src/pages/api/v1/chat/completions.ts
View file @
5876a47d
...
@@ -69,6 +69,8 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex
...
@@ -69,6 +69,8 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex
}
=
req
.
body
as
Props
;
}
=
req
.
body
as
Props
;
try
{
try
{
const
originIp
=
requestIp
.
getClientIp
(
req
);
await
connectToDatabase
();
await
connectToDatabase
();
// body data check
// body data check
if
(
!
messages
)
{
if
(
!
messages
)
{
...
@@ -99,7 +101,7 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex
...
@@ -99,7 +101,7 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex
if
(
shareId
&&
outLinkUid
)
{
if
(
shareId
&&
outLinkUid
)
{
const
{
user
,
appId
,
authType
,
responseDetail
,
uid
}
=
await
authOutLinkChatStart
({
const
{
user
,
appId
,
authType
,
responseDetail
,
uid
}
=
await
authOutLinkChatStart
({
shareId
,
shareId
,
ip
:
requestIp
.
getClientIp
(
req
)
,
ip
:
originIp
,
outLinkUid
,
outLinkUid
,
question
:
question
.
value
question
:
question
.
value
});
});
...
@@ -245,7 +247,10 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex
...
@@ -245,7 +247,10 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex
value
:
answerText
,
value
:
answerText
,
responseData
responseData
}
}
]
],
metadata
:
{
originIp
}
});
});
}
}
...
...
projects/app/src/service/utils/chat/saveChat.ts
View file @
5876a47d
...
@@ -17,6 +17,7 @@ type Props = {
...
@@ -17,6 +17,7 @@ type Props = {
shareId
?:
string
;
shareId
?:
string
;
outLinkUid
?:
string
;
outLinkUid
?:
string
;
content
:
[
ChatItemType
,
ChatItemType
];
content
:
[
ChatItemType
,
ChatItemType
];
metadata
?:
Record
<
string
,
any
>
;
};
};
export
async
function
saveChat
({
export
async
function
saveChat
({
...
@@ -29,7 +30,8 @@ export async function saveChat({
...
@@ -29,7 +30,8 @@ export async function saveChat({
source
,
source
,
shareId
,
shareId
,
outLinkUid
,
outLinkUid
,
content
content
,
metadata
=
{}
}:
Props
)
{
}:
Props
)
{
try
{
try
{
const
chat
=
await
MongoChat
.
findOne
(
const
chat
=
await
MongoChat
.
findOne
(
...
@@ -39,9 +41,14 @@ export async function saveChat({
...
@@ -39,9 +41,14 @@ export async function saveChat({
tmbId
,
tmbId
,
appId
appId
},
},
'_id'
'_id
metadata
'
);
);
const
metadataUpdate
=
{
...
chat
?.
metadata
,
...
metadata
};
const
promise
:
any
[]
=
[
const
promise
:
any
[]
=
[
MongoChatItem
.
insertMany
(
MongoChatItem
.
insertMany
(
content
.
map
((
item
)
=>
({
content
.
map
((
item
)
=>
({
...
@@ -53,6 +60,7 @@ export async function saveChat({
...
@@ -53,6 +60,7 @@ export async function saveChat({
}))
}))
)
)
];
];
console
.
log
(
metadataUpdate
);
const
title
=
const
title
=
chatContentReplaceBlock
(
content
[
0
].
value
).
slice
(
0
,
20
)
||
chatContentReplaceBlock
(
content
[
0
].
value
).
slice
(
0
,
20
)
||
...
@@ -65,7 +73,8 @@ export async function saveChat({
...
@@ -65,7 +73,8 @@ export async function saveChat({
{
chatId
},
{
chatId
},
{
{
title
,
title
,
updateTime
:
new
Date
()
updateTime
:
new
Date
(),
metadata
:
metadataUpdate
}
}
)
)
);
);
...
@@ -80,7 +89,8 @@ export async function saveChat({
...
@@ -80,7 +89,8 @@ export async function saveChat({
title
,
title
,
source
,
source
,
shareId
,
shareId
,
outLinkUid
outLinkUid
,
metadata
:
metadataUpdate
})
})
);
);
}
}
...
...
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