替换ChatGPT接口为其他免费接口

This commit is contained in:
xiaoqi.cxq 2023-06-29 21:49:02 +08:00
parent 90d887519d
commit 8e12eaebd2
2 changed files with 15 additions and 24 deletions

View File

@ -8,7 +8,7 @@
<form-entry label="生成内容要求详细描述" error="content">
<textarea slot="field" class="text-input" type="text" placeholder="输入内容(支持换行)" v-model.trim="content" :disabled="generating"></textarea>
<div class="form-entry__info">
使用 <a href="https://chat.forefront.ai" target="_blank">https://chat.forefront.ai</a> AIGPT-3.5 Turbo
使用 <a href="https://chat1.52ai.pw/" target="_blank">chat1.52ai.pw</a> 的免费接口生成内容AI模型是GPT-3.5 Turbo
</div>
</form-entry>
<div class="modal__result">

View File

@ -1,25 +1,21 @@
import store from '../store';
export default {
chat({
content,
}, callback) {
chat({ content }, callback) {
const xhr = new XMLHttpRequest();
const url = 'https://streaming.tenant-forefront-default.knative.chi.coreweave.com/free-chat';
const url = 'https://fd.52ai.pw/v1/chat/completions';
xhr.open('POST', url);
xhr.setRequestHeader('Authorization', 'Bearer null');
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.setRequestHeader('Authorization', 'Bearer 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');
xhr.send(JSON.stringify({
model: 'gpt-3.5-turbo',
action: 'noauth',
text: content,
messagePersona: '607e41fe-95be-497e-8e97-010a59b2e2c0',
messages: [],
internetMode: 'auto',
hidden: false,
id: '',
parentId: '',
workspaceId: '',
max_tokens: 3000,
top_p: 0,
temperature: 0.9,
frequency_penalty: 0,
presence_penalty: 0,
messages: [{ role: 'user', content }],
stream: true,
}));
let lastRespLen = 0;
xhr.onprogress = () => {
@ -28,17 +24,12 @@ export default {
responseText.split('\n\n')
.filter(l => l.length > 0)
.forEach((text) => {
if (text === 'event: end') {
const item = text.substr(6);
if (item === '[DONE]') {
callback({ done: true });
} else if (text.startsWith('event: message')) {
const item = text.split('\n')[1].substr(6);
} else {
const data = JSON.parse(item);
if (data.error) {
store.dispatch('notification/error', `ChatGPT接口报错,错误信息:${data.error.message}`);
callback({ error: 'ChatGPT接口请求异常' });
} else {
callback({ content: data.delta });
}
callback({ content: data.choices[0].delta.content });
}
});
};