UiPath2025笔记第七节:B端Ai操控C端Rpa机器人
一、效果展示
当我们在B端机器输入ai指令时:打开ppt。Ai模型通过分析语境分析要执行的动作,进而执行对应的Rpa。
二、Ai端代码
作者使用的是DeepSeek模型,将这个功能封装在chat函数中了,然后一定要写好提示词模板!
public static String chat(String userInput) throws Exception {OkHttpClient client = new OkHttpClient();// 构建JSON对象JSONObject requestBody = new JSONObject();requestBody.put("model", "deepseek-v3.1-250821");JSONArray messages = new JSONArray();JSONObject systemMsg = new JSONObject();systemMsg.put("role", "system");systemMsg.put("content", "你是一个办公智能体,现在有两个功能供你选择,1是打开ppt,2是打开word 你要根据用户的输入内容选择哪一个功能、" +"若你能够判断出则给出回答:选择功能{数字},记住格式必须是:选择功能{数字},一定要带上{}!。如果你判断不出,则回复:请你输入正确的指令");messages.put(systemMsg);JSONObject userMsg = new JSONObject();userMsg.put("role", "user");userMsg.put("content", userInput);messages.put(userMsg);requestBody.put("messages", messages);RequestBody body = RequestBody.create(requestBody.toString(),MediaType.parse("application/json"));Request request = new Request.Builder().url("https://qianfan.baidubce.com/v2/chat/completions").post(body).addHeader("Authorization", "Bearer 你的密钥").addHeader("Content-Type", "application/json").build();Response response = client.newCall(request).execute();String responseBody = response.body().string();// 解析响应,只提取内容JSONObject jsonResponse = new JSONObject(responseBody);JSONArray choices = jsonResponse.getJSONArray("choices");JSONObject firstChoice = choices.getJSONObject(0);JSONObject message = firstChoice.getJSONObject("message");return message.getString("content");}
三、Rpa端代码演示
可以查看作者上一篇文章有详细解答
UiPath2025笔记第六节:java调试API触发器
这段代码主要是操控C端机器
public static String OpenPPT() {try {OkHttpClient client = new OkHttpClient().newBuilder().build();Request request = new Request.Builder().url("https://cloud.uipath.com/组织/租户/orchestrator_/t/498d0f54-7282-432f-adb8-c6c59699c798/123456").get().addHeader("Authorization", "Bearer 你的token").addHeader("Accept", "application/json").addHeader("Host", "cloud.uipath.com").build();Response response = client.newCall(request).execute();if (response.isSuccessful()) {String responseBody = response.body().string();return "打开ppt成功";} else {return "Request failed! Code: " + response.code() + ", Message: " + response.message();}} catch (Exception e) {return "Error: " + e.getMessage();}}
四、结语
这段代码仅仅是展示简单的流程:用户输入->Ai分析->Rpa执行