diff --git a/src/components/modals/ChatGptConfigModal.vue b/src/components/modals/ChatGptConfigModal.vue
index 5a074e5e..85ad8bf0 100644
--- a/src/components/modals/ChatGptConfigModal.vue
+++ b/src/components/modals/ChatGptConfigModal.vue
@@ -17,6 +17,12 @@
apiKey 请到 https://platform.openai.com/account/api-keys 获取
+
+
+
+ 采样温度,介于 0 和 2 之间。较高的值(如 0.8)将使输出更加随机,而较低的值(如 0.2)将使输出更加集中和确定。
+
+
@@ -32,21 +38,32 @@ export default modalTemplate({
data: () => ({
apiKey: null,
proxyHost: null,
+ temperature: 1,
}),
methods: {
resolve() {
if (!this.apiKey) {
this.setError('apiKey');
+ return;
+ }
+ if (this.temperature < 0 || this.temperature > 2) {
+ this.setError('temperature');
+ return;
}
if (this.proxyHost && this.proxyHost.endsWith('/')) {
this.proxyHost = this.proxyHost.substring(0, this.proxyHost.length - 1);
}
- this.config.resolve({ apiKey: this.apiKey, proxyHost: this.proxyHost });
+ this.config.resolve({
+ apiKey: this.apiKey,
+ proxyHost: this.proxyHost,
+ temperature: parseFloat(this.temperature),
+ });
},
},
mounted() {
this.apiKey = this.config.apiKey;
this.proxyHost = this.config.proxyHost;
+ this.temperature = this.config.temperature || this.temperature;
},
});
diff --git a/src/components/modals/ChatGptModal.vue b/src/components/modals/ChatGptModal.vue
index c3afae9d..ea2ac108 100644
--- a/src/components/modals/ChatGptModal.vue
+++ b/src/components/modals/ChatGptModal.vue
@@ -73,7 +73,12 @@ export default modalTemplate({
this.generating = true;
this.result = '';
try {
- this.xhr = chatGptSvc.chat(this.chatGptConfig.proxyHost, this.chatGptConfig.apiKey, `${this.content}\n(使用Markdown方式输出结果)`, this.process);
+ this.xhr = chatGptSvc.chat({
+ proxyHost: this.chatGptConfig.proxyHost,
+ apiKey: this.chatGptConfig.apiKey,
+ content: `${this.content}\n(使用Markdown方式输出结果)`,
+ temperature: this.chatGptConfig.temperature || 1,
+ }, this.process);
} catch (err) {
this.generating = false;
store.dispatch('notification/error', err);
@@ -81,7 +86,12 @@ export default modalTemplate({
},
async openConfig() {
try {
- const config = await store.dispatch('modal/open', { type: 'chatGptConfig', apiKey: this.chatGptConfig.apiKey, proxyHost: this.chatGptConfig.proxyHost });
+ const config = await store.dispatch('modal/open', {
+ type: 'chatGptConfig',
+ apiKey: this.chatGptConfig.apiKey,
+ proxyHost: this.chatGptConfig.proxyHost,
+ temperature: this.chatGptConfig.temperature,
+ });
store.dispatch('chatgpt/setCurrConfig', config);
} catch (e) { /* Cancel */ }
},
diff --git a/src/services/chatGptSvc.js b/src/services/chatGptSvc.js
index a06772ed..3f8ffc1b 100644
--- a/src/services/chatGptSvc.js
+++ b/src/services/chatGptSvc.js
@@ -1,7 +1,12 @@
import store from '../store';
export default {
- chat(proxyHost, apiKey, content, callback) {
+ chat({
+ proxyHost,
+ apiKey,
+ content,
+ temperature,
+ }, callback) {
const xhr = new XMLHttpRequest();
const url = `${proxyHost || 'https://api.openai.com'}/v1/chat/completions`;
xhr.open('POST', url);
@@ -10,7 +15,7 @@ export default {
xhr.send(JSON.stringify({
model: 'gpt-3.5-turbo',
messages: [{ role: 'user', content }],
- temperature: 1,
+ temperature: temperature || 1,
stream: true,
}));
let lastRespLen = 0;