Skip to content

Commit

Permalink
Support GPT-4
Browse files Browse the repository at this point in the history
  • Loading branch information
WongSaang committed Mar 27, 2023
1 parent f8c2f39 commit 8175f19
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 22 deletions.
10 changes: 7 additions & 3 deletions components/ModelParameters.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
<script setup>
const dialog = ref(false)
const currentModel = useCurrentModel()
const availableModels = [
DEFAULT_MODEL.name
'gpt-3.5-turbo',
'gpt-4'
]
const currentModelDefault = ref(MODELS[currentModel.value.name])
watch(currentModel, (newVal, oldVal) => {
currentModelDefault.value = MODELS[newVal.name]
saveCurrentModel(newVal)
}, { deep: true })
Expand Down Expand Up @@ -83,7 +87,7 @@ watch(currentModel, (newVal, oldVal) => {
single-line
density="compact"
type="number"
max="2048"
:max="currentModelDefault.total_tokens"
step="1"
style="width: 100px"
class="flex-grow-0"
Expand All @@ -93,7 +97,7 @@ watch(currentModel, (newVal, oldVal) => {
<v-col cols="12">
<v-slider
v-model="currentModel.max_tokens"
:max="2048"
:max="currentModelDefault.total_tokens"
:step="1"
hide-details
>
Expand Down
2 changes: 1 addition & 1 deletion composables/states.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

export const useModels = () => useState('models', () => getStoredModels())
// export const useModels = () => useState('models', () => getStoredModels())

export const useCurrentModel = () => useState('currentModel', () => getCurrentModel())

Expand Down
5 changes: 3 additions & 2 deletions pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,13 @@ const fetchReply = async (message) => {
throw err;
},
async onmessage(message) {
// console.log(message)
const event = message.event
const data = JSON.parse(message.data)
if (event === 'error') {
throw new Error(data.error);
abortFetch()
showSnackbar(data.error)
return;
}
if (event === 'userMessageId') {
Expand Down
30 changes: 22 additions & 8 deletions utils/enums.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,25 @@ export const STORAGE_KEY = {
OPENAI_API_KEY: 'openai_api_key',
}

export const DEFAULT_MODEL = {
name: 'gpt-3.5-turbo',
frequency_penalty: 0.0,
presence_penalty: 0.0,
max_tokens: 1000,
temperature: 0.7,
top_p: 1.0
}
export const MODELS = {
'gpt-3.5-turbo': {
name: 'gpt-3.5-turbo',
frequency_penalty: 0.0,
presence_penalty: 0.0,
total_tokens: 4096,
max_tokens: 1000,
temperature: 0.7,
top_p: 1.0
},
'gpt-4': {
name: 'gpt-4',
frequency_penalty: 0.0,
presence_penalty: 0.0,
total_tokens: 8192,
max_tokens: 2000,
temperature: 0.7,
top_p: 1.0
}
}

export const DEFAULT_MODEL_NAME = 'gpt-3.5-turbo'
17 changes: 9 additions & 8 deletions utils/localStorage.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {MODELS} from "~/utils/enums";

const get = (key) => {
let val = localStorage.getItem(key)
Expand All @@ -17,13 +18,13 @@ export const setModels = (val) => {
models.value = val
}

export const getStoredModels = () => {
let models = get(STORAGE_KEY.MODELS)
if (!models) {
models = [DEFAULT_MODEL]
}
return models
}
// export const getStoredModels = () => {
// let models = get(STORAGE_KEY.MODELS)
// if (!models) {
// models = [DEFAULT_MODEL]
// }
// return models
// }

export const saveCurrentModel = (val) => {
set(STORAGE_KEY.CURRENT_MODEL, val)
Expand All @@ -32,7 +33,7 @@ export const saveCurrentModel = (val) => {
export const getCurrentModel = () => {
let model = get(STORAGE_KEY.CURRENT_MODEL)
if (!model) {
model = DEFAULT_MODEL
model = MODELS[DEFAULT_MODEL_NAME]
}
return model
}
Expand Down

0 comments on commit 8175f19

Please sign in to comment.