mirror of
https://github.com/RYDE-WORK/Langchain-Chatchat.git
synced 2026-01-22 14:57:02 +08:00
* feat:提交前端代码 * feat:提交logo样式切换 * feat:替换avatar、部分位置icon、chatchat相关说明、git链接、Wiki链接、关于、设置、反馈与建议等功能,关闭lobehub自检更新功能 * fix:移除多余代码 --------- Co-authored-by: liunux4odoo <41217877+liunux4odoo@users.noreply.github.com>
35 lines
931 B
TypeScript
35 lines
931 B
TypeScript
import { ShareGPTConversation } from '@/types/share';
|
|
import { parseMarkdown } from '@/utils/parseMarkdown';
|
|
|
|
export const SHARE_GPT_URL = 'https://sharegpt.com/api/conversations';
|
|
|
|
class ShareGPTService {
|
|
public async createShareGPTUrl(conversation: ShareGPTConversation) {
|
|
const items = [];
|
|
|
|
for (const item of conversation.items) {
|
|
items.push({
|
|
from: item.from,
|
|
value: item.from === 'gpt' ? await parseMarkdown(item.value) : item.value,
|
|
});
|
|
}
|
|
|
|
const res = await fetch(SHARE_GPT_URL, {
|
|
body: JSON.stringify({ ...conversation, items }),
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
method: 'POST',
|
|
});
|
|
|
|
const { id } = await res.json();
|
|
|
|
if (!id) throw new Error('Failed to create ShareGPT URL');
|
|
|
|
// short link to the ShareGPT post
|
|
return `https://shareg.pt/${id}`;
|
|
}
|
|
}
|
|
|
|
export const shareGPTService = new ShareGPTService();
|