PaLM API and json

81 views Asked by At

I am trying to execute the following command in powershell:

curl "https://generativelanguage.googleapis.com/v1beta3/models/text-bison-001:generateText?key=AIzaSyAxHrnH91lSLOeaWs5Rda1_PTn-OnWN9Kg" -H 'Content-Type: application/json' -X POST -d '{ "prompt": { "text": "Write a story about a magic backpack"} }'

but receiving the following error:

"System.String" to type "System.Collections.IDictionary".
At line:1 char:140
+ ... SLOeaWs5Rda1_PTn-OnWN9Kg" -H 'Content-Type: application/json' -X POST ...
+                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Invoke-WebRequest], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

I tried the following command as some of them said to.

Get-Command curl

-----------     ----                                               -------    ------
Alias           curl -> Invoke-WebRequest

but Invoke-WebRequest also did not helped.

1

There are 1 answers

0
Mark McDonald On BEST ANSWER

From this:

"System.String" to type "System.Collections.IDictionary".
At line:1 char:140
+ ..." -H 'Content-Type: application/json' -X POST ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

It looks like PowerShell's curl doesn't support the same args as Linux's curl.

I would either switch to WSL to use real curl, or use native PowerShell like so:

Invoke-RestMethod `
  -Method POST `
  -Uri "https://generativelanguage.googleapis.com/v1beta3/models/text-bison-001:generateText?key=DO_NOT_SHARE_YOUR_KEY_ON_THE_INTERNET_EVER" `
  -Body '{ "prompt": { "text": "Write a story about a magic backpack"} }' `
  -ContentType "application/json"