Skip to content

Commit

Permalink
Merge pull request #13 from ilyydy/wework
Browse files Browse the repository at this point in the history
支持企业微信
  • Loading branch information
ilyydy authored Apr 5, 2023
2 parents e8ff6c6 + 0d53e30 commit db7d8d5
Show file tree
Hide file tree
Showing 34 changed files with 2,376 additions and 1,550 deletions.
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
# [0.1.0](https://github.com/ilyydy/cf-openai/compare/v0.0.2...v0.1.0) (2023-04-04)


### Bug Fixes

* 查询用量的时间问题 ([1dd152f](https://github.com/ilyydy/cf-openai/commit/1dd152ff321dcc7a342dc6d488a1bc09259b3010))


### Features

* openai session key ([f63e408](https://github.com/ilyydy/cf-openai/commit/f63e4087023ca02e8c5969f5f013a961ed41a08d))
* userId mask 处理 ([79cc400](https://github.com/ilyydy/cf-openai/commit/79cc400307db8896d71cec3d6c7175e42cd0d756))
* 企业微信接入 ([0766a49](https://github.com/ilyydy/cf-openai/commit/0766a49cf92db54cb5c3c665578ee391859e6534))
* 利用微信重试3次每次5秒机制,增长程序处理时间,减少用户手动重试 ([d3ae8e5](https://github.com/ilyydy/cf-openai/commit/d3ae8e5dc86dd43ee546d6683c506cbad5dcd501))
* 增加两个快速重试命令 ([95780b4](https://github.com/ilyydy/cf-openai/commit/95780b4ffe10c0b4dfdf22ce8a3a946117d9bb02))
* 增加全局配置 ADMIN_AUTH_TOKEN 和命令 /adminAuth,方便设置不同平台的管理员 ([002195e](https://github.com/ilyydy/cf-openai/commit/002195ed8f58ac0b710af8a389325ce9c56793cc))
* 增加配置 OPEN_AI_API_KEY_OCCUPYING_DURATION,对 openai 的 key 进行限流 ([8ba6c6b](https://github.com/ilyydy/cf-openai/commit/8ba6c6bcf7ce4cc8af4f3c10a059d3700b5ebacc))
* 请求上下文增加 startTime ([9df8c22](https://github.com/ilyydy/cf-openai/commit/9df8c228d14951308e17008f9b3db305a6dc4b92))
* 迁移 [#12](https://github.com/ilyydy/cf-openai/issues/12),增长提问/回答的保存时间配置化,默认 3 分钟 ([b767222](https://github.com/ilyydy/cf-openai/commit/b767222ac7d6e788abe266c48940b7c042cdda4c))



## [0.0.2](https://github.com/ilyydy/cf-openai/compare/v0.0.1...v0.0.2) (2023-03-29)


Expand Down
113 changes: 77 additions & 36 deletions README.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cf-openai",
"version": "0.0.2",
"version": "0.1.0",
"devDependencies": {
"@cloudflare/workers-types": "^4.20230307.0",
"@commitlint/cli": "^17.5.0",
Expand Down
33 changes: 31 additions & 2 deletions src/controller/openai/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
import type { OpenAiConfig } from '../../types'

export const commandName = {
help: '/help',
bindKey: '/bindKey',
unbindKey: '/unbindKey',
testKey: '/testKey',
setChatType: '/setChatType',
newChat: '/newChat',
retry: '/retry',
retryLastMessage: '..',
retryLastMessage2: '。。',
usage: '/usage',
bindSessionKey: '/bindSessionKey',
unbindSessionKey: '/unbindSessionKey',
freeUsage: '/freeUsage',
version: '/version',
setEnv: '/setEnv',
system: '/system',
faq: '/faq',
adminAuth: '/adminAuth',
// TODO 发消息给开发者
}

export const CONFIG: OpenAiConfig = {
// OpenAI 的模型名称
CHAT_MODEL: 'gpt-3.5-turbo',
Expand All @@ -8,7 +30,10 @@ export const CONFIG: OpenAiConfig = {
// OpenAI API key 长度范围
OPEN_AI_API_KEY_MAX_LEN: 51,
OPEN_AI_API_KEY_MIN_LEN: 51,
OPEN_AI_API_KEY_OCCUPYING_DURATION: 6,
// 游客的默认 openai key
GUEST_KEY: '',
// admin 用户的默认 openai key
ADMIN_KEY: '',
// OpenAI 的用量地址
OPEN_AI_USAGE: 'https://api.openai.com/dashboard/billing/usage',
// OpenAI 的免费用量地址
Expand All @@ -17,14 +42,18 @@ export const CONFIG: OpenAiConfig = {
OPEN_AI_API_EXTRA_PARAMS: {},
// OpenAI API 请求超时,毫秒
OPEN_AI_API_TIMEOUT_MS: 30000,
// OpenAI API key 使用间隔,单位秒,用于限流
OPEN_AI_API_KEY_OCCUPYING_DURATION: 0,
// 单次请求 OpenAI 最大 token 数
MAX_CHAT_TOKEN_NUM: 4000,
// OpenAI 回复的最小 token 数
MIN_CHAT_RESPONSE_TOKEN_NUM: 500,
// 串聊最大历史记录长度
MAX_HISTORY_LENGTH: 20,
// 消息的保存时长,分钟
// 提问/回答的保存时长,分钟
ANSWER_EXPIRES_MINUTES: 3,
// 全局默认初始化消息,不能使用 Date.now() 获取当前时间,实际会为 0,cloudflare 的限制
SYSTEM_INIT_MESSAGE: `You are ChatGPT, a large language model trained by OpenAI. Answer as concisely as possible. Knowledge cutoff: 2021-09-01. Current is 2023`,
// 用户关注应用时发出的欢迎信息
WELCOME_MESSAGE: `欢迎使用,可输入 ${commandName.help} 查看当前可用命令`,
}
Loading

0 comments on commit db7d8d5

Please sign in to comment.