MCPcopy
hub / github.com/domeccleston/sharegpt

github.com/domeccleston/sharegpt @v1.4 sqlite

repository ↗ · DeepWiki ↗ · release v1.4 ↗
85 symbols 254 edges 56 files 0 documented · 0%
README

ShareGPT – Share your wildest ChatGPT conversations with one click.

ShareGPT

Share your wildest ChatGPT conversations with one click.

Twitter License

Introduction · Tech Stack · REST API

Introduction

ShareGPT is an open-source Chrome Extension for you to share your wildest ChatGPT conversations with one click.

Features

  • Share your ChatGPT conversations with one-click
  • Browse examples on sharegpt.com/explore
  • Save your favorite conversations for later
  • Leave comments on conversations

Tech Stack

ShareGPT is built with the following stack:

REST API

The ShareGPT API is a REST-styled API that allows you to write and read conversations from our database, exposed as HTTP endpoints.

Conversations Endpoint

POST: https://sharegpt.com/api/conversations

You can use this endpoint to add new conversations to our database.

First, if you haven't already, process the ShareGPT conversation using the following code:

function conversationData() {
  const threadContainer = document.querySelector(
    "#__next main div:nth-of-type(1) div:nth-of-type(1) div:nth-of-type(1) div:nth-of-type(1)"
  );

  var result = {
    avatarUrl: getAvatarImage(),
    items: [],
  };

  for (const node of threadContainer.children) {
    const markdownContent = node.querySelector(".markdown");

    // tailwind class indicates human or gpt
    if ([...node.classList].includes("dark:bg-gray-800")) {
      result.items.push({
        from: "human",
        value: node.textContent,
      });
      // if it's a GPT response, it might contain code blocks
    } else if ([...node.classList].includes("bg-gray-50")) {
      result.items.push({
        from: "gpt",
        value: markdownContent.outerHTML,
      });
    }
  }

  return result;
}

function getAvatarImage() {
  // Create a canvas element
  const canvas = document.createElement("canvas");

  const image = document.querySelectorAll("img")[1];

  // Set the canvas size to 30x30 pixels
  canvas.width = 30;
  canvas.height = 30;

  // Draw the img onto the canvas
  canvas.getContext("2d").drawImage(image, 0, 0);

  // Convert the canvas to a base64 string as a JPEG image
  const base64 = canvas.toDataURL("image/jpeg");

  return base64;
}

Then, send a POST request to the endpoint above with the following payload and request headers:

const res = await fetch("https://sharegpt.com/api/conversations", {
  body: JSON.stringify(conversationData),
  headers: {
    "Content-Type": "application/json",
  },
  method: "POST",
});

This will return an object with an id attribute which will be the unique identifier for the generated post:

const { id } = await res.json();
const url = `https://shareg.pt/${id}`; // short link to the ShareGPT post

GET: https://sharegpt.com/api/conversations

This endpoint takes 3 optional query parameters:

  • type:
  • Used for sorting the results.
  • Takes 2 string values: "new" | "top"
  • "new" sorts conversations by creation time
  • "top" sorts conversations by number of views
  • If undefined, defaults to "top"
  • page:
  • Used for pagination
  • Takes an integer value as a factor of the PAGINATION_LIMIT, which is set to 50.
  • E.g. to get posts 100 - 150, set page to 3
  • If undefined, defaults to 1
  • search
  • Used for filtering records by title.
  • E.g. search = "python" returns all records with the word "python" in the title
  • If undefined, search results are not filtered

Example:

await fetch(
  "https://sharegpt.com/api/conversations?type=new&page=2&search=python"
);

This returns a list of conversations with the following type:

interface ConversationMeta {
  id: string; // unique id for the conversation
  title: string; // title of the conversation (first user prompt)
  avatar: string; // base64 encoded URI of the user's avatar
  saves: number; // number of times the conversation is saved on ShareGPT
  comments: number; // number of comments the conversation has on ShareGPT
  views: number; // number of times the conversation has been viewed on ShareGPT
  createdAt: Date; // timestamp when the conversation was creataed
}
[];

Extension points exported contracts — how you extend this code

ChatParams (Interface)
(no doc)
sharegpt-app/pages/c/[id].tsx
SWRError (Interface)
(no doc)
sharegpt-app/lib/utils.ts
Session (Interface)
(no doc)
sharegpt-app/lib/auth.ts
ConversationProps (Interface)
(no doc)
sharegpt-app/lib/types.ts
ConversationMeta (Interface)
(no doc)
sharegpt-app/lib/types.ts
Session (Interface)
(no doc)
sharegpt-app/lib/types.ts

Core symbols most depended-on inside this repo

nFormatter
called by 7
sharegpt-app/lib/utils.ts
setPage
called by 3
sharegpt-app/components/explore/pagination.tsx
timeAgo
called by 3
sharegpt-app/lib/utils.ts
getConvos
called by 3
sharegpt-app/lib/api.ts
showIfNotLoading
called by 2
sharegpt-extension/index.js
useSignInModal
called by 2
sharegpt-app/components/layout/sign-in-modal.tsx
getServerSession
called by 2
sharegpt-app/lib/auth.ts
init
called by 1
sharegpt-extension/index.js

Shape

Function 77
Interface 8

Languages

TypeScript100%

Modules by API surface

sharegpt-app/lib/utils.ts5 symbols
sharegpt-extension/index.js4 symbols
sharegpt-app/pages/explore/[[...slug]].tsx4 symbols
sharegpt-app/pages/c/[id].tsx4 symbols
sharegpt-app/lib/types.ts4 symbols
sharegpt-app/components/explore/pagination.tsx4 symbols
sharegpt-app/components/comments/modal.tsx4 symbols
sharegpt-app/pages/sitemap.xml.tsx3 symbols
sharegpt-app/next.config.js3 symbols
sharegpt-app/lib/hooks/use-intersection-observer.ts3 symbols
sharegpt-app/lib/api.ts3 symbols
sharegpt-app/pages/index.tsx2 symbols

Dependencies from manifests, versioned

@next-auth/prisma-adapter1.0.5 · 1×
@next/font13.0.6 · 1×
@planetscale/database1.5.0 · 1×
@prisma/client4.7.1 · 1×
@radix-ui/react-hover-card1.0.2 · 1×
@radix-ui/react-popover1.0.2 · 1×
@splinetool/react-spline2.2.3 · 1×
@splinetool/runtime0.9.149 · 1×
@tailwindcss/forms0.5.3 · 1×
@tailwindcss/line-clamp0.4.2 · 1×
@types/html-to-text8.1.1 · 1×
@types/ms0.7.31 · 1×

For agents

$ claude mcp add sharegpt \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact