替换ChatGPT接口为其他免费接口
This commit is contained in:
parent
90d887519d
commit
8e12eaebd2
@ -8,7 +8,7 @@
|
|||||||
<form-entry label="生成内容要求详细描述" error="content">
|
<form-entry label="生成内容要求详细描述" error="content">
|
||||||
<textarea slot="field" class="text-input" type="text" placeholder="输入内容(支持换行)" v-model.trim="content" :disabled="generating"></textarea>
|
<textarea slot="field" class="text-input" type="text" placeholder="输入内容(支持换行)" v-model.trim="content" :disabled="generating"></textarea>
|
||||||
<div class="form-entry__info">
|
<div class="form-entry__info">
|
||||||
使用 <a href="https://chat.forefront.ai" target="_blank">https://chat.forefront.ai</a> 的免费接口生成内容,AI模型是:GPT-3.5 Turbo。
|
使用 <a href="https://chat1.52ai.pw/" target="_blank">chat1.52ai.pw</a> 的免费接口生成内容,AI模型是:GPT-3.5 Turbo。
|
||||||
</div>
|
</div>
|
||||||
</form-entry>
|
</form-entry>
|
||||||
<div class="modal__result">
|
<div class="modal__result">
|
||||||
|
@ -1,25 +1,21 @@
|
|||||||
import store from '../store';
|
import store from '../store';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
chat({
|
chat({ content }, callback) {
|
||||||
content,
|
|
||||||
}, callback) {
|
|
||||||
const xhr = new XMLHttpRequest();
|
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.open('POST', url);
|
||||||
xhr.setRequestHeader('Authorization', 'Bearer null');
|
|
||||||
xhr.setRequestHeader('Content-Type', 'application/json');
|
xhr.setRequestHeader('Content-Type', 'application/json');
|
||||||
|
xhr.setRequestHeader('Authorization', 'Bearer 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');
|
||||||
xhr.send(JSON.stringify({
|
xhr.send(JSON.stringify({
|
||||||
model: 'gpt-3.5-turbo',
|
model: 'gpt-3.5-turbo',
|
||||||
action: 'noauth',
|
max_tokens: 3000,
|
||||||
text: content,
|
top_p: 0,
|
||||||
messagePersona: '607e41fe-95be-497e-8e97-010a59b2e2c0',
|
temperature: 0.9,
|
||||||
messages: [],
|
frequency_penalty: 0,
|
||||||
internetMode: 'auto',
|
presence_penalty: 0,
|
||||||
hidden: false,
|
messages: [{ role: 'user', content }],
|
||||||
id: '',
|
stream: true,
|
||||||
parentId: '',
|
|
||||||
workspaceId: '',
|
|
||||||
}));
|
}));
|
||||||
let lastRespLen = 0;
|
let lastRespLen = 0;
|
||||||
xhr.onprogress = () => {
|
xhr.onprogress = () => {
|
||||||
@ -28,17 +24,12 @@ export default {
|
|||||||
responseText.split('\n\n')
|
responseText.split('\n\n')
|
||||||
.filter(l => l.length > 0)
|
.filter(l => l.length > 0)
|
||||||
.forEach((text) => {
|
.forEach((text) => {
|
||||||
if (text === 'event: end') {
|
const item = text.substr(6);
|
||||||
|
if (item === '[DONE]') {
|
||||||
callback({ done: true });
|
callback({ done: true });
|
||||||
} else if (text.startsWith('event: message')) {
|
|
||||||
const item = text.split('\n')[1].substr(6);
|
|
||||||
const data = JSON.parse(item);
|
|
||||||
if (data.error) {
|
|
||||||
store.dispatch('notification/error', `ChatGPT接口报错,错误信息:${data.error.message}`);
|
|
||||||
callback({ error: 'ChatGPT接口请求异常!' });
|
|
||||||
} else {
|
} else {
|
||||||
callback({ content: data.delta });
|
const data = JSON.parse(item);
|
||||||
}
|
callback({ content: data.choices[0].delta.content });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user