Why pay for ChatGPT's API when it's free in the browser?
ChatGPT Anywhere is a browser extension skeleton for seamless ChatGPT integration, interacting directly with the ChatGPT browser API and offering developers a cost-efficient solution by eliminating the need for OpenAI's paid API calls.
Clone the repository:
git clone https://github.com/AkashKarnatak/chatgpt-anywhere.git
Navigate to the project directory:
cd chatgpt-anywhere
Install dependencies:
npm install
Build the extension for chrome and firefox:
npm run build
After building, two folders named chrome-extension
and firefox-extension
will
be created. You can now load these extensions into their respective browsers
for testing.
The OpenAIConversation
class provided in the extension/openai.js
file allows
developers to easily integrate ChatGPT conversations within their browser
extensions. Each instance of OpenAIConversation
represents a new conversation
with ChatGPT, and the ask method preserves the conversation history for ongoing
interactions.
To use the API in your extension, follow these steps:
Access OpenAIConversation API:
content-script.js
has access to the OpenAIConversation
class defined in
openai.js
.
Create a New Conversation Instance:
Create a new instance of OpenAIConversation
. This instance will handle the
communication with ChatGPT. For example:
const conv = new OpenAIConversation({
onMessage: (content) => {
// Handle the response from ChatGPT here.
// Eg: Changing text content of a div
console.log(content);
},
onError: (error) => {
// Handle any errors here.
console.error(error);
}
});
ask
method to send a message to ChatGPT and start the conversation.
Subsequent calls to ask
will continue the conversation with the preserved history.
For example:conv.ask('Why does the sky appear blue?');
Handle Responses and Errors:
Implement the onMessage
and onError
callbacks to process responses and
handle errors respectively.
Integrate into Extension Functionality: Use the conversation object within your extension's functionality to enable dynamic interactions with ChatGPT.
If you have developed an extension using "ChatGPT Anywhere" and would like to feature it here, please share details about your project in this issue.
Contributions are welcome! If you find a bug, have an idea for an enhancement, or want to contribute in any way, feel free to open an issue or submit a pull request.
This project is licensed under the AGPL3 License. For details, see the LICENSE file.