旅游宣传网站建设方案百度seo优化怎么做
记录一下学习coze官方提供的java-sdk的过程
官方参考文档
一、搭建知识库
1、登录coze后,点击工作空间-资源库,点击右上角的资源,点击知识库
2、输入知识库名词以及知识库的描述
3、选择要上传的文档类型,点击创建并导入,上传文档,点击下一步
4、选择分段策略,我这里选择的是自定义,把知识库按照###进行分片,点击下一步
5、看一下切片结果是否符合预期,没问题就点击下一步
至此知识库就创建完成了。
二、创建智能体
1、点击项目开发、创建
2、输入智能体名称和描述,选择创建的知识库
3、添加知识库
4、输入一段话,测试
5、发布
三、创建token
1、创建新令牌
2、保存好创建的toekn,SDK调用时需要用到
四、SDK调用
public class StreamChatExample {public static void main(String[] args) {// 申请的令牌String token = COZE_CONSTARNTS.coze_token;//智能体IDString botID = COZE_CONSTARNTS.bot_id;//user_id:标识当前与智能体交互的用户。调试时可将此参数固定为一个任意字符串,例如 123。String userID = "123";TokenAuth authCli = new TokenAuth(token);// Init the Coze client through the access_token.CozeAPI coze =new CozeAPI.Builder().baseURL(Consts.COZE_CN_BASE_URL).auth(authCli).readTimeout(10000).build();;/** Step one, create chat* Call the coze.chat().stream() method to create a chat. The create method is a streaming* chat and will return a Flowable ChatEvent. Developers should iterate the iterator to get* chat event and handle them.* */CreateChatReq req =CreateChatReq.builder().botID(botID).userID(userID).messages(Collections.singletonList(Message.buildUserQuestionText("接驳线路的生成原理是什么"))).build();Flowable<ChatEvent> resp = coze.chat().stream(req);resp.blockingForEach(event -> {if (ChatEventType.CONVERSATION_MESSAGE_DELTA.equals(event.getEvent())) {System.out.print(event.getMessage().getContent());}if (ChatEventType.CONVERSATION_CHAT_COMPLETED.equals(event.getEvent())) {System.out.println("Token usage:" + event.getChat().getUsage().getTokenCount());}});System.out.println("done");coze.shutdownExecutor();}
}
至此完成SDK调用的实例