chatgpt调整
This commit is contained in:
parent
c1232b59db
commit
90d887519d
@ -42,7 +42,6 @@ import SponsorModal from './modals/SponsorModal';
|
||||
import CommitMessageModal from './modals/CommitMessageModal';
|
||||
import WorkspaceImgPathModal from './modals/WorkspaceImgPathModal';
|
||||
import ChatGptModal from './modals/ChatGptModal';
|
||||
import ChatGptConfigModal from './modals/ChatGptConfigModal';
|
||||
|
||||
// Providers
|
||||
import GooglePhotoModal from './modals/providers/GooglePhotoModal';
|
||||
@ -114,7 +113,6 @@ export default {
|
||||
CommitMessageModal,
|
||||
WorkspaceImgPathModal,
|
||||
ChatGptModal,
|
||||
ChatGptConfigModal,
|
||||
// Providers
|
||||
GooglePhotoModal,
|
||||
GoogleDriveAccountModal,
|
||||
|
@ -1,69 +0,0 @@
|
||||
<template>
|
||||
<modal-inner aria-label="ChatGPT配置">
|
||||
<div class="modal__content">
|
||||
<div class="modal__image">
|
||||
<icon-chat-gpt></icon-chat-gpt>
|
||||
</div>
|
||||
<p> <b>ChatGPT</b> 配置<br>官方的接口地址在国内可能无法正常访问,可以自行找代理地址</p>
|
||||
<form-entry label="代理地址" error="proxyHost">
|
||||
<input slot="field" class="textfield" type="text" v-model.trim="proxyHost" @keydown.enter="resolve()">
|
||||
<div class="form-entry__info">
|
||||
<b>非必填,默认是官方接口地址(https://api.openai.com),代理地址如:</b> https://openai.geekr.cool
|
||||
</div>
|
||||
</form-entry>
|
||||
<form-entry label="apiKey" error="apiKey">
|
||||
<input slot="field" class="textfield" type="text" v-model.trim="apiKey" @keydown.enter="resolve()">
|
||||
<div class="form-entry__info">
|
||||
<b>apiKey</b> 请到 <a href="https://platform.openai.com/account/api-keys" target="_blank">https://platform.openai.com/account/api-keys</a> 获取<br>
|
||||
</div>
|
||||
</form-entry>
|
||||
<form-entry label="采样温度" error="temperature">
|
||||
<input slot="field" class="textfield" type="number" v-model.trim="temperature" @keydown.enter="resolve()">
|
||||
<div class="form-entry__info">
|
||||
<b>采样温度</b>,介于 0 和 2 之间。较高的值(如 0.8)将使输出更加随机,而较低的值(如 0.2)将使输出更加集中和确定。<br>
|
||||
</div>
|
||||
</form-entry>
|
||||
</div>
|
||||
<div class="modal__button-bar">
|
||||
<button class="button" @click="config.reject()">取消</button>
|
||||
<button class="button button--resolve" @click="resolve()">确认</button>
|
||||
</div>
|
||||
</modal-inner>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import modalTemplate from './common/modalTemplate';
|
||||
|
||||
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,
|
||||
temperature: parseFloat(this.temperature),
|
||||
});
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
this.apiKey = this.config.apiKey;
|
||||
this.proxyHost = this.config.proxyHost;
|
||||
this.temperature = this.config.temperature || this.temperature;
|
||||
},
|
||||
});
|
||||
</script>
|
@ -6,17 +6,9 @@
|
||||
</div>
|
||||
<p><b>ChatGPT内容生成</b><br>生成时长受ChatGPT服务响应与网络响应时长影响,时间可能较长</p>
|
||||
<form-entry label="生成内容要求详细描述" error="content">
|
||||
<textarea slot="field" class="text-input" type="text" placeholder="输入内容(支持换行)" v-model.trim="content" :disabled="generating || !chatGptConfig.apiKey"></textarea>
|
||||
<textarea slot="field" class="text-input" type="text" placeholder="输入内容(支持换行)" v-model.trim="content" :disabled="generating"></textarea>
|
||||
<div class="form-entry__info">
|
||||
<span v-if="!chatGptConfig.apiKey" class="config-warning">
|
||||
未配置apiKey,请点击 <a href="javascript:void(0)" @click="openConfig">配置</a> apiKey。
|
||||
</span>
|
||||
<span v-else>
|
||||
<span v-if="chatGptConfig.proxyHost">
|
||||
<b>当前使用的接口代理:</b>{{ chatGptConfig.proxyHost }}
|
||||
</span>
|
||||
<a href="javascript:void(0)" @click="openConfig">修改apiKey配置</a>
|
||||
</span>
|
||||
使用 <a href="https://chat.forefront.ai" target="_blank">https://chat.forefront.ai</a> 的免费接口生成内容,AI模型是:GPT-3.5 Turbo。
|
||||
</div>
|
||||
</form-entry>
|
||||
<div class="modal__result">
|
||||
@ -33,7 +25,6 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { mapGetters } from 'vuex';
|
||||
import modalTemplate from './common/modalTemplate';
|
||||
import chatGptSvc from '../../services/chatGptSvc';
|
||||
import store from '../../store';
|
||||
@ -45,14 +36,9 @@ export default modalTemplate({
|
||||
result: '',
|
||||
xhr: null,
|
||||
}),
|
||||
computed: {
|
||||
...mapGetters('chatgpt', [
|
||||
'chatGptConfig',
|
||||
]),
|
||||
},
|
||||
methods: {
|
||||
resolve(evt) {
|
||||
evt.preventDefault(); // Fixes https://github.com/mafgwo/stackedit/issues/1503
|
||||
evt.preventDefault();
|
||||
const { callback } = this.config;
|
||||
this.config.resolve();
|
||||
callback(this.result);
|
||||
@ -74,27 +60,13 @@ export default modalTemplate({
|
||||
this.result = '';
|
||||
try {
|
||||
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);
|
||||
}
|
||||
},
|
||||
async openConfig() {
|
||||
try {
|
||||
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 */ }
|
||||
},
|
||||
reject() {
|
||||
if (this.generating) {
|
||||
if (this.xhr) {
|
||||
|
@ -2,21 +2,24 @@ import store from '../store';
|
||||
|
||||
export default {
|
||||
chat({
|
||||
proxyHost,
|
||||
apiKey,
|
||||
content,
|
||||
temperature,
|
||||
}, callback) {
|
||||
const xhr = new XMLHttpRequest();
|
||||
const url = `${proxyHost || 'https://api.openai.com'}/v1/chat/completions`;
|
||||
const url = 'https://streaming.tenant-forefront-default.knative.chi.coreweave.com/free-chat';
|
||||
xhr.open('POST', url);
|
||||
xhr.setRequestHeader('Authorization', `Bearer ${apiKey}`);
|
||||
xhr.setRequestHeader('Authorization', 'Bearer null');
|
||||
xhr.setRequestHeader('Content-Type', 'application/json');
|
||||
xhr.send(JSON.stringify({
|
||||
model: 'gpt-3.5-turbo',
|
||||
messages: [{ role: 'user', content }],
|
||||
temperature: temperature || 1,
|
||||
stream: true,
|
||||
action: 'noauth',
|
||||
text: content,
|
||||
messagePersona: '607e41fe-95be-497e-8e97-010a59b2e2c0',
|
||||
messages: [],
|
||||
internetMode: 'auto',
|
||||
hidden: false,
|
||||
id: '',
|
||||
parentId: '',
|
||||
workspaceId: '',
|
||||
}));
|
||||
let lastRespLen = 0;
|
||||
xhr.onprogress = () => {
|
||||
@ -25,12 +28,17 @@ export default {
|
||||
responseText.split('\n\n')
|
||||
.filter(l => l.length > 0)
|
||||
.forEach((text) => {
|
||||
const item = text.substr(6);
|
||||
if (item === '[DONE]') {
|
||||
if (text === 'event: end') {
|
||||
callback({ done: true });
|
||||
} else {
|
||||
} else if (text.startsWith('event: message')) {
|
||||
const item = text.split('\n')[1].substr(6);
|
||||
const data = JSON.parse(item);
|
||||
callback({ content: data.choices[0].delta.content });
|
||||
if (data.error) {
|
||||
store.dispatch('notification/error', `ChatGPT接口报错,错误信息:${data.error.message}`);
|
||||
callback({ error: 'ChatGPT接口请求异常!' });
|
||||
} else {
|
||||
callback({ content: data.delta });
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
@ -1,25 +0,0 @@
|
||||
const chatgptConfigKey = 'chatgpt/config';
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state: {
|
||||
config: {
|
||||
apiKey: null,
|
||||
proxyHost: null,
|
||||
},
|
||||
},
|
||||
mutations: {
|
||||
setCurrConfig: (state, value) => {
|
||||
state.config = value;
|
||||
},
|
||||
},
|
||||
getters: {
|
||||
chatGptConfig: state => state.config,
|
||||
},
|
||||
actions: {
|
||||
setCurrConfig({ commit }, value) {
|
||||
commit('setCurrConfig', value);
|
||||
localStorage.setItem(chatgptConfigKey, JSON.stringify(value));
|
||||
},
|
||||
},
|
||||
};
|
@ -20,7 +20,6 @@ import userInfo from './userInfo';
|
||||
import workspace from './workspace';
|
||||
import img from './img';
|
||||
import theme from './theme';
|
||||
import chatgpt from './chatgpt';
|
||||
import locationTemplate from './locationTemplate';
|
||||
import emptyPublishLocation from '../data/empties/emptyPublishLocation';
|
||||
import emptySyncLocation from '../data/empties/emptySyncLocation';
|
||||
@ -52,7 +51,6 @@ const store = new Vuex.Store({
|
||||
workspace,
|
||||
img,
|
||||
theme,
|
||||
chatgpt,
|
||||
},
|
||||
state: {
|
||||
light: false,
|
||||
|
Loading…
Reference in New Issue
Block a user