agentic
agentic copied to clipboard
parentMessageId is not valid,How to use parentMessageId
Verify latest release
- [X] I verified that the issue exists in the latest
chatgpt
release
Verify webapp is working
- [X] I verify that the ChatGPT webapp is working properly for this account.
Environment details
node14
Describe the Bug
const api = new ChatGPTAPI({ apiKey: apiKey })
const res = await api.sendMessage("Who is Iron Man?")
--> "Iron Man is a superhero character from Marvel Comics, created by writer Stan Lee, designed by artist Don Heck and first appeared in Tales of Suspense #39 in 1963. The character's real name is Tony Stark, a billionaire inventor and playboy who builds a suit of powered armor to become a high-tech crime fighter known as Iron Man."
const res1 = await api.sendMessage("Is he dead?", { parentMessageId: res.id })
--> "I'm sorry, I don't have enough information to answer your question. Could you please provide me with more context about who or what you are referring to?"
Same problem here, would be great to have a fix. @transitive-bullshit do you need any more info to debug this?
Same here....
When u new a ChatGPTAPI, don't write it in a function.
don't do this:
import ... from ...
function click() {
const api = new ChatGPTAPI({...});
const res = await api.sendMessage("hello world");
...
}
do this:
import ... from ...
const api = new ChatGPTAPI({...});
function click() {
const res = await api.sendMessage("hello world");
...
}
When u new a ChatGPTAPI, don't write it in a function.
I am calling a script that is rerun once I have a follow-up and I am calling the object just once, but per script call :-) Judging from the docs this should be possible, or @transitive-bullshit?
When u new a ChatGPTAPI, don't write it in a function.
don't do this:
import ... from ... function click() { const api = new ChatGPTAPI({...}); const res = await api.sendMessage("hello world"); ... }
do this:
import ... from ... const api = new ChatGPTAPI({...}); function click() { const res = await api.sendMessage("hello world"); ... }
This is not possible when using CommonJS (Error related to that 'ChatGPTAPI' is not a constructor).
I looked into the messages in debug mode and it seems that the library is sending the whole history to openAI. I think this means:
- The library is doing something internal with 'parentMessageId' which doesn't work when it's not running from same constructor.
- It would cost much more that using the same parameter using the formal API.
Am I wrong? could this be fixed?
Thanks @sidan5, that would explain why it doesn't work for me as the script calls the constructor several times.
Thanks @sidan5, that would explain why it doesn't work for me as the script calls the constructor several times.
Check this issue out (just noticed): https://github.com/transitive-bullshit/chatgpt-api/issues/489
@olafthiele Have you found any solution for that? I'm trying to figure out if there is a way to actually using this library with multiple messages and I'm not sure it's feasible....
@sidan5 I have switched to the official Python lib from openai. They require you to send all previous questions and answers together with the new one. It therefore makes sense that you can't use it stateless. Openai doesn't store (at least for you) the conversation. You have to :-) @transitive-bullshit, could you change sendMessage(s) to us providing all previous messages and send that?
@olafthiele Thanks for the reference. Following your comment I've also implemented my use case with OpenAI official with node.js library. Seems to work...
Guess the best case for me to use this library was storing/following the whole user session, as that doesn't happen to my understanding, guess using the official library is better (sadly I would need to implement all the other stuff - sessions per user etc).
Singleton pattern can be used.
import { ChatGPTAPI } from "chatgpt";
class CreateAPI {
private static instance: ChatGPTAPI;
public static getInstance(apiKey?: string, apiBaseUrl?: string): ChatGPTAPI {
if (!CreateAPI.instance) {
CreateAPI.instance = new ChatGPTAPI({
apiKey: apiKey || "",
apiBaseUrl: apiBaseUrl || "xxxxxxxx",
});
}
return CreateAPI.instance;
}
}
export default CreateAPI;
Thanks @youngle316, I just need a stateless implementation, but a singletion solves this problem. It's just OpenAI's API, you have to send all previous questions and answers yourself as they count towards the tokens. More of a misunderstanding on my part.
@lwm98, ready to close this as it is due to how the API from OpenAI works?
@lwm98, ready to close this as it is due to how the API from OpenAI works?
As long as people are aware that this project doesn't do anything clever with chat history, it simply manages the sending of the entire history every time you ask a new question. And that over time, this will become a very expensive way of ensuring history.
This project is undergoing a major revamp; closing out old issues as part of the prep process.
The chatgpt
package is pretty outdated at this point. I recommend that you use the openai package or the openai-fetch package instead.