设为首页 加入收藏

TOP

开发了一个Java库的Google Bard API,可以自动化与AI对话了(一)
2023-07-25 21:35:44 】 浏览:57
Tags:Java Google Bard API

开发了一个Java库的Google Bard API,可以自动化与AI对话了

Google Bard是Google提供的还在实验阶段的人工智能对话服务。这明显是对标ChatGPT来的,它可以提供更实时的答案,会基于Google强大的网页数据。

为了更方便的使用并实现自动化,我写了一个Java类库,GitHub仓库地址为:https://github.com/LarryDpk/Google-Bard

欢迎大家STAR...

如何使用

使用是非常简单的,只要网络通就可以了。

引入依赖

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

拿到验证Token

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

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

Java代码

两行代码即可:

AIClient client = new GoogleBardClient(token);
List<String> answers = client.ask("How to be a good father?");

返回的是一个列表:
如果Google Bard能够回答问题,一般会给出三个答案。第一个是推荐的答案。

for (int i = 0; i < answers.size(); i++) {
    if (i == 0) {
        System.out.println("### Recommended Answer");
        System.out.println(answers.get(i));
    } else {
        System.out.println("### Answer " + i);
        System.out.println(answers.get(i));
    }
}

Google Bard目前还是实验阶段,只在美国英国可用,所以你懂的:

NetworkUtils.setUpProxy("localhost", "7890");

这个要在程序最开始设置。

我尝试的问题如答案

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

Here are some tips on how to be a good father:

  • Spend time with your child. Quality time is essential for building a strong relationship with your child. Make time for activities that you both enjoy, such as playing games, going to the park, or reading stories.
  • Be a good role model. Children learn by watching the adults in their lives. Set a good example by being honest, kind, and respectful.
  • Be supportive. Let your child know that you are there for them, no matter what. Offer them your support and encouragement, especially when they are going through tough times.
  • Be a good communicator. Talk to your child about their day, their feelings, and their hopes and dreams. Let them know that they can come to you with anything.
  • Be patient. Parenting is a journey, not a destination. There will be times when you feel frustrated or overwhelmed. Remember to be patient with yourself and your child.
  • Be loving. The most important thing a father can do is to love his child unconditionally. Let your child know that you love them every day.

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:

  • Spend time with your child. Quality time is essential for building a strong relationship with your child. Make time for activities that you both enjoy, such as playing games, going to the park, or reading stories.
  • Be a good role model. Children learn by watching the adults in their lives. Set a good example by being honest, kind, and respectful.
  • Be supportive. Let your child know that you are there for them, no matter what. Offer them your support and encouragement, especially when they are going through tough times.
  • Be a good communicator. Talk to your child about their day, their feelings, and their hopes and dreams. Let them know that they can come to you with anything.
  • Be patient. Parenting is a journey, not a destination. There will be times when you feel frustrated or overwhelmed. Remember to be patient with yourself and your child.
  • Be loving. The most important thing a father can do is to love his child unconditionally. Let your child know t
首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇spring源码环境搭建 下一篇Java学习十一

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目