LarryDpk / Google-Bard

A Java Lib for Google-Bard API (Reverse engineering of Google's Bard API)
MIT License
88 stars 26 forks source link

Error testing the example provided in the documentation #14

Open jabrena opened 1 year ago

jabrena commented 1 year ago

Hi,

I am testing your library with the example from the project:

Code:

public class BardDemo {

    public static void main(String[] args) {
        AIClient client = new GoogleBardClient("MY_TOKEN");
        Answer answer = client.ask("What is the date today?");
    }
}

but I don´t understand the following error:

17:31:59.717 [BardDemo.main()] INFO com.pkslow.ai.util.WebUtils -- Creating OkHttpClient with timeout PT5M
17:32:00.011 [BardDemo.main()] INFO com.pkslow.ai.util.WebUtils -- OkHttpClient created
17:32:00.731 [BardDemo.main()] INFO com.pkslow.ai.GoogleBardClient -- getSNlM0e Response code: 200
17:32:00.809 [BardDemo.main()] INFO com.pkslow.ai.GoogleBardClient -- calling Bard with request BardRequest{strSNlM0e=null, question=What is the date today?, conversationId=, responseId=, choiceId=}
17:32:00.814 [BardDemo.main()] ERROR com.pkslow.ai.GoogleBardClient -- Failed to get answer: 
java.lang.NullPointerException: Parameter specified as non-null is null: method okhttp3.FormBody$Builder.add, parameter value
        at okhttp3.FormBody$Builder.add(FormBody.kt)
        at com.pkslow.ai.util.BardUtils.buildRequestBodyForAsk(BardUtils.java:100)
        at com.pkslow.ai.util.BardUtils.createPostRequestForAsk(BardUtils.java:86)
        at com.pkslow.ai.GoogleBardClient.callBardToAsk(GoogleBardClient.java:89)
        at com.pkslow.ai.GoogleBardClient.ask(GoogleBardClient.java:53)
        at BardDemo.main(BardDemo.java:15)
        at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:254)
        at java.base/java.lang.Thread.run(Thread.java:833)

I am using this version of your project:

https://mvnrepository.com/artifact/com.pkslow/google-bard

        <dependency>
            <groupId>com.pkslow</groupId>
            <artifactId>google-bard</artifactId>
            <version>0.3.3</version>
        </dependency>

Can you help me?

Many thanks in advance

Juan Antonio

LarryDpk commented 1 year ago

There's some change for the auth on Google Bard side. working on this to find a better solution.

jabrena commented 1 year ago

Oki, tell me when I can test again the library

LarryDpk commented 1 year ago

open bard with incognito mode and get the token again can work for a short time. now Google makes the token expire soon.

jabrena commented 1 year ago

I will try today

jabrena commented 1 year ago

Hi,

I tried again but it didn´t work using the approach to open an annonimous browser:

Example: https://github.com/jabrena/spring-boot-user-beans/blob/be736d0af419a749724da3f3a54174434b8fe916/spring-boot-starter-user-beans/src/test/java/io/github/jabrena/GoogleBardTest.java

LarryDpk commented 1 year ago

From this issue https://github.com/acheong08/Bard/issues/68#issuecomment-1637132696 we can see: Bard now requires 3 different types of cookies Secure-1PAPISID, Secure-1PSIDTS, __Secure-1PSIDCC and one of them is rotated every 20 mins. This makes the whole implementation becomes impossible.

I will add more cookies and try. But Bard is making more restriction.

jabrena commented 1 year ago

Oki, if you have the Curl requests, I could test from my side in Spain.

LarryDpk commented 1 year ago

Strange, it's ok for me. Reloign incognito mode and get the new token:

image

Successful call:

image
estebangarciaalonso commented 1 year ago

It worked the first time as you said and then it stopped working...

LarryDpk commented 1 year ago

can't do anything due to Google Bard Limit

LarryDpk commented 1 year ago

Now it needs two cookies, please use latest version