ToB企服应用市场:ToB评测及商务社交产业平台

标题: 开发了一个Java库的Google Bard API,可以自动化与AI对话了 [打印本页]

作者: 千千梦丶琪    时间: 2023-4-4 14:12
标题: 开发了一个Java库的Google Bard API,可以自动化与AI对话了
开发了一个Java库的Google Bard API,可以自动化与AI对话了

Google Bard是Google提供的还在实验阶段的人工智能对话服务。这明显是对标ChatGPT来的,它可以提供更实时的答案,会基于Google强大的网页数据。
为了更方便的使用并实现自动化,我写了一个Java类库,GitHub仓库地址为:https://github.com/LarryDpk/Google-Bard
欢迎大家STAR...
如何使用

使用是非常简单的,只要网络通就可以了。
引入依赖
  1. <dependencies>
  2.     <dependency>
  3.         <groupId>com.pkslow</groupId>
  4.         <artifactId>google-bard</artifactId>
  5.         <version>0.0.1</version>
  6.     </dependency>
  7. </dependencies>
复制代码
拿到验证Token

目前没有用户名密码的方式,直接有Token就行。但这个要从网页上拿。它其实就是一个Cookie,名为__Secure-1PSID:

据说Google未来会开放API接口,拭目以待吧。
Java代码

两行代码即可:
  1. AIClient client = new GoogleBardClient(token);
  2. List<String> answers = client.ask("How to be a good father?");
复制代码
返回的是一个列表:
如果Google Bard能够回答问题,一般会给出三个答案。第一个是推荐的答案。
  1. for (int i = 0; i < answers.size(); i++) {
  2.     if (i == 0) {
  3.         System.out.println("### Recommended Answer");
  4.         System.out.println(answers.get(i));
  5.     } else {
  6.         System.out.println("### Answer " + i);
  7.         System.out.println(answers.get(i));
  8.     }
  9. }
复制代码
Google Bard目前还是实验阶段,只在美国英国可用,所以你懂的:
  1. NetworkUtils.setUpProxy("localhost", "7890");
复制代码
这个要在程序最开始设置。
我尝试的问题如答案

我问了一个问题:How to be a good father?
答案是Markdown格式的,我获得的答案如下:
Recommended Answer

Here are some tips on how to be a good father:
Being a good father is a lifelong journey. There is no one right way to do it. Just remember to be there for your child, be a good role model, and show them love.
Answer 1

Here are some tips on how to be a good father:
Being a good father is a lifelong journey. There is no one right way to do it. Just remember to be there for your child, be a good role model, and show them love.
Answer 2

Here are some tips on how to be a good father:
Being a good father is a lifelong journey. There will be times when you make mistakes, but that's okay. The important thing is to learn from your mistakes and keep trying to be the best father you can be.
Answer 3

Here are some tips on how to be a good father:
Being a good father is one of the most important things you can do in life. By following these tips, you can help your child grow into a happy, healthy, and successful adult.

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!




欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) Powered by Discuz! X3.4