kudoai / chatgpt.js Goto Github PK
View Code? Open in Web Editor NEW🤖 A powerful, open source client-side JavaScript library for ChatGPT
Home Page: https://chatgpt.js.org
License: MIT License
🤖 A powerful, open source client-side JavaScript library for ChatGPT
Home Page: https://chatgpt.js.org
License: MIT License
chatgpt.getLastResponse() is getting always this response: '1 / 1'
hello i could not figure out how to call send message and get the response right away. theres a way for it ?
https://github.com/kudoai/chatgpt.js/blob/main/chatgpt.js#L480
https://github.com/kudoai/chatgpt.js/blob/main/chatgpt.js#L488
https://github.com/kudoai/chatgpt.js/blob/main/chatgpt.js#L510
the above lines treat asynchronous functions as normal ones
I'm working on a new method I want to call getChatID
. what is it? basically a rewritten fetch
function. this is what I got so far:
// Needs to be called before document loading
const originalFetch = window.fetch;
window.fetch = function (url, options) {
return originalFetch.apply(this, arguments)
.then((response) => {
if (response.url.includes('://chat.openai.com/backend-api/conversations')) {
response.json().then((data) => { console.log(data); });
}
return response;
});
};
the chat id is the url identifier
why rewriting fetch instead of splitting the url? because you can't get the current chat id unless you refresh the page
why am I opening the issue? because even tho it works (the chats ids are in the items
object key)
it breaks the loading of conversations and I don't know how to fix it
The parameter btns
in chatgpt.alert()
doesn't take count of functions that have multiple words (eg. function hello_world()
) and renders them in the buttons, taken the previous example, as "Hello_world". I think it could be a nice addition.
@mefengl in your chatgpt-infinite you need to attribute this repo or chatgptjs.org and/or mention copyright me & you under MIT license (and any other scripts you use the code in)
Users want access to as much AI as they can get, they dont want to manage 50 accounts, they want the fastest AI they want the cheapest AI, and you can provide all of that for them with this update.
in addition to or in place of integrating with any aggregators - Please integrate APIpie so devs can access them all from one place/subscription and plus it also provides:
-The most affordable, reliable and fastest AI available
-One API to access ~500 Models and growing
-Language, embedding, voice, image, vision and more
-Global AI load balancing, route queries based on price or latency
-Redundancy for major models providing the greatest up time possible
-Global reporting of AI availability, pricing and performance
Its the same API format as openai, just change the domain name and your API key and enjoy a plethora of models without changing any of your code other than how you handle the models list.
This is a win win for everyone, any new AI's from any providers will be automatically integrated into your stack with this one integration. Not to mention all the other advantages.
Cause ChatGPT web is using Tailwind, if we pre-tag elements with id, it will make other scripts' development easier.
Such as, I used to get sendButton by the last button in the form, but after installing the wide-screen mode script, that function actually returned the wrong button.
this should not be much work, cause can use the function defined in #1
Hi,
the extension currently fails to run with a 404 error from chatgpt.js
line 30
Failed to load resource: the server responded with a status of 404 () https://raw.githubusercontent.com/KudoAI/chatgpt.js/main/data/_locales/en_GB/messages.json
does not exist
By the way - thank your work - I do not understand why OpenAI insists on a narrow chat window...
After adding the starter pack to my website, I encountered an issue. When I restart the extension and refresh the browser page, the request is not being made until I navigate to the chat.open.ai page. Is there a solution to call ChatGPT in the background from other pages?
We may use a bundle tool like esbuild
, then can split this single file into different files and then bundle them into a single file.
The main benefit is that conflict will be much less since working on a different file.
Another benefit is that it can auto-do compatibility work.
No matter what I try I get a CORS policy error.
Tried using the CDN to include the script still errors. Uploaded it to perplexity and asked it to give me code that sends a message and gets a response and perplexity says there's an error in the send on line 1575 ;(
current is by function run every second
I think we should store an access token somewhere in the chatgpt object as a variable, and update it once it expires (the token has an expiration date, reference here) to avoid getting rate limited by the api and reducing the speed of the library
problem is idk about the security of doing this
edit: it shouldn't even matter since there's literally a function that retrieves the access token, so storing it in the object is not even a big deal, and removing the object from the window will literally make it disappear
Dear devloper:
Thanks for the great app. I have to feature request below:
Here are three width now:
It will be great that you can add the fourth option: between "default" and "wide screen", that will be good for some conversation.
In some conversations, I have asked too many questions, it will be very easy to navigate to any question if there be an TOC on the right side.
Thank you.
https://github.com/mefengl/chatgpt-utils
If you like, I will add them to this repo
'message' in data[key] 会导致后面的data[key].message.author.role报错
'message' in data[key] 替换成 data[key].message != null 后正常运行
var chatgpt = {
// ...
eventEmitter: {
events: {},
on: function(eventName, callback) {
if (!this.events[eventName]) {
this.events[eventName] = [];
}
this.events[eventName].push(callback);
},
once: function(eventName, callback) {
var self = this;
function oneTimeCallback() {
callback.apply(null, arguments);
self.removeListener(eventName, oneTimeCallback);
}
this.on(eventName, oneTimeCallback);
},
removeListener: function(eventName, callback) {
if (this.events[eventName]) {
this.events[eventName] = this.events[eventName].filter(function(cb) {
return cb !== callback;
});
}
},
emit: function(eventName) {
if (this.events[eventName]) {
var args = Array.prototype.slice.call(arguments, 1);
this.events[eventName].forEach(function(callback) {
callback.apply(null, args);
});
}
}
},
// ...
};
emit is used when status change or other situation
user usage:
// Adding event listeners
chatgpt.eventEmitter.on('beforeSend', function() {
console.log('Before sending message...');
});
chatgpt.eventEmitter.on('afterSend', function() {
console.log('After sending message...');
});
chatgpt.eventEmitter.on('onGenerating', function() {
console.log('Generating a response...');
});
chatgpt.eventEmitter.on('onDidGenerate', function() {
console.log('Response generated.');
});
// Removing an event listener
// chatgpt.eventEmitter.removeListener('beforeSend', callback);
// Listening to an event only once
// chatgpt.eventEmitter.once('beforeSend', function() {
// console.log('Before sending message (only once)');
// });
-- from ChatGPT and mefengl
such add button to input
add button into the sidebar (like the auto clear history scripts)
As the chat GPT page has a ton of new features pertaining to GPT versions and custom GPTs, it would be very handy to have the ability to get or set chat context (amongst multiple historical chats or to a particular custom GPT) from the library.
{ Thank you so much for the time and effort you've put into making this library possible :) }
in manifest it should be
chatgpt.com/*
instead of
chat.openai.com/*
@mefengl I'm going to temporarily remove your status check to build an initial 0.0.1 release so I can test CORS passes when using ES6 import
from CDN so I can update ES6 instructions, then you can try to implement it cleaner in a branch or I will add final clean solution in main, does that sound good?
I tried using both chatgpt.send()
and creating my own logic, but none of them worked. it was working before, but the ChatGPT website got a UI update in which somehow it won't send the message automatically anymore (you have to manually modify the text first)
my own logic:
const sendButton = document.querySelector('form button[class*="bottom"]');
const chatInput = document.querySelector("form textarea");
if (chatInput) chatInput.value = "some text";
if (sendButton) {
sendButton.removeAttribute("disabled");
sendButton.click();
}
I'm not sure if adding a file upload feature is already on your product roadmap, but I believe it is a very important capability to have.
I couldn't find a delete chat func, would be great if added.
Here is playwright code to delete current chat:
page.get_by_label("Chat history").get_by_role("button").nth(1).click()
page.get_by_text("Delete chat").click()
page.get_by_role("button", name="Delete").click()
I can provide a Nepali translation for the README file since there is no option for the README to be in the Nepali language.
Should I proceed?
Dear chatgpt.js developer,
Greetings! I am vansinhu, a community developer and volunteer at InternLM. Your work has been immensely beneficial to me, and I believe it can be effectively utilized in InternLM as well. Welcome to add Discord https://discord.gg/gF9ezcmtM3 . I hope to get in touch with you.
Best regards,
vansinhu
Uncaught TypeError: Cannot set properties of null (setting 'value')
I would like to use this extension to save the current chat as json file.
I've noticed that when chat history is set to off, methods like getLastResponse
will return messages from my last saved conversation, not the current temporary conversation.
I'm interested in getting the markdown content of messages. I know it exists locally as the copy to clipboard message at the bottom of each response will put it in your keyboard without hitting any API endpoint.
Is this something that could be supported?
I'm using a userscript I made to rewrite the fetch function calls and log the details, and I found an API-way to get a response. I'm working on it, and it might even be better than the DOM solution
const endpoints = {
session: 'https://chat.openai.com/api/auth/session',
chat: 'https://chat.openai.com/backend-api/conversations',
singleChat: 'https://chat.openai.com/backend-api/conversation'
};
test: function(chatIdx, responseIdx, regeneratedIdx) {
chatIdx = chatIdx ? chatIdx : 0; // leave it as is because getChatDetails already takes care of the -1
responseIdx = responseIdx ? responseIdx - 1 : 0;
regeneratedIdx = regeneratedIdx ? regeneratedIdx - 1 : 0;
return new Promise((resolve) => { chatgpt.getAccessToken().then(token => {
getChatData(token).then(data => { resolve(data); });});});
function getChatData(token) {
return new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();
chatgpt.getChatDetails(chatIdx).then(chat => {
xhr.open('GET', endpoints.singleChat + '/' + chat.id, true); // GET request to the conversation
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.setRequestHeader('Authorization', 'Bearer ' + token);
xhr.onload = () => {
if (xhr.status !== 200) return reject('🤖 chatgpt.js >> Request failed. Cannot retrieve chat messages.');
const data = JSON.parse(xhr.responseText).mapping; // all messages
const userMessages = [];
const responses = [];
for (const key in data) if (data[key].message && data[key].message.author.role === 'user') userMessages.push(data[key].id); // filter out user messages
for (const key in data)
// match responses with their indexed parent (user message)
if (data[key].message && data[key].message.author.role === 'assistant' && data[key].parent === userMessages[responseIdx]) // use responseIdx because at each user message corresponds a response so it doesn't matter if the variable says response
responses.push(data[key].message); // push only chatgpt responses
responses.sort((a, b) => a.create_time - b.create_time); // sort by creation time (in case of the response being regenerated)
resolve(responses[regeneratedIdx].content.parts[0]); // resolve promise giving the regenerate value requested
};
xhr.send();
});
});}
},
Looks like the script is not working with the new ChatGPT Teams subscriptions. Getting Uncaught (in promise) 🤖 chatgpt.js >> No chat with id = xxxxx-xxxx-xxx found.
I tried running the following script, and every object prefixed with: chatgpt. returns null. Greasemonkey did download the minified chatgpt js file, but it cannot work at all with the object chatgpt . chatgpt.getLastReply, chatgpt.getLastResponse all return null.
// ==UserScript==
// @name ChatGPT Userscript
// @description A Greasemonkey template to start using chatgpt.js like a boss
// @author chatgpt.js
// @namespace https://chatgpt.js.org
// @Version 2024.1.28
// @match https://chat.openai.com/*
// @ICON https://raw.githubusercontent.com/kudoai/chatgpt.js-greasemonkey-starter/main/media/images/icons/robot/icon48.png
// @require https://cdn.jsdelivr.net/npm/@kudoai/[email protected]/dist/chatgpt-2.6.4.min.js
// @grant GM_getValue
// @grant GM_setValue
// @Noframes
// @homepageURL https://github.com/kudoai/chatgpt.js-greasemonkey-starter
// ==/UserScript==
(async () => {
// Init config
console.log("Inside async ");
// Print chatgpt.js methods
await chatgpt.isLoaded();
console.log("Past GPT loading ");
function logHello() {
(async () => {
console.log("Hello again");
try {
let lastResponse = await chatgpt.getLastReply();
if (typeof lastResponse === 'string') {
console.log("Hello " + lastResponse);
} else {
console.error("Hello Error: lastResponse is not a string");
}
console.log("Hello " + lastResponse);
} catch (error) {
console.error("Async Hello Error:", error);
}
})();
}
// Run the logger when the DOM is ready
window.addEventListener('DOMContentLoaded', logHello());
})();
Hey yall,
Curious to get in touch with whoever is managing this project
https://juicebox.money/v2/p/588 (0xad029Eb29Dc085ed2BC83c59eaC72B5BF0493EDE)
Excited to help make it successful, but first want to confirm who owns it.
also (this is just an idea of mine), I think we should store an access token somewhere in the chatgpt object as a variable, and update it once it expires (the token has an expiration date, reference [here](https://github.com/kudoai/chatgpt.js/blob/main/chatgpt.js#L379)) to avoid getting rate limited by the api and reducing the speed of the library
problem is idk about the security of doing this
edit: it shouldn't even matter since there's literally a function that retrieves the access token, so storing it in the object is not even a big deal, and removing the object from the window will literally make it disappear
Originally posted by @madkarmaa in #79 (comment)
Do you have any format config files to share?
I think this issue can be easily solved by asking ChatGPT.
chatgpt-conversation-1
chatgpt-conversation-1-prompt
chatgpt-conversation-1-response-1
chatgpt-conversation-1-response-2
You can move the newest code to https://github.com/chatgptjs/chatgptjs-tampermonkey-starter to find out if it works.
That repo can be a substitute for a test.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.