ngoctuanai commited on
Commit
eba489e
1 Parent(s): 2b9e507

Upload 135 files

Browse files
package-lock.json CHANGED
@@ -1,12 +1,12 @@
1
  {
2
  "name": "chatgpt-web",
3
- "version": "2.10.9",
4
  "lockfileVersion": 2,
5
  "requires": true,
6
  "packages": {
7
  "": {
8
  "name": "chatgpt-web",
9
- "version": "2.10.9",
10
  "dependencies": {
11
  "@traptitech/markdown-it-katex": "^3.6.0",
12
  "@vueuse/core": "^9.13.0",
 
1
  {
2
  "name": "chatgpt-web",
3
+ "version": "2.11.1",
4
  "lockfileVersion": 2,
5
  "requires": true,
6
  "packages": {
7
  "": {
8
  "name": "chatgpt-web",
9
+ "version": "2.11.1",
10
  "dependencies": {
11
  "@traptitech/markdown-it-katex": "^3.6.0",
12
  "@vueuse/core": "^9.13.0",
service/src/chatgpt/index.ts CHANGED
@@ -62,22 +62,11 @@ let api: ChatGPTAPI | ChatGPTUnofficialProxyAPI
62
  options.maxModelTokens = 32768
63
  options.maxResponseTokens = 8192
64
  }
65
- // if use GPT-4 Turbo
66
- else if (model.toLowerCase().includes('1106-preview')) {
67
- options.maxModelTokens = 128000
68
- options.maxResponseTokens = 4096
69
- }
70
  else {
71
  options.maxModelTokens = 8192
72
  options.maxResponseTokens = 2048
73
  }
74
  }
75
- else if (model.toLowerCase().includes('gpt-3.5')) {
76
- if (model.toLowerCase().includes('16k')) {
77
- options.maxModelTokens = 16384
78
- options.maxResponseTokens = 4096
79
- }
80
- }
81
 
82
  if (isNotEmptyString(OPENAI_API_BASE_URL))
83
  options.apiBaseUrl = `${OPENAI_API_BASE_URL}/v1`
@@ -88,6 +77,7 @@ let api: ChatGPTAPI | ChatGPTUnofficialProxyAPI
88
  apiModel = 'ChatGPTAPI'
89
  }
90
  else {
 
91
  const options: ChatGPTUnofficialProxyAPIOptions = {
92
  accessToken: process.env.OPENAI_ACCESS_TOKEN,
93
  apiReverseProxyUrl: isNotEmptyString(process.env.API_REVERSE_PROXY) ? process.env.API_REVERSE_PROXY : 'https://ai.fakeopen.com/api/conversation',
@@ -139,9 +129,15 @@ async function chatReplyProcess(options: RequestOptions) {
139
  }
140
 
141
  async function fetchUsage() {
142
- const OPENAI_API_KEY = process.env.OPENAI_API_KEY
143
  const OPENAI_API_BASE_URL = process.env.OPENAI_API_BASE_URL
144
 
 
 
 
 
 
 
145
  if (!isNotEmptyString(OPENAI_API_KEY))
146
  return Promise.resolve('-')
147
 
@@ -235,4 +231,4 @@ function currentModel(): ApiModel {
235
 
236
  export type { ChatContext, ChatMessage }
237
 
238
- export { chatReplyProcess, chatConfig, currentModel }
 
62
  options.maxModelTokens = 32768
63
  options.maxResponseTokens = 8192
64
  }
 
 
 
 
 
65
  else {
66
  options.maxModelTokens = 8192
67
  options.maxResponseTokens = 2048
68
  }
69
  }
 
 
 
 
 
 
70
 
71
  if (isNotEmptyString(OPENAI_API_BASE_URL))
72
  options.apiBaseUrl = `${OPENAI_API_BASE_URL}/v1`
 
77
  apiModel = 'ChatGPTAPI'
78
  }
79
  else {
80
+ console.log('OPENAI_ACCESS_TOKEN',OPENAI_ACCESS_TOKEN);
81
  const options: ChatGPTUnofficialProxyAPIOptions = {
82
  accessToken: process.env.OPENAI_ACCESS_TOKEN,
83
  apiReverseProxyUrl: isNotEmptyString(process.env.API_REVERSE_PROXY) ? process.env.API_REVERSE_PROXY : 'https://ai.fakeopen.com/api/conversation',
 
129
  }
130
 
131
  async function fetchUsage() {
132
+ let OPENAI_API_KEY = process.env.OPENAI_API_KEY
133
  const OPENAI_API_BASE_URL = process.env.OPENAI_API_BASE_URL
134
 
135
+ if (isNotEmptyString(process.env.OPENAI_API_KEY_ARR)){
136
+ const OPENAI_API_KEY_ARR = JSON.parse(process.env.OPENAI_API_KEY_ARR);
137
+ const randomIndex = Math.floor(Math.random() * OPENAI_API_KEY_ARR.length);
138
+ OPENAI_API_KEY = OPENAI_API_KEY_ARR[randomIndex];
139
+ }
140
+
141
  if (!isNotEmptyString(OPENAI_API_KEY))
142
  return Promise.resolve('-')
143
 
 
231
 
232
  export type { ChatContext, ChatMessage }
233
 
234
+ export { chatReplyProcess, chatConfig, currentModel }
src/hooks/useLanguage.ts CHANGED
@@ -1,5 +1,5 @@
1
  import { computed } from 'vue'
2
- import { viVN, enUS } from 'naive-ui'
3
  import { useAppStore } from '@/store'
4
  import { setLocale } from '@/locales'
5
 
@@ -7,18 +7,16 @@ export function useLanguage() {
7
  const appStore = useAppStore()
8
 
9
  const language = computed(() => {
 
10
  switch (appStore.language) {
11
- case 'vi-VN':
12
- setLocale('vi-VN')
13
- return viVN
14
  case 'en-US':
15
- setLocale('en-US')
16
  return enUS
 
 
17
  default:
18
- setLocale('en-US')
19
  return enUS
20
  }
21
  })
22
 
23
  return { language }
24
- }
 
1
  import { computed } from 'vue'
2
+ import { enUS, viVN } from 'naive-ui'
3
  import { useAppStore } from '@/store'
4
  import { setLocale } from '@/locales'
5
 
 
7
  const appStore = useAppStore()
8
 
9
  const language = computed(() => {
10
+ setLocale(appStore.language)
11
  switch (appStore.language) {
 
 
 
12
  case 'en-US':
 
13
  return enUS
14
+ case 'vi-VN':
15
+ return viVN
16
  default:
 
17
  return enUS
18
  }
19
  })
20
 
21
  return { language }
22
+ }
src/locales/vi-VN.ts CHANGED
@@ -30,11 +30,13 @@ export default {
30
  },
31
  chat: {
32
  newChatButton: 'Cuộc trò truyện mới',
 
33
  placeholder: 'Hỏi tôi bất cứ điều gì...(Shift + Enter = ngắt dòng, "/" để kích hoạt lời nhắc)',
34
  placeholderMobile: 'Hỏi tôi điều gì đó...',
35
  copy: 'Sao chép',
36
  copied: 'Đã sao chép',
37
  copyCode: 'Sao chép mã',
 
38
  clearChat: 'Xóa Chat',
39
  clearChatConfirm: 'Bạn có chắc chắn muốn xóa chat này?',
40
  exportImage: 'Xuất Ảnh',
 
30
  },
31
  chat: {
32
  newChatButton: 'Cuộc trò truyện mới',
33
+ newChatTitle: 'Hội thoại mới',
34
  placeholder: 'Hỏi tôi bất cứ điều gì...(Shift + Enter = ngắt dòng, "/" để kích hoạt lời nhắc)',
35
  placeholderMobile: 'Hỏi tôi điều gì đó...',
36
  copy: 'Sao chép',
37
  copied: 'Đã sao chép',
38
  copyCode: 'Sao chép mã',
39
+ copyFailed: 'Sao chép thất bại',
40
  clearChat: 'Xóa Chat',
41
  clearChatConfirm: 'Bạn có chắc chắn muốn xóa chat này?',
42
  exportImage: 'Xuất Ảnh',
src/store/modules/app/helper.ts CHANGED
@@ -6,6 +6,13 @@ export type Theme = 'light' | 'dark' | 'auto'
6
 
7
  export type Language = 'en-US' | 'vi-VN'
8
 
 
 
 
 
 
 
 
9
  export interface AppState {
10
  siderCollapsed: boolean
11
  theme: Theme
@@ -13,7 +20,8 @@ export interface AppState {
13
  }
14
 
15
  export function defaultSetting(): AppState {
16
- return { siderCollapsed: false, theme: 'light', language: 'en-US' }
 
17
  }
18
 
19
  export function getLocalSetting(): AppState {
 
6
 
7
  export type Language = 'en-US' | 'vi-VN'
8
 
9
+ const languageMap: { [key: string]: Language } = {
10
+ 'en': 'en-US',
11
+ 'en-US': 'en-US',
12
+ 'vi': 'vi-VN',
13
+ 'vi-VN': 'vi-VN',
14
+ }
15
+
16
  export interface AppState {
17
  siderCollapsed: boolean
18
  theme: Theme
 
20
  }
21
 
22
  export function defaultSetting(): AppState {
23
+ const language = languageMap[navigator.language]
24
+ return { siderCollapsed: false, theme: 'light', language }
25
  }
26
 
27
  export function getLocalSetting(): AppState {
src/store/modules/chat/helper.ts CHANGED
@@ -1,4 +1,5 @@
1
  import { ss } from '@/utils/storage'
 
2
 
3
  const LOCAL_NAME = 'chatStorage'
4
 
@@ -7,7 +8,7 @@ export function defaultState(): Chat.ChatState {
7
  return {
8
  active: uuid,
9
  usingContext: true,
10
- history: [{ uuid, title: 'New Chat', isEdit: false }],
11
  chat: [{ uuid, data: [] }],
12
  }
13
  }
 
1
  import { ss } from '@/utils/storage'
2
+ import { t } from '@/locales'
3
 
4
  const LOCAL_NAME = 'chatStorage'
5
 
 
8
  return {
9
  active: uuid,
10
  usingContext: true,
11
+ history: [{ uuid, title: t('chat.newChatTitle'), isEdit: false }],
12
  chat: [{ uuid, data: [] }],
13
  }
14
  }
src/store/modules/chat/index.ts CHANGED
@@ -1,6 +1,7 @@
1
  import { defineStore } from 'pinia'
2
  import { defaultState, getLocalState, setLocalState } from './helper'
3
  import { router } from '@/router'
 
4
 
5
  export const useChatStore = defineStore('chat-store', {
6
  state: (): Chat.ChatState => getLocalState(),
@@ -103,7 +104,7 @@ export const useChatStore = defineStore('chat-store', {
103
  }
104
  else {
105
  this.chat[0].data.push(chat)
106
- if (this.history[0].title === 'New Chat')
107
  this.history[0].title = chat.text
108
  this.recordState()
109
  }
@@ -112,7 +113,7 @@ export const useChatStore = defineStore('chat-store', {
112
  const index = this.chat.findIndex(item => item.uuid === uuid)
113
  if (index !== -1) {
114
  this.chat[index].data.push(chat)
115
- if (this.history[index].title === 'New Chat')
116
  this.history[index].title = chat.text
117
  this.recordState()
118
  }
 
1
  import { defineStore } from 'pinia'
2
  import { defaultState, getLocalState, setLocalState } from './helper'
3
  import { router } from '@/router'
4
+ import { t } from '@/locales'
5
 
6
  export const useChatStore = defineStore('chat-store', {
7
  state: (): Chat.ChatState => getLocalState(),
 
104
  }
105
  else {
106
  this.chat[0].data.push(chat)
107
+ if (this.history[0].title === t('chat.newChatTitle'))
108
  this.history[0].title = chat.text
109
  this.recordState()
110
  }
 
113
  const index = this.chat.findIndex(item => item.uuid === uuid)
114
  if (index !== -1) {
115
  this.chat[index].data.push(chat)
116
+ if (this.history[index].title === t('chat.newChatTitle'))
117
  this.history[index].title = chat.text
118
  this.recordState()
119
  }
src/views/chat/components/Message/Text.vue CHANGED
@@ -70,9 +70,9 @@ function addCopyEvents() {
70
  const code = btn.parentElement?.nextElementSibling?.textContent
71
  if (code) {
72
  copyToClip(code).then(() => {
73
- btn.textContent = '复制成功'
74
  setTimeout(() => {
75
- btn.textContent = '复制代码'
76
  }, 1000)
77
  })
78
  }
 
70
  const code = btn.parentElement?.nextElementSibling?.textContent
71
  if (code) {
72
  copyToClip(code).then(() => {
73
+ btn.textContent = t('chat.copied')
74
  setTimeout(() => {
75
+ btn.textContent = t('chat.copyCode')
76
  }, 1000)
77
  })
78
  }
src/views/chat/components/Message/index.vue CHANGED
@@ -84,10 +84,10 @@ function handleRegenerate() {
84
  async function handleCopy() {
85
  try {
86
  await copyToClip(props.text || '')
87
- message.success('复制成功')
88
  }
89
  catch {
90
- message.error('复制失败')
91
  }
92
  }
93
  </script>
 
84
  async function handleCopy() {
85
  try {
86
  await copyToClip(props.text || '')
87
+ message.success(t('chat.copied'))
88
  }
89
  catch {
90
+ message.error(t('chat.copyFailed'))
91
  }
92
  }
93
  </script>
src/views/chat/index.vue CHANGED
@@ -481,7 +481,7 @@ onUnmounted(() => {
481
  <template v-if="!dataSources.length">
482
  <div class="flex items-center justify-center mt-4 text-center text-neutral-300">
483
  <SvgIcon icon="ri:bubble-chart-fill" class="mr-2 text-3xl" />
484
- <span>Aha~</span>
485
  </div>
486
  </template>
487
  <template v-else>
 
481
  <template v-if="!dataSources.length">
482
  <div class="flex items-center justify-center mt-4 text-center text-neutral-300">
483
  <SvgIcon icon="ri:bubble-chart-fill" class="mr-2 text-3xl" />
484
+ <span>{{ t('chat.newChatTitle') }}</span>
485
  </div>
486
  </template>
487
  <template v-else>
src/views/chat/layout/sider/index.vue CHANGED
@@ -20,7 +20,7 @@ const show = ref(false)
20
  const collapsed = computed(() => appStore.siderCollapsed)
21
 
22
  function handleAdd() {
23
- chatStore.addHistory({ title: 'New Chat', uuid: Date.now(), isEdit: false })
24
  if (isMobile.value)
25
  appStore.setSiderCollapsed(true)
26
  }
 
20
  const collapsed = computed(() => appStore.siderCollapsed)
21
 
22
  function handleAdd() {
23
+ chatStore.addHistory({ title: t('chat.newChatTitle'), uuid: Date.now(), isEdit: false })
24
  if (isMobile.value)
25
  appStore.setSiderCollapsed(true)
26
  }