Git Product home page Git Product logo

zsodur / chatgpt-api-by-browser-script Goto Github PK

View Code? Open in Web Editor NEW
155.0 1.0 36.0 789 KB

This project runs on users' browsers through the Tampermonkey script and converts the web version of ChatGPT operations into an API interface. This way, you can use GPT-4 in chatgpt web pages to play things like Auto-GPT. / 该项目通过Tampermonkey脚本在用户的浏览器上运行,并将ChatGPT操作的Web版本转换为API接口。这样,您就可以使用chatgpt网页中的GPT-4来玩Auto-GPT等内容。

JavaScript 98.86% Dockerfile 1.14%

chatgpt-api-by-browser-script's Introduction

Chatgpt API By Browser Script

中文文档

This project runs on users' browsers through the Tampermonkey script and converts the web version of ChatGPT operations into an API interface. You can use this API to do some interesting things, such as playing Auto-GPT.

Update

2024-05-19: Support new version UI and gpt-4o.

Features

  • API no cost.
  • If you have a chatgpt plus account, you can use gpt-4 api.
  • Having unlimited context.
  • Not easy to be banned and easier to handle errors.

ChatGPT API Image

Usage

Step 1 Installation and Configuration

  1. Make sure your system has installed Node.js and npm.
  2. Clone this repository and run npm install in the project directory to install dependencies.
  3. Run npm run start to start the Node.js server.
  4. Alternatively, you can use Docker docker-compose up to start the Node.js server.

Step 2 Use Tampermonkey

  1. Install Tampermonkey browser extension.
  2. Open Tampermonkey management panel and create a new script.
  3. Copy the contents of tampermonkey-script.js file into the newly created script and save it.

Step 3 Download and Install the Browser Extension Disable Content-Security-Policy

Download from here

Step 4 Open and Log in to ChatGPT

https://chat.openai.com/

If you see this in the upper right corner of the webpage, you have succeeded !

Success Image

Step 5 Use API

You now have an API address: http://localhost:8766/v1/chat/completions

API Params

Parameter Description Default Required
messages Refer to OpenAI API documentation Yes
model No longer supported, please select model on the webpage.
stream Refer to OpenAI API documentation false No

Example of Request Parameters

{
  "messages": [
    {
      "role": "system",
      "content": "You are a helpful assistant."
    },
    {
      "role": "user",
      "content": "Who are you?"
    }
  ],
  "model": "gpt-4"
}

Play with Auto-GPT

Modify the llm_utils.py file in Auto-GPT.

import requests
# response = openai.ChatCompletion.create(
#     model=model,
#     messages=messages,
#     temperature=temperature,
#     max_tokens=max_tokens,
# )
response = requests.post("http://localhost:8766/v1/chat/completions", json={"messages": messages, "model": model, "newChat": False, "temperature": temperature, "max_tokens": max_tokens}).json()


# return response.choices[0].message["content"]
return response["choices"][0]["message"]["content"]

chatgpt-api-by-browser-script's People

Contributors

einarsapinis avatar zsodur avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

chatgpt-api-by-browser-script's Issues

API error

Hello,

I am getting message when sending a sample POST request (the one you have on your page as a test request)

{
"choices": [
{
"message": {
"content": "api error"
},
"delta": {
"content": "api error"
}
}
],
}

NodeJS console shows error:

request body {}
result { choices: [ { message: [Object], delta: [Object] } ] }
The browser connection has not been established, the request cannot be processed
.

Tampermonkey is installed, script is added and enabled.

Any idea what can be the problem? It runs on Win 7 64 bit, if this makes a difference. Thank you!

增加多账号功能

如果能增加多账号自动登录和达到限制时自动切换,我愿称你为最强!

api error

userscript.html?name=ChatGPT-API-By-Browser-Script.user.js&id=d8e1299c-925f-4332-be05-6b3082979646:130 Refused to connect to 'ws://localhost:8765/' because it violates the following Content Security

The script just doesnt load somehow

I have tried everything. changing the port, running as admin, disabling content security policy, using firefox edge chrome, etc.. but the script will not show any error in console, say anything in console or display any text. sometimes it randomly says error for a second or so but i cant find any pattern when that happens

edit: i found the error that sometimes pops up but only once then its gone for some time again doesnt matter what i do "Uncaught NS_ERROR_CONTENT_BLOCKED:"

edit2: the websocket works fine on other sites google etc just not on chatgpt

edit3: lol :) the problem seems to be that the script waits until the page is loaded but that never seems to happen according to the code to do that. i removed it and its kinda hacky and i dont get a response but the script loads in the first place

如何调用这段api到其他的程序中???

之前调用api的语句是:import openai

openai.api_key = 'your-api-key'或者:set OPENAI_API_KEY=your-api-key

这种。但是现在这个网址应该怎么调用?在不同类型的代码中应该如何进行调用

Textarea is null

I always get the error Uncaught (in promise) TypeError: textarea is null
image

I changed the selector to the correct one:

      const textarea = document.querySelector('#prompt-textarea');

But still no success.

Content security policy issue

Hello, I get this to work couple days ago. But now it is giving API error. And this is the error in the console. Did OpenAI block such scripts?

userscript.html?name=ChatGPT-API-By-Browser-Script.user.js&id=369ebf7e-0282-49bc-8bcd-1d341d20f2fc:130
Refused to connect to 'ws://localhost:8765/' because it violates the following Content Security Policy directive: "connect-src 'self' o33249.ingest.sentry.io statsigapi.net http://localhost:* https://*.oaistatic.com https://events.statsigapi.net *.oaiusercontent.com api-js.mixpanel.com fileserviceuploadsperm.blob.core.windows.net api-iam.intercom.io wss://fp-async-webps-prod.webpubsub.azure.com https://featuregates.org https://tcr9i.chat.openai.com rum.browser-intake-datadoghq.com https://cdn.openai.com wss://fp-async-webps-staging.webpubsub.azure.com https://chat.openai.com".

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.