Skip to content

Commit c549ef3

Browse files
author
Kerwin
committed
Merge remote-tracking branch 'github/main'
# Conflicts: # README.en.md # README.md # package.json # service/pnpm-lock.yaml # service/src/chatgpt/index.ts # src/components/common/Setting/About.vue # src/locales/en-US.ts # src/locales/zh-CN.ts # src/locales/zh-TW.ts
2 parents 8549c15 + 1187d88 commit c549ef3

File tree

12 files changed

+89
-22
lines changed

12 files changed

+89
-22
lines changed

CHANGELOG.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,33 @@
1+
## v2.10.9
2+
3+
`2023-04-03`
4+
5+
> 更新默认 `accessToken` 反代地址为 [[acheong08](https://github.com/acheong08)]`https://bypass.churchless.tech/api/conversation`
6+
7+
## Enhancement
8+
- 添加 `socks5` 代理认证 [[yimiaoxiehou](https://github.com/Chanzhaoyu/chatgpt-web/pull/999)]
9+
- 添加 `socks` 代理用户名密码的配置 [[hank-cp](https://github.com/Chanzhaoyu/chatgpt-web/pull/890)]
10+
- 添加可选日志打印 [[zcong1993](https://github.com/Chanzhaoyu/chatgpt-web/pull/1041)]
11+
- 更新侧边栏按钮本地化[[simonwu53](https://github.com/Chanzhaoyu/chatgpt-web/pull/911)]
12+
- 优化代码块滚动条高度 [[Fog3211](https://github.com/Chanzhaoyu/chatgpt-web/pull/1153)]
13+
## BugFix
14+
- 修复 `PWA` 问题 [[bingo235](https://github.com/Chanzhaoyu/chatgpt-web/pull/807)]
15+
- 修复 `ESM` 错误 [[kidonng](https://github.com/Chanzhaoyu/chatgpt-web/pull/826)]
16+
- 修复反向代理开启时限流失效的问题 [[gitgitgogogo](https://github.com/Chanzhaoyu/chatgpt-web/pull/863)]
17+
- 修复 `docker` 构建时 `.env` 可能被忽略的问题 [[zaiMoe](https://github.com/Chanzhaoyu/chatgpt-web/pull/877)]
18+
- 修复导出异常错误 [[KingTwinkle](https://github.com/Chanzhaoyu/chatgpt-web/pull/938)]
19+
- 修复空值异常 [[vchenpeng](https://github.com/Chanzhaoyu/chatgpt-web/pull/1103)]
20+
- 移动端上的体验问题
21+
22+
## Other
23+
- `Docker` 容器名字名义 [[LOVECHEN](https://github.com/Chanzhaoyu/chatgpt-web/pull/1035)]
24+
- `kubernetes` 部署配置 [[CaoYunzhou](https://github.com/Chanzhaoyu/chatgpt-web/pull/1001)]
25+
- 感谢 [[assassinliujie](https://github.com/Chanzhaoyu/chatgpt-web/pull/962)][[puppywang](https://github.com/Chanzhaoyu/chatgpt-web/pull/1017)] 的某些贡献
26+
- 更新 `kubernetes/deploy.yaml` [[idawnwon](https://github.com/Chanzhaoyu/chatgpt-web/pull/1085)]
27+
- 文档更新 [[#yi-ge](https://github.com/Chanzhaoyu/chatgpt-web/pull/883)]
28+
- 文档更新 [[weifeng12x](https://github.com/Chanzhaoyu/chatgpt-web/pull/880)]
29+
- 依赖更新
30+
131
## v2.10.8
232

333
`2023-03-23`

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@
5656
| `ChatGPTUnofficialProxyAPI(网页 accessToken)` || 相对不可靠 | 聪明 |
5757

5858
对比:
59-
1. `ChatGPTAPI` 使用 `gpt-3.5-turbo-0301` 通过官方`OpenAI`补全`API`模拟`ChatGPT`(最稳健的方法,但它不是免费的,并且没有使用针对聊天进行微调的模型)
60-
2. `ChatGPTUnofficialProxyAPI` 使用非官方代理服务器访问 `ChatGPT` 的后端`API`,绕过`Cloudflare`使用真实的的`ChatGPT`,非常轻量级,但依赖于第三方服务器,并且有速率限制)
59+
1. `ChatGPTAPI` 使用 `gpt-3.5-turbo` 通过 `OpenAI` 官方 `API` 调用 `ChatGPT`
60+
2. `ChatGPTUnofficialProxyAPI` 使用非官方代理服务器访问 `ChatGPT` 的后端`API`,绕过`Cloudflare`依赖于第三方服务器,并且有速率限制)
6161

6262
警告:
6363
1. 你应该首先使用 `API` 方式

kubernetes/deploy.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ spec:
3030
- name: OPENAI_API_MODEL
3131
value: gpt-3.5-turbo
3232
- name: API_REVERSE_PROXY
33-
value: https://bypass.duti.tech/api/conversation
33+
value: https://bypass.churchless.tech/api/conversation
3434
- name: AUTH_SECRET_KEY
3535
value: '123456'
3636
- name: TIMEOUT_MS

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "chatgpt-web",
3-
"version": "2.11.1",
3+
"version": "2.11.7",
44
"private": false,
55
"description": "ChatGPT Web",
66
"author": "ChenZhaoYu <chenzhaoyu1994@gmail.com>",

service/.env.example

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ OPENAI_API_MODEL=
1313
# set `true` to disable OpenAI API debug log
1414
OPENAI_API_DISABLE_DEBUG=
1515

16-
# Reverse Proxy
16+
# Reverse Proxy - Available on accessToken
17+
# Default: https://bypass.churchless.tech/api/conversation
18+
# More: https://github.com/transitive-bullshit/chatgpt-api#reverse-proxy
1719
API_REVERSE_PROXY=
1820

1921
# timeout

service/src/chatgpt/index.ts

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ import { ChatGPTAPI, ChatGPTUnofficialProxyAPI } from 'chatgpt'
55
import { SocksProxyAgent } from 'socks-proxy-agent'
66
import httpsProxyAgent from 'https-proxy-agent'
77
import fetch from 'node-fetch'
8-
import axios from 'axios'
98
import { getCacheConfig, getOriginConfig } from '../storage/config'
109
import { sendResponse } from '../utils'
1110
import { isNotEmptyString } from '../utils/is'
1211
import type { ApiModel, ChatContext, ChatGPTUnofficialProxyAPIOptions, ModelConfig } from '../types'
13-
import type { RequestOptions } from './types'
12+
import type { BalanceResponse, RequestOptions } from './types'
1413

1514
const { HttpsProxyAgent } = httpsProxyAgent
1615

@@ -72,11 +71,15 @@ export async function initApi() {
7271
accessToken: config.accessToken,
7372
debug: !config.apiDisableDebug,
7473
}
74+
7575
if (isNotEmptyString(OPENAI_API_MODEL))
7676
options.model = OPENAI_API_MODEL
7777

78-
if (isNotEmptyString(config.reverseProxy))
79-
options.apiReverseProxyUrl = config.reverseProxy
78+
if (isNotEmptyString(config.reverseProxy)) {
79+
options.apiReverseProxyUrl = isNotEmptyString(config.reverseProxy)
80+
? config.reverseProxy
81+
: 'https://bypass.churchless.tech/api/conversation'
82+
}
8083

8184
await setupProxy(options)
8285

@@ -122,6 +125,7 @@ async function chatReplyProcess(options: RequestOptions) {
122125
}
123126

124127
async function fetchBalance() {
128+
// 计算起始日期和结束日期
125129
const config = await getCacheConfig()
126130
const OPENAI_API_KEY = config.apiKey
127131
const OPENAI_API_BASE_URL = config.apiBaseUrl
@@ -133,17 +137,38 @@ async function fetchBalance() {
133137
? OPENAI_API_BASE_URL
134138
: 'https://api.openai.com'
135139

140+
const [startDate, endDate] = formatDate()
141+
142+
// 每月使用量
143+
const urlUsage = `${API_BASE_URL}/v1/dashboard/billing/usage?start_date=${startDate}&end_date=${endDate}`
144+
145+
const headers = {
146+
'Authorization': `Bearer ${OPENAI_API_KEY}`,
147+
'Content-Type': 'application/json',
148+
}
149+
136150
try {
137-
const headers = { 'Content-Type': 'application/json', 'Authorization': `Bearer ${OPENAI_API_KEY}` }
138-
const response = await axios.get(`${API_BASE_URL}/dashboard/billing/credit_grants`, { headers })
139-
const balance = response.data.total_available ?? 0
140-
return Promise.resolve(balance.toFixed(3))
151+
// 获取已使用量
152+
const useResponse = await fetch(urlUsage, { headers })
153+
const usageData = await useResponse.json() as BalanceResponse
154+
const usage = Math.round(usageData.total_usage) / 100
155+
return Promise.resolve(usage ? `$${usage}` : '-')
141156
}
142157
catch {
143158
return Promise.resolve('-')
144159
}
145160
}
146161

162+
function formatDate(): string[] {
163+
const today = new Date()
164+
const year = today.getFullYear()
165+
const month = today.getMonth() + 1
166+
const lastDay = new Date(year, month, 0)
167+
const formattedFirstDay = `${year}-${month.toString().padStart(2, '0')}-01`
168+
const formattedLastDay = `${year}-${month.toString().padStart(2, '0')}-${lastDay.getDate().toString().padStart(2, '0')}`
169+
return [formattedFirstDay, formattedLastDay]
170+
}
171+
147172
async function chatConfig() {
148173
const config = await getOriginConfig() as ModelConfig
149174
config.balance = await fetchBalance()

service/src/chatgpt/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@ export interface RequestOptions {
66
process?: (chat: ChatMessage) => void
77
systemMessage?: string
88
}
9+
10+
export interface BalanceResponse {
11+
total_usage: number
12+
}

src/locales/en-US.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export default {
3636
},
3737
chat: {
3838
newChatButton: 'New Chat',
39-
placeholder: 'Ask me anything...(Shift + Enter = line break)',
39+
placeholder: 'Ask me anything...(Shift + Enter = line break, "/" to trigger prompts)',
4040
placeholderMobile: 'Ask me anything...',
4141
copy: 'Copy',
4242
copied: 'Copied',
@@ -94,6 +94,7 @@ export default {
9494
loginEnabled: 'Login Enabled',
9595
loginSalt: 'Login Salt',
9696
loginSaltTip: 'Changes will invalidate all logged in',
97+
monthlyUsage: 'Monthly Usage',
9798
},
9899
store: {
99100
siderButton: 'Prompt Store',

src/locales/zh-CN.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export default {
3636
},
3737
chat: {
3838
newChatButton: '新建聊天',
39-
placeholder: '来说点什么吧...(Shift + Enter = 换行)',
39+
placeholder: '来说点什么吧...(Shift + Enter = 换行,"/" 触发提示词)',
4040
placeholderMobile: '来说点什么...',
4141
copy: '复制',
4242
copied: '复制成功',
@@ -94,6 +94,7 @@ export default {
9494
loginEnabled: '注册登录',
9595
loginSalt: '登录混淆盐',
9696
loginSaltTip: '变更会导致所有已登录失效',
97+
monthlyUsage: '本月使用量',
9798
},
9899
store: {
99100
siderButton: '提示词商店',

src/locales/zh-TW.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export default {
3636
},
3737
chat: {
3838
newChatButton: '新建對話',
39-
placeholder: '來說點什麼...(Shift + Enter = 換行)',
39+
placeholder: '來說點什麼...(Shift + Enter = 換行,"/" 觸發提示詞)',
4040
placeholderMobile: '來說點什麼...',
4141
copy: '複製',
4242
copied: '複製成功',
@@ -94,6 +94,7 @@ export default {
9494
loginEnabled: '注册登录',
9595
loginSalt: '登录混淆盐',
9696
loginSaltTip: '变更会导致所有已登录失效',
97+
monthlyUsage: '本月使用量',
9798
},
9899
store: {
99100
siderButton: '提示詞商店',

src/styles/lib/highlight.less

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,10 @@ html {
123123
}
124124

125125
code.hljs {
126-
padding: 3px 5px
126+
padding: 3px 5px;
127+
&::-webkit-scrollbar {
128+
height: 4px;
129+
}
127130
}
128131

129132
.hljs {

src/views/chat/index.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ async function onConversation() {
140140
dataSources.value.length - 1,
141141
{
142142
dateTime: new Date().toLocaleString(),
143-
text: lastText + data.text ?? '',
143+
text: lastText + (data.text ?? ''),
144144
inversion: false,
145145
error: false,
146146
loading: true,
@@ -245,7 +245,7 @@ async function onRegenerate(index: number) {
245245
error: false,
246246
loading: true,
247247
conversationOptions: null,
248-
requestOptions: { prompt: message, ...options },
248+
requestOptions: { prompt: message, options: { ...options } },
249249
},
250250
)
251251
@@ -274,12 +274,12 @@ async function onRegenerate(index: number) {
274274
index,
275275
{
276276
dateTime: new Date().toLocaleString(),
277-
text: lastText + data.text ?? '',
277+
text: lastText + (data.text ?? ''),
278278
inversion: false,
279279
error: false,
280280
loading: true,
281281
conversationOptions: { conversationId: data.conversationId, parentMessageId: data.id },
282-
requestOptions: { prompt: message, ...options },
282+
requestOptions: { prompt: message, options: { ...options } },
283283
},
284284
)
285285
@@ -323,7 +323,7 @@ async function onRegenerate(index: number) {
323323
error: true,
324324
loading: false,
325325
conversationOptions: null,
326-
requestOptions: { prompt: message, ...options },
326+
requestOptions: { prompt: message, options: { ...options } },
327327
},
328328
)
329329
}

0 commit comments

Comments
 (0)