Change the api key to local storage

This commit is contained in:
Rafi
2023-02-12 14:16:34 +08:00
parent edde4112c1
commit 6dfc92ede9
7 changed files with 119 additions and 19 deletions

View File

@@ -1,11 +1,13 @@
import {useCurrentModel, useModels} from "~/composables/states";
const get = (key) => {
let val = localStorage.getItem(key)
if (val) {
val = JSON.parse(val)
if (typeof window !== 'undefined') {
let val = localStorage.getItem(key)
if (val) {
val = JSON.parse(val)
}
return val
}
return val
return null
}
const set = (key, val) => {
@@ -40,4 +42,14 @@ export const getCurrentModel = () => {
model = DEFAULT_OPENAI_MODEL
}
return model
}
export const setApiKey = (val) => {
const apiKey = useApiKey()
set(STORAGE_KEY.OPENAI_API_KEY, val)
apiKey.value = val
}
export const getStoredApiKey = () => {
return get(STORAGE_KEY.OPENAI_API_KEY)
}