google / generative-ai-docs

Documentation for Google's Gen AI site - including the Gemini API and Gemma
https://ai.google.dev
Apache License 2.0
1.69k stars 610 forks source link

PaLM API: "INVALID_ARGUMENT" error for prompt #58

Closed pentney closed 1 year ago

pentney commented 1 year ago

I know that I am successfully sending requests to the PaLM API because other prompts have succeeded. This one, however, returns an error:

{"prompt": {"text": "What tools are targets of this attack, if any? Respond in JSON.\n\n4 / 7Analysis After analyzing the captured samples, Sangfor found that it is nearlly identical to the first version in code structure. After launch, the virus will first create a note file (HOW T O BACK YOUR FILES.exe) and then disable the family group and then Windows defender . Subsequently , the virus will create an auto-startup item named WindowsUpdateCheck, which will be executed through CMD to delete disk volumes, stop database service, traverse and mount volumes and traverse disk files: 5 / 7 After encrypting files, the virus will duplicate the note file to the encrypted file directory: Finally , the virus executes command through CMD to delete the RDP connection and system logs and delete itself. Solutions Currently there is no decryption tool for victims. Y ou may isolate infected hosts and disconnect them from network. We recommend performing a virus scan and removal as soon as possible. Detection and Removal 6 / 7Sangfor EDR and NGAF products are capable of detecting and removing this ransom virus. Sangfor of fers customers and users free anti-malware software to scan for and remove the virus. Protection The Sangfor Security T eam recommends proactive protection, as there is no way to decrypt the files encrypted by majority of ransom viruses. 1. Fix the vulnerability quickly by installing the corresponding patch on the host. 2. Back up critical data files regularly to other hosts or storage devices. 3. Do not click on any email attachment from unknown sources and do not download any software from untrusted websites. 4. Disable unnecessary file sharing. 5. Strengthen your computer password and do not use the same passwords for multiple computers to avoid compromising a series of computers. 6. Disable RDP if it is unnecessary for your business. When computers are attacked, use Sangfor NGAF or EDR to block port 3389 and stop the virus from spreading. 7. Sangfor NGAF and EDR can prevent brute-force attacks. T urn on brute-force attack prevention on NGAF and enable Rules 1 1080051, 1 1080027 and 1 1080016. T urn on brute- force attack prevention on Sangfor EDR. 8. For Sangfor NGAF customers, update NGAF to version 8.0.5 and enable AI-based Sangfor Engine Zero to achieve the most comprehensive protection. 7 / 79. Deploy Sangfor security products and connect to cloud-based Sangfor Neural-X to detect new threats. 10. Sangfor SOC, featuring AI, is ready to quickly enhance security capabilities. SOC provides services including checks on device security policies, security threats and relevant vulnerabilities to ensure timely risk detection, remediation and prevention, as well as policy update. 11. Perform a security scan and virus removal on the entire network to enhance network security . We recommend Sangfor NGAF and EDR to detect, prevent and protect your internal network."}}

This parses as valid JSON, has what I believe to be a valid number of tokens, and is in the same format as other successful prompts, but I get this response.

{
  "error": {
    "code": 400,
    "message": "Invalid JSON payload received. Parsing terminated before end of input.\n\"}}\n                {\"prompt\": {\"text\": \n                    ^",
    "status": "INVALID_ARGUMENT"
  }
}

Am I missing something here?

markmcd commented 1 year ago

How are you making the request? cURL? Python?

It's hard to tell without seeing the full context, but my guess is that something is literally interpreting the \n before it makes the web request, so it breaks up the JSON into invalid chunks.

pentney commented 1 year ago

After experimenting some more, I realized this was happening only when I made repeated calls with similar, but slightly different text for the prompt, in succession. I could not reproduce it in other circumstances. Is there an intentional restriction on this? The request was made through the REST API.

markmcd commented 1 year ago

If you're getting Invalid JSON payload received, then yes, that's intentional if the JSON is malformed. Can you provide the text that is failing, and exactly how you executed it (e.g. show the full curl command, or code used to build the request)?

MarkDaoust commented 1 year ago
Parsing terminated before end of input.\n\"}}\n                {\"prompt\": {\"text\": \n                    ^",

That phrase seems to be from a proto parsing library.

Its not totally clear how the snippet after is meant to be parsed. But it looks like there's something in the json string before {"prompt". That doesn't make any sense since for generate_text, prompt is a top level key.

I'm able to reproduce the error by pasting two queries into curl:

curl -H 'Content-Type: application/json'  \
    -H "x-goog-api-key: ${PALM_API_KEY}" \
    -d '{"prompt": {text: "hello"} }  {"prompt": {text: "hello2"} }' \
    "https://generativelanguage.googleapis.com/v1beta2/models/text-bison-001:generateText"
{
  "error": {
    "code": 400,
    "message": "Invalid JSON payload received. Parsing terminated before end of input.\n {text: \"hello\"} }  {\"prompt\": {text: \"h\n                    ^",
    "status": "INVALID_ARGUMENT"
  }
}

I think this is a copy-paste error.