Coder Social home page Coder Social logo

llegomark / sharegpt Goto Github PK

View Code? Open in Web Editor NEW

This project forked from domeccleston/sharegpt

1.0 1.0 0.0 4.48 MB

Easily share permanent links to ChatGPT conversations with your friends

Home Page: https://sharegpt.com

Shell 0.16% JavaScript 8.98% TypeScript 84.66% CSS 5.00% HTML 1.19%

sharegpt's Introduction

ShareGPT – Share your wildest ChatGPT conversations with one click.

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
}
[];

sharegpt's People

Contributors

domeccleston avatar steven-tey avatar tianenpang avatar devnvll avatar llegomark avatar vicradon avatar piotrski avatar benwurth avatar

Stargazers

Roman avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.