Skip to content

Commit

Permalink
feat: Supports the use of the Groq api by default
Browse files Browse the repository at this point in the history
  • Loading branch information
Caojiahao-Coder committed May 3, 2024
1 parent 0113236 commit 39f4f44
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/chat.completion/ConversationController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { addNewConversationAsync, getConversationByIdAsync, getConversationList
import { removeMessagesByConversationIdAsync } from './MessageServices'
import useConversationStore from '@/store/conversation-store'
import type { NewConverstationInfo, TBConverstationInfo } from '@/database/table-type'
import { alwaysUseGroq } from '@/store/localstorage'

class ConversationController {
/**
Expand Down Expand Up @@ -94,7 +95,7 @@ class ConversationController {
description: '',
conversation_token: uid(32),
type: 'chat',
use_groq: false,
use_groq: alwaysUseGroq.value,
} as NewConverstationInfo

return await this.addConversationAsync(newInfo)
Expand Down
6 changes: 4 additions & 2 deletions src/components/ConversationBody.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import useConversationStore from '@/store/conversation-store'
import conversationController from '@/chat.completion/ConversationController'
import type { TBConverstationInfo, TBMessageInfo } from '@/database/table-type'
import useChatCompletionStore from '@/store/chat-completion-store'
import { groqApiKey, groqBaseURL, groqModel } from '@/store/localstorage'
import { alwaysUseGroq, groqApiKey, groqBaseURL, groqModel } from '@/store/localstorage'
import { push } from '@/main'
const { t } = useI18n()
Expand Down Expand Up @@ -65,6 +65,8 @@ function updateConversationInfo(newInfo: TBConverstationInfo) {
function onUseGroqAPI() {
const info = chatCompletionStore.chatCompletionHandler?.getConversationInfo()
alwaysUseGroq.value = !info?.use_groq
if (info?.use_groq === false) {
if (groqApiKey.value.length === 0 || groqBaseURL.value.length === 0 || groqModel.value.length === 0) {
push.warning(t('use_groq_api.cannot_empty'))
Expand Down Expand Up @@ -162,7 +164,7 @@ function updateConversationUseAPI(useGroqAPI: boolean) {
>
<div class="flex-1" />
<div class="flex flex-row gap-2">
<input type="checkbox" :checked="chatCompletionStore.chatCompletionHandler?.getConversationInfo().use_groq ?? false" class="w-22px h-22px m-0">
<input type="checkbox" :checked="chatCompletionStore.chatCompletionHandler?.getConversationInfo().use_groq ?? alwaysUseGroq" class="w-22px h-22px m-0">
<div class="w-22px h-22px i-carbon-face-wink-filled" />
<div class="line-height-22px">
{{ t('use_groq_api.title') }}
Expand Down
3 changes: 2 additions & 1 deletion src/components/LeftSideBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useI18n } from 'vue-i18n'
import { uid } from 'uid'
import config from '../../package.json'
import ConversationsList from './ConversationsList.vue'
import { expandLeftSideBar, filterType } from '@/store/localstorage'
import { alwaysUseGroq, expandLeftSideBar, filterType } from '@/store/localstorage'
import conversationController from '@/chat.completion/ConversationController'
import type { NewConverstationInfo } from '@/database/table-type'
import UpdateLog from '@/components/UpdateLog.vue'
Expand All @@ -23,6 +23,7 @@ function onCreateNewConversation() {
description: '',
conversation_token: uid(32),
type: 'chat',
use_groq: alwaysUseGroq.value,
} as NewConverstationInfo
conversationController.addConversationAsync(newConversationInfo)
Expand Down
2 changes: 2 additions & 0 deletions src/components/WelcomePage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useWindowSize } from '@vueuse/core'
import { useI18n } from 'vue-i18n'
import { uid } from 'uid'
import conversationController from '@/chat.completion/ConversationController'
import { alwaysUseGroq } from '@/store/localstorage'
const { t } = useI18n()
Expand All @@ -15,6 +16,7 @@ function createNewMessage() {
create_time: Date.now(),
description: '',
conversation_token: uid(32),
use_groq: alwaysUseGroq.value,
}
conversationController.addConversationAsync(newInfo)
}
Expand Down
2 changes: 2 additions & 0 deletions src/pages/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import useConversationStore from '@/store/conversation-store'
import UndefineConversation from '@/components/UndefineConversation.vue'
import DrawImageModeBody from '@/components/DrawImageModeBody.vue'
import conversationController from '@/chat.completion/ConversationController'
import { alwaysUseGroq } from '@/store/localstorage'
const conversationStore = useConversationStore()
Expand Down Expand Up @@ -40,6 +41,7 @@ function createNewConversation() {
create_time: Date.now(),
description: '',
conversation_token: uid(32),
use_groq: alwaysUseGroq.value,
}
conversationController.addConversationAsync(newInfo)
Expand Down
2 changes: 2 additions & 0 deletions src/store/localstorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@ export const groqBaseURL: Ref<string> = useStorage('groqBaseURL', 'https://api.g
export const groqApiKey: Ref<string> = useStorage('groqApiKey', '')

export const groqModel: Ref<string> = useStorage('groqModel', 'mixtral-8x7b-32768')

export const alwaysUseGroq: Ref<boolean> = useStorage('alwaysUseGroq', false)

0 comments on commit 39f4f44

Please sign in to comment.