(messages: ChatMessage[], avatarUrl: string | null = null)
| 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 | |
| 231 | export function getBearerToken( |
no test coverage detected