diff --git a/components/ModelParameters.vue b/components/ModelParameters.vue new file mode 100644 index 0000000..3c54f34 --- /dev/null +++ b/components/ModelParameters.vue @@ -0,0 +1,191 @@ + + + + + + + + + + {{ $t('modelParameters') }} + + + + + + + + + + + + {{ $t('temperature') }} + + + + + + + + + + + + {{ $t('maxTokens') }} + + + + + + + + + + + + {{ $t('topP') }} + + + + + + + + + + + + {{ $t('frequencyPenalty') }} + + + + + + + + + + + {{ $t('presencePenalty') }} + + + + + + + + + + + + + \ No newline at end of file diff --git a/lang/en-US.json b/lang/en-US.json index 07da319..d55b4ca 100644 --- a/lang/en-US.json +++ b/lang/en-US.json @@ -18,6 +18,13 @@ "feedback": "Feedback", "newConversation": "New conversation", "clearConversations": "Clear conversations", + "modelParameters": "Model Parameters", + "model": "Model", + "temperature": "Temperature", + "topP": "Top P", + "frequencyPenalty": "Frequency Penalty", + "presencePenalty": "Presence Penalty", + "maxTokens": "Max Tokens", "roles": { "me": "Me", "ai": "AI" diff --git a/lang/zh-CN.json b/lang/zh-CN.json index 8848229..b7ebe42 100644 --- a/lang/zh-CN.json +++ b/lang/zh-CN.json @@ -18,6 +18,13 @@ "feedback": "反馈", "newConversation": "新的对话", "clearConversations": "清除对话", + "modelParameters": "模型参数", + "model": "模型", + "temperature": "Temperature", + "topP": "Top P", + "frequencyPenalty": "Frequency Penalty", + "presencePenalty": "Presence Penalty", + "maxTokens": "Max Tokens", "roles": { "me": "我", "ai": "AI" diff --git a/layouts/default.vue b/layouts/default.vue index 1460007..1cb6ad1 100644 --- a/layouts/default.vue +++ b/layouts/default.vue @@ -228,6 +228,8 @@ onNuxtReady(async () => { + + diff --git a/pages/index.vue b/pages/index.vue index ed04a58..cac80b3 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -51,6 +51,14 @@ const abortFetch = () => { } const fetchReply = async (message, parentMessageId) => { ctrl = new AbortController() + + const data = Object.assign({}, currentModel.value, { + openaiApiKey: openaiApiKey.value, + message: message, + parentMessageId: parentMessageId, + conversationId: currentConversation.value.id + }) + try { await fetchEventSource('/api/conversation/', { signal: ctrl.signal, @@ -59,13 +67,7 @@ const fetchReply = async (message, parentMessageId) => { 'accept': 'application/json', 'Content-Type': 'application/json', }, - body: JSON.stringify({ - model: currentModel.value, - openaiApiKey: openaiApiKey.value, - message: message, - parentMessageId: parentMessageId, - conversationId: currentConversation.value.id - }), + body: JSON.stringify(data), onopen(response) { if (response.ok && response.headers.get('content-type') === EventStreamContentType) { return; diff --git a/utils/enums.js b/utils/enums.js index 0d94f56..29b4348 100644 --- a/utils/enums.js +++ b/utils/enums.js @@ -1,6 +1,15 @@ export const STORAGE_KEY = { - OPENAI_MODELS: 'openai_models', - CURRENT_OPENAI_MODEL: 'current_openai_model', + MODELS: 'models', + CURRENT_MODEL: 'current_model', 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 } \ No newline at end of file diff --git a/utils/localStorage.js b/utils/localStorage.js index 6ee60ef..9d32e5d 100644 --- a/utils/localStorage.js +++ b/utils/localStorage.js @@ -11,32 +11,28 @@ const set = (key, val) => { localStorage.setItem(key, JSON.stringify(val)) } -const DEFAULT_OPENAI_MODEL = 'text-davinci-003' - export const setModels = (val) => { const models = useModels() - set(STORAGE_KEY.OPENAI_MODELS, val) + set(STORAGE_KEY.MODELS, val) models.value = val } export const getStoredModels = () => { - let models = get(STORAGE_KEY.OPENAI_MODELS) + let models = get(STORAGE_KEY.MODELS) if (!models) { - models = [DEFAULT_OPENAI_MODEL] + models = [DEFAULT_MODEL] } return models } -export const setCurrentModel = (val) => { - const model = useCurrentModel() - set(STORAGE_KEY.CURRENT_OPENAI_MODEL, val) - model.value = val +export const saveCurrentModel = (val) => { + set(STORAGE_KEY.CURRENT_MODEL, val) } export const getCurrentModel = () => { - let model = get(STORAGE_KEY.CURRENT_OPENAI_MODEL) + let model = get(STORAGE_KEY.CURRENT_MODEL) if (!model) { - model = DEFAULT_OPENAI_MODEL + model = DEFAULT_MODEL } return model }