BruceQiu1996 / NChatGPTRev

ChatGPT C# SDK. Lightweight package for interacting with ChatGPT's API by OpenAI. Uses reverse engineered official API. ChatGPT 聊天机器人 .net 版. 开箱即用.
83 stars 29 forks source link

To Many Requests after one successful request #1

Open jgric2 opened 1 year ago

jgric2 commented 1 year ago

First of all thank you for writing this in C#!

However I have followed your instructions and have provided my own useragent from chrome in the network tab as well as the "__Secure-next-auth.session-token" and "cf_clearance", however when the code reaches " RefreshSessionAsync()" and tries to get a response it always seems to return forbidden. I would love to get this running so any help as to what I am doing wrong would be greatly appreciated!

I noticed some other values in the chrome network tab such as "Host-next-auth.csrf-token" and "cf_bm", I see no instructions for those but was just wondering perhaps they are also needed for authentication?

looking forward to your response :) James

jgric2 commented 1 year ago

Never mind! got it working when I got home, might have been the internet connection I was on, thanks again for the great API!

jgric2 commented 1 year ago

seems that I can connect without the forbidden code, but after the first request I keep on getting a "To Many Requests" error. however this seems strange as I only sent through one question before this happened and it keeps occurring despite the website version of ChatGPT working fine.

Edit: Just tried using a VPN and putting the new credentials into the code and once again it worked for the first request before immediately throwing the "To Many Requests" error. After switching back off the VPN the same thing happens, one request is processed but any additional ones on the same IP seem to fail.

any ideas?

BruceQiu1996 commented 1 year ago

yes,because of to networdk may cause to many request.

BruceQiu1996 commented 1 year ago

@jgric2 may be you can call ''ResetConversation" method when you get response from chatgpt.But it will not continue you last converstaion.i will survey it when weekend.

jgric2 commented 1 year ago

yes,because of to networdk may cause to many request.

I see... it just seems odd it seems to occur after only one request :/

I will try resetting the conversationMethod and see if that helps in anyway, ill also spend the next few days debugging and seeing what I can do and will report back if I have any findings to assist you Bruce :)

thanks again let me know if you find any solutions while surveying the code on the weekend :)

Nil0516 commented 1 year ago

To Many Requests problem: Because await client.GetAsync didn't close. below code resolved.

using (var client = new HttpClient())
{
    client.BaseAddress = new Uri(url);   
    using (var response = await client.GetAsync(url))
    {
        // do
    } 
}   // auto close

But I still got error code of Forbidden. It could be CloudFlare protection mechanism.

jgric2 commented 1 year ago

To Many Requests problem: Because await client.GetAsync didn't close. below code resolved.

using (var client = new HttpClient())
{
    client.BaseAddress = new Uri(url);   
    using (var response = await client.GetAsync(url))
    {
        // do
    } 
}   // auto close

But I still got error code of Forbidden. It could be CloudFlare protection mechanism.

unfortunately the problem still exists even after trying your new code snipped, wish I could help with the forbidden problem but it didnt work for me on another network but on my home network I can always initialize the connection using the latest tokens from chrome dev mode.

I just cant seem to get it to send any actual messages to ChatGPT and get a non-error message about to many requests unless its the first time after a new token is provided and the previous token timeout has expired.

Perhaps the issue is with client.PostAsync?

BruceQiu1996 commented 1 year ago

@jgric2 Sorry to reply you so late. I'm infected with COVID-19. Today is the third day.

jgric2 commented 1 year ago

Hope your feeling ok :(, covid is a nasty one, heal up as best you can!