evyatar9 / GptHidra

GptHidra is a Ghidra plugin that uses the OpenAI Chat GPT to explain functions. With GptHidra, you can easily understand the purpose and behavior of functions in your codebase. Now with GPT4 Support!
304 stars 22 forks source link

404 Error on API Call #8

Closed sugitime closed 1 month ago

sugitime commented 2 months ago

Receiving a 404 error when trying to send a request to https://api.openai.com/v1/chat/completions.

Traceback (most recent call last): File "C:\Users\New\ghidra_scripts\GptHydra.py", line 75, in <module> explanation = explainFunction(c_code) File "C:\Users\New\ghidra_scripts\GptHydra.py", line 75, in <module> explanation = explainFunction(c_code) File "C:\Users\New\ghidra_scripts\GptHydra.py", line 34, in explainFunction response = json.loads(urllib2.urlopen(req).read()) File "C:\Users\New\Downloads\ghidra_11.0.2_PUBLIC_20240326\ghidra_11.0.2_PUBLIC\Ghidra\Features\Python\data\jython-2.7.3\Lib\urllib2.py", line 154, in urlopen return opener.open(url, data, timeout) File "C:\Users\New\Downloads\ghidra_11.0.2_PUBLIC_20240326\ghidra_11.0.2_PUBLIC\Ghidra\Features\Python\data\jython-2.7.3\Lib\urllib2.py", line 435, in open response = meth(req, response) File "C:\Users\New\Downloads\ghidra_11.0.2_PUBLIC_20240326\ghidra_11.0.2_PUBLIC\Ghidra\Features\Python\data\jython-2.7.3\Lib\urllib2.py", line 547, in http_response response = self.parent.error( File "C:\Users\New\Downloads\ghidra_11.0.2_PUBLIC_20240326\ghidra_11.0.2_PUBLIC\Ghidra\Features\Python\data\jython-2.7.3\Lib\urllib2.py", line 473, in error return self._call_chain(*args) File "C:\Users\New\Downloads\ghidra_11.0.2_PUBLIC_20240326\ghidra_11.0.2_PUBLIC\Ghidra\Features\Python\data\jython-2.7.3\Lib\urllib2.py", line 407, in _call_chain result = func(*args) File "C:\Users\New\Downloads\ghidra_11.0.2_PUBLIC_20240326\ghidra_11.0.2_PUBLIC\Ghidra\Features\Python\data\jython-2.7.3\Lib\urllib2.py", line 556, in http_error_default raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) urllib2.HTTPError: HTTP Error 404: Not Found

The URL opens in a browser (asks for API key, as expected). Not able to be called from Ghidra though for some reason. Have you ran into this? Is it a settings issue?

sugitime commented 2 months ago

I resolved this issue for myself in case anyone else has this issue.

If you want to pay for ChatGPT, you can just pay for an account and it will work.

If you want to use the free API, you need to do a tiny bit of work:

  1. I changed the code to use the ChatGPT 3.5 (gpt-3.5-turbo) engine here: https://github.com/evyatar9/GptHidra/blob/796c18eb03764fe38735f8d2348e097863cf648a/GptHidra.py#L28

  2. Add $5 worth of credit to your ChatGPT account and have billing info on your ChatGPT account

Once this is in place, it will work with the free API engine.

evyatar9 commented 1 month ago

Hi, You can use GptHidra-GPT-4

Thanks for your feedback