agentic icon indicating copy to clipboard operation
agentic copied to clipboard

The unofficial api always times out after setting the conversationId

Open hyn-lei opened this issue 2 years ago • 3 comments

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

  • version :4.7.2
  • nodejs: 18.14.1
  • api: unofficial api

Describe the Bug

code and shell list below


import { ChatGPTUnofficialProxyAPI } from 'chatgpt'

async function example() {

// let url = 'https://gpt.pawan.krd/backend-api/conversation'
let url = 'https://chat.duti.tech/api/conversation'

const api = new ChatGPTUnofficialProxyAPI({

    apiReverseProxyUrl: url,
    debug:true,
    accessToken:'token'
  })

  let cid = 'cid'
  // let cid=''
  try{
  const res = await api.sendMessage('why i cant set coversation id when i call api',{conversationId:cid})
  console.log(res)
  console.log(res.text)}
  catch(ex){
  	console.log(res)
  }
}
 example()
 npx tsx test.ts

The unofficial api always times out when i set the conversationId='xxxx', and it works good when i set conversationId='', i am wrong or it is a bug?

test this code on windows 11 and almalinux 8 with nodejs 18.14.1

hyn-lei avatar Feb 24 '23 03:02 hyn-lei

@Atomin-Lee if you're setting conversationId, you must also set parentMessageId (and they both have to be valid having come from the ChatGPT account you're currently using). Otherwise, the behavior of ChatGPT's API is undefined and will likely lead to difficult to diagnose errors.

transitive-bullshit avatar Feb 24 '23 08:02 transitive-bullshit

@transitive-bullshit Thanks for your help. I solved this problem by setting a reasonable id that already exists in the chatgpt as parentMessageId,

Currently I rely on conversion to organize data, so I need to get the conversation history and the data below according to the conversationId so that the subsequent sendMessage can be completed correctly.

hyn-lei avatar Feb 24 '23 09:02 hyn-lei

@Atomin-Lee if you're setting conversationId, you must also set parentMessageId (and they both have to be valid having come from the ChatGPT account you're currently using). Otherwise, the behavior of ChatGPT's API is undefined and will likely lead to difficult to diagnose errors.

@transitive-bullshit Cheers mate. I saw it is not tricky to identify invalid conversationId in the Python libary ChatGPT by @acheong08. But I am really not good at JS so I cannot find where to add such a feature to detect invalid conversationId after try 2 days.

When a invalid conversationId was sent, the server respond with '{"detail":"Conversation not found"}'.

I guess such a feature can be added to the Parser or fetchSSE but I am not sure. Anyway, looking forward someone who can contribute a pull request.

liyucheng09 avatar Feb 25 '23 01:02 liyucheng09

@liyucheng09 good idea. just added this in 539aa6d

transitive-bullshit avatar Feb 28 '23 10:02 transitive-bullshit

I also added some additional error handling making sure that if you set conversationId, you have to also set parentMessageId and vice-versa.

transitive-bullshit avatar Feb 28 '23 10:02 transitive-bullshit

https://github.com/transitive-bullshit/chatgpt-api/releases/tag/v4.8.1

transitive-bullshit avatar Feb 28 '23 10:02 transitive-bullshit