您现在的位置是:首页 > 文章详情

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

日期:2023-08-22点击:645

推荐一套基于 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>
原文链接:https://www.oschina.net/news/254841
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章