Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

malformed error from openai #3

Open
ddmunhoz opened this issue Dec 3, 2024 · 4 comments
Open

malformed error from openai #3

ddmunhoz opened this issue Dec 3, 2024 · 4 comments

Comments

@ddmunhoz
Copy link

ddmunhoz commented Dec 3, 2024

Hi @LiangWei88 !

Great work! I was trying to get it to work and hit the following issue, the request to OAI was somehow being malformed and it was complaining that you were including both keys oai_key, oai_url on the request.

{
  "error": {
    "message": "Unrecognized request arguments supplied: oai_key, oai_url",
    "type": "invalid_request_error",
    "param": null,
    "code": null
  }
}

Here is the payload generate by your extension:

{
    "response": {
        "data": {
            "oai_url": "https://api.openai.com/v1/chat/completions",
            "oai_key": "sk-OPEN_AI_KEY",
            "model": "gpt-3.5-turbo",
            "messages": [
                {
                    "role": "system",
                    "content": "Please provide a  summary of the following "
                },
                {
                    "role": "user",
                    "content": "input: \nimg: `image`\n\nPresident Biden granted blanket clemency to stop his son from being prosecuted by the Trump administration for his foreign business. Experts reached for historical parallels.\n\nPresident Biden’s pardon for his son not only allowed him to escape consequences from his current convictions, but likely for any crimes he might have committed in the past 11 years.\n\nThat sweeping amnesty is raising awkward historical comparisons and sharp questions about the use of presidential clemency.\n\nIt also has inflamed a debate about who deserves mercy and for what, while underscoring the Biden family’s concerns about Hunter Biden’s vulnerability to prosecution related to his foreign business activities. Experts searched for an apt comparison, finding some similarities to the pardons granted by Gerald R. Ford to`Richard M. Nixon`; Andrew Johnson to`former Confederate soldiers`; George H.W. Bush to`Iran-contra figures`; and to those`issued`to`more distant family members`by President Bill Clinton and by Donald J. Trump during his first term.\n\nYet, none of those pardons seemed to hit as close to home for the presidents who issued them, nor did they cover as broad a range of activity over as long a period of time, experts said.\n\n“It is extraordinarily hazardous to use the pardon power in a case where the person is an intimate of the president,” said Aziz Z. Huq, a professor at the University of Chicago Law School.\n\nMr. Huq, who`warned against Mr. Trump pardoning himself`at the end of his first term, said President Biden’s pardon of his son “really does strike at the rule of law.”\n\nWe are having trouble retrieving the article content.\n\nPlease enable JavaScript in your browser settings.\n\nThank you for your patience while we verify access. If you are in Reader mode please exit and `log into` your Times account, or `subscribe` for all of The Times.\n\nThank you for your patience while we verify access.\n\nAlready a subscriber? `Log in`.\n\nWant all of The Times? `Subscribe`.\n\nimg: ``\n\n© Haiyun Jiang for The New York Times\n\nHunter Biden outside the courthouse in Wilmington, Del., in June."
                }
            ],
            "max_tokens": 2048,
            "temperature": 0.7,
            "n": 1
        },
        "provider": "openai",
        "error": null
    },
    "status": 200
}

So I went to script.js line 105 and implemented the following fix:

   const ourl = oaiParams.oai_url;
    const okey = oaiParams.oai_key;
    delete oaiParams.oai_url;
    delete oaiParams.oai_key;
    const response = await fetch(ourl, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'Authorization': `Bearer ${okey}`
      },
      body: JSON.stringify(oaiParams)
    });

I'm not a PHP/JS dev. So I'll let you evaluate and apply the proper fix. But the one above was capable to get me up and running.

Thanks for the hard work!

@LiangWei88
Copy link
Owner

I didn't actually use the open AI interface, I just used a service that is compatible with it. It may be that the rigor of parameter detection is different. I will see how to modify it and release a new version. Thank you for your reminder.

@ddmunhoz
Copy link
Author

ddmunhoz commented Dec 4, 2024

No problem @LiangWei88, I can put a PR that fixes it as well. Let me know and I’ll do it.

@LiangWei88
Copy link
Owner

You are very welcome to submit a PR, thank you very much

@LiangWei88
Copy link
Owner

Submit on the dev branch if possible

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants