acheong08 / EdgeGPT

Reverse engineered API of Microsoft's Bing Chat AI
The Unlicense
8.07k stars 909 forks source link

[Bug]: Unable to customize cookie record file path using Query #462

Open starhui70520 opened 1 year ago

starhui70520 commented 1 year ago

Is there an existing issue for this?

What happened?

Unable to customize cookie record file path using Query

Steps to reproduce the problem

Save the bing_cookies_0.json file in a subdirectory of the directory where the program is located for example:cookie_file="./newbing_tokens/bing_cookies_0.json"

What should have happened?

Should return str type text normally

Version where the problem happens

0.7.0

What Python version are you running this with?

Python 3.10.6

What is your operating system ?

Other/Cloud

Command Line Arguments

None

Console logs

> Please set Cookie.current_filepath to a valid cookie file, then run Cookie.import_data()
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
File /usr/local/lib/python3.10/dist-packages/EdgeGPT.py:1105, in Cookie.import_data(cls)
   1104 try:
-> 1105     cls.current_filepath = cls.files()[cls.current_file_index]
   1106 except IndexError as exc:

IndexError: list index out of range

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
Cell In[12], line 35
     33 style = newbing_config.get("style")
     34 if style and token_path:
---> 35     q = Query(
     36           "你是谁?",
     37           style=style,
     38           cookie_file="newbing_tokens/bing_cookies_0.json"
     39           #cookie_file= os.path.join(token_path, get_newbing_JsonFile(token_path))
     40         )
     41     print(q)
     42 else:

File /usr/local/lib/python3.10/dist-packages/EdgeGPT.py:1159, in Query.__init__(self, prompt, style, content_type, cookie_file, echo, echo_prompt, proxy)
   1157 self.request_count = {}
   1158 self.image_dirpath = Path("./").resolve()
-> 1159 Cookie.import_data()
   1160 self.index += [self]
   1161 self.prompt = prompt

File /usr/local/lib/python3.10/dist-packages/EdgeGPT.py:1110, in Cookie.import_data(cls)
   1106 except IndexError as exc:
   1107     print(
   1108         "> Please set Cookie.current_filepath to a valid cookie file, then run Cookie.import_data()",
   1109     )
-> 1110     raise "No valid cookie file found." from exc
   1111 print(f"> Importing cookies from: {cls.current_filepath.name}")
   1112 with open(cls.current_filepath, encoding="utf-8") as file:

TypeError: exceptions must derive from BaseException

Additional information

No response

starhui70520 commented 1 year ago

I have tried placing the json file in the same directory as the program, which can run

PFython commented 1 year ago

@acheong08 - This relates to Query/Cookiie so I'm happy if you want to assign the Issue to me.

MonsterDruide1 commented 1 year ago

This does not contain chinese for the most part. Also, as far as I understand, it is not an issue report, but more like a feature request: Being able to customize the search path for the cookie file to a subdirectory, instead of the current directory.

PFython commented 1 year ago

Sorry copy/paste error.

acheong08 commented 1 year ago

@PFython Thanks!

PFython commented 1 year ago

See https://github.com/acheong08/EdgeGPT/pull/507

PFython commented 1 year ago

The most recent update ('today') allows you to set the cookie directory with Cookie.dir_path = r"..." or not use cookies at all.

I think this can be closed now?