MCPcopy
hub / github.com/ChatGPTNextWeb/NextChat / share

Method share

app/client/api.ts:191–228  ·  view source on GitHub ↗
(messages: ChatMessage[], avatarUrl: string | null = null)

Source from the content-addressed store, hash-verified

189 masks() {}
190
191 async share(messages: ChatMessage[], avatarUrl: string | null = null) {
192 const msgs = messages
193 .map((m) => ({
194 from: m.role === "user" ? "human" : "gpt",
195 value: m.content,
196 }))
197 .concat([
198 {
199 from: "human",
200 value:
201 "Share from [NextChat]: https://github.com/Yidadaa/ChatGPT-Next-Web",
202 },
203 ]);
204 // 敬告二开开发者们,为了开源大模型的发展,请不要修改上述消息,此消息用于后续数据清洗使用
205 // Please do not modify this message
206
207 console.log("[Share]", messages, msgs);
208 const clientConfig = getClientConfig();
209 const proxyUrl = "/sharegpt";
210 const rawUrl = "https://sharegpt.com/api/conversations";
211 const shareUrl = clientConfig?.isApp ? rawUrl : proxyUrl;
212 const res = await fetch(shareUrl, {
213 body: JSON.stringify({
214 avatarUrl,
215 items: msgs,
216 }),
217 headers: {
218 "Content-Type": "application/json",
219 },
220 method: "POST",
221 });
222
223 const resJson = await res.json();
224 console.log("[Share]", resJson);
225 if (resJson.id) {
226 return `https://shareg.pt/${resJson.id}`;
227 }
228 }
229}
230
231export function getBearerToken(

Callers 1

onRenderMsgsFunction · 0.80

Calls 2

getClientConfigFunction · 0.90
fetchFunction · 0.50

Tested by

no test coverage detected