Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

聊天历史由 MongoDB 中获取 #113

Merged
merged 1 commit into from
May 8, 2023

Conversation

zhujunsan
Copy link
Contributor

@zhujunsan zhujunsan commented May 7, 2023

重启服务后上下文在提问中得以保存

同时关掉 api 依赖库中的缓存以减少长时间使用后的内存占用


可能带来的问题是上下文条数很多时多次读取 MongoDB 数据库,会加大数据库压力和增大延迟,可以做的优化是做一层小缓存


只试过 API 走 GPT 3.5,accessToken 方式需要测试

同时关掉 api 依赖库中的缓存
@@ -45,6 +46,8 @@ export async function initApi() {
apiKey: config.apiKey,
completionParams: { model },
debug: !config.apiDisableDebug,
messageStore: undefined,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

关闭默认的 LRU 缓存

@@ -45,6 +46,8 @@ export async function initApi() {
apiKey: config.apiKey,
completionParams: { model },
debug: !config.apiDisableDebug,
messageStore: undefined,
getMessageById,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

覆写获取信息方法

@Kerwin1202
Copy link
Member

试了下 很不错,accessToken 应该是官网自带维护的,只需要对应的对话等id,

但是有 2 个小问题,目前会重复1次,以及 另外 我数了下 现在只能回溯前面20条消息(x2=40 重复了1次),这个数字能否控制更改

image

image

@zhujunsan
Copy link
Contributor Author

zhujunsan commented May 8, 2023

1 重复一次是因为一次是取completion,一次是取prompt,所以我说做一层小缓存是可以在取completion的时候缓存下,再往上取prompt的时候可以不走MongoDB,但要考虑自动失效什么的也挺烦先就没搞了

2 往上追溯多少这个是上游api决定的,这里控制,他往上追溯到上下文大于 model总token数 - 最大completion token数的时候就不加了,默认model 4000,最大completion 1000,所以下一条上下文加上时超过3000token的时候就不加了

@Kerwin1202 Kerwin1202 merged commit 5b70413 into chatgpt-web-dev:main May 8, 2023
2 checks passed
@zhujunsan zhujunsan deleted the messageHistoryInMongy branch May 8, 2023 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants