chatgpt-api: parentMessageId is not valid,How to use parentMessageId

Verify latest release

  • I verified that the issue exists in the latest chatgpt release

Verify webapp is working

  • 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?”

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Reactions: 6
  • Comments: 15 (1 by maintainers)

Most upvoted comments

Same here…

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;

@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?

Thanks @sidan5, that would explain why it doesn’t work for me as the script calls the constructor several times.

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?