Skip to content

Commit 8afc235

Browse files
author
Kerwin
committed
fix: reverse proxy save lost
fix: access token error
1 parent 568f428 commit 8afc235

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

service/src/index.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -244,22 +244,22 @@ router.post('/chat', auth, async (req, res) => {
244244
await updateChat(message._id as unknown as string,
245245
response.data.text,
246246
response.data.id,
247-
response.data.detail.usage as UsageResponse,
247+
response.data.detail?.usage as UsageResponse,
248248
previousResponse)
249249
}
250250
else {
251251
await updateChat(message._id as unknown as string,
252252
response.data.text,
253253
response.data.id,
254-
response.data.detail.usage as UsageResponse)
254+
response.data.detail?.usage as UsageResponse)
255255
}
256256

257257
if (response.data.usage) {
258258
await insertChatUsage(req.headers.userId as string,
259259
roomId,
260260
message._id,
261261
response.data.id,
262-
response.data.detail.usage as UsageResponse)
262+
response.data.detail?.usage as UsageResponse)
263263
}
264264
}
265265
res.send(response)
@@ -341,22 +341,22 @@ router.post('/chat-process', [auth, limiter], async (req, res) => {
341341
await updateChat(message._id as unknown as string,
342342
result.data.text,
343343
result.data.id,
344-
result.data.detail.usage as UsageResponse,
344+
result.data.detail?.usage as UsageResponse,
345345
previousResponse)
346346
}
347347
else {
348348
await updateChat(message._id as unknown as string,
349349
result.data.text,
350350
result.data.id,
351-
result.data.detail.usage as UsageResponse)
351+
result.data.detail?.usage as UsageResponse)
352352
}
353353

354-
if (result.data.detail.usage) {
354+
if (result.data.detail?.usage) {
355355
await insertChatUsage(req.headers.userId as string,
356356
roomId,
357357
message._id,
358358
result.data.id,
359-
result.data.detail.usage as UsageResponse)
359+
result.data.detail?.usage as UsageResponse)
360360
}
361361
}
362362
catch (error) {
@@ -575,7 +575,7 @@ router.post('/verifyadmin', async (req, res) => {
575575

576576
router.post('/setting-base', rootAuth, async (req, res) => {
577577
try {
578-
const { apiKey, apiModel, apiBaseUrl, accessToken, timeoutMs, socksProxy, socksAuth, httpsProxy } = req.body as Config
578+
const { apiKey, apiModel, apiBaseUrl, accessToken, timeoutMs, reverseProxy, socksProxy, socksAuth, httpsProxy } = req.body as Config
579579

580580
if (apiKey == null && accessToken == null)
581581
throw new Error('Missing OPENAI_API_KEY or OPENAI_ACCESS_TOKEN environment variable.')
@@ -585,6 +585,7 @@ router.post('/setting-base', rootAuth, async (req, res) => {
585585
thisConfig.apiModel = apiModel
586586
thisConfig.apiBaseUrl = apiBaseUrl
587587
thisConfig.accessToken = accessToken
588+
thisConfig.reverseProxy = reverseProxy
588589
thisConfig.timeoutMs = timeoutMs
589590
thisConfig.socksProxy = socksProxy
590591
thisConfig.socksAuth = socksAuth

src/views/chat/index.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ async function onConversation() {
136136
chunk = responseText.substring(lastIndex)
137137
try {
138138
const data = JSON.parse(chunk)
139-
const usage = data.detail.usage
139+
const usage = (data.detail && data.detail.usage)
140140
? {
141141
completion_tokens: data.detail.usage.completion_tokens || null,
142142
prompt_tokens: data.detail.usage.prompt_tokens || null,
@@ -279,7 +279,7 @@ async function onRegenerate(index: number) {
279279
chunk = responseText.substring(lastIndex)
280280
try {
281281
const data = JSON.parse(chunk)
282-
const usage = data.detail.usage
282+
const usage = (data.detail && data.detail.usage)
283283
? {
284284
completion_tokens: data.detail.usage.completion_tokens || null,
285285
prompt_tokens: data.detail.usage.prompt_tokens || null,
@@ -571,7 +571,7 @@ onUnmounted(() => {
571571
:date-time="item.dateTime"
572572
:text="item.text"
573573
:inversion="item.inversion"
574-
:usage="item.usage || undefined"
574+
:usage="item && item.usage || undefined"
575575
:error="item.error"
576576
:loading="item.loading"
577577
@regenerate="onRegenerate(index)"

0 commit comments

Comments
 (0)