首个支持 Google PaLM 的 Java SDK 1.9.0 发布

推荐一套基于 SpringBoot 开发的全平台数据 (数据库管理工具) 功能比较完善,建议下载使用: https://github.com/EdurtIO/datacap 目前已经支持 40+ 多种数据源。国内首个应用 ChatGPT 到数据管理系统中项目。

推荐一套基于 SpringBoot 开发的简单、易用的开源权限管理平台,建议下载使用: https://github.com/devlive-community/authx

OpenAI Java SDK 为 Java 开发人员提供方便易用的 SDK 来与开放 AI 模型的 API 进行交互。

  • 支持 Google PaLM

没有得到授权用户可以到 https://developers.generativeai.google/products/palm 申请授权

创建 Completion

try(OpenAiClient client=OpenAiClient.builder()
        .provider(ProviderModel.GOOGLE_PALM)
        .model(CompletionModel.TEXT_BISON_001)
        .apiKey(System.getProperty("google.token"))
        .build())
{
    PromptEntity prompt = PromptEntity.builder()
        .text("How to create a completion")
        .build();
    CompletionEntity configure = CompletionEntity.builder()
        .prompt(prompt)
        .build();
    client.createPaLMCompletion(configure).getCandidates();
}
 

创建 Chat

try(OpenAiClient client=OpenAiClient.builder()
        .provider(ProviderModel.GOOGLE_PALM)
        .model(CompletionModel.CHAT_BISON_001)
        .apiKey(System.getProperty("google.token"))
        .build())
{
    List<MessageEntity> messages = Lists.newArrayList();
    messages.add(MessageEntity.builder()
        .content("Hello, my name is openai-java-sdk")
        .build());

    PromptEntity prompt = PromptEntity.builder()
        .messages(messages)
        .build();

    ChatEntity configure = ChatEntity.builder()
        .prompt(prompt)
        .build();

    client.createPaLMChat(configure)
        .getCandidates()
        .forEach(System.out::println);
}
 

如何使用?

<properties>
    <openai.version>1.9.0</openai.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.devlive.sdk</groupId>
        <artifactId>openai-java-sdk</artifactId>
        <version>${openai.version}</version>
    </dependency>
</dependencies>

猜你喜欢

转载自www.oschina.net/news/254841