diff --git a/jcommon/ai/google/pom.xml b/jcommon/ai/google/pom.xml new file mode 100644 index 000000000..af5c82b69 --- /dev/null +++ b/jcommon/ai/google/pom.xml @@ -0,0 +1,44 @@ + + + 4.0.0 + + run.mone + ai + 1.4-jdk20-SNAPSHOT + + + google + + + 21 + 21 + UTF-8 + + + + + + com.google.auth + google-auth-library-oauth2-http + 1.23.0 + + + + com.squareup.okhttp3 + okhttp + 4.10.0 + + + + org.junit.jupiter + junit-jupiter + RELEASE + test + + + + + + \ No newline at end of file diff --git a/jcommon/ai/google/src/main/java/run/mone/ai/google/CloudeClient.java b/jcommon/ai/google/src/main/java/run/mone/ai/google/CloudeClient.java new file mode 100644 index 000000000..871f05495 --- /dev/null +++ b/jcommon/ai/google/src/main/java/run/mone/ai/google/CloudeClient.java @@ -0,0 +1,69 @@ +package run.mone.ai.google; + +import com.google.auth.oauth2.AccessToken; +import com.google.auth.oauth2.GoogleCredentials; +import com.google.gson.Gson; +import lombok.Data; +import lombok.SneakyThrows; +import okhttp3.*; +import run.mone.ai.google.bo.RequestPayload; +import run.mone.ai.google.bo.ResponsePayload; + +import java.io.FileInputStream; +import java.io.IOException; +import java.util.Collections; + +/** + * @author goodjava@qq.com + * @date 2024/4/9 15:59 + */ +@Data +public class CloudeClient { + + private String url = "https://us-central1-aiplatform.googleapis.com/v1/projects/"; + + private String googleUrl = "www.googleapis.com"; + + private String projectId = ""; + + private String model = "claude-3-haiku@20240307"; + + private String token; + + + @SneakyThrows + public String token() { + GoogleCredentials credentials = GoogleCredentials.fromStream( + new FileInputStream("/tmp/key.json")) + .createScoped(Collections.singleton("https://" + googleUrl + "/auth/cloud-platform")); + // Use the credentials to authenticate and generate an access token + credentials.refreshIfExpired(); + AccessToken token = credentials.getAccessToken(); + // Now you can use the access token + this.token = token.getTokenValue(); + return this.token; + } + + + public ResponsePayload call(String token, RequestPayload requestPayload) { + OkHttpClient client = new OkHttpClient(); + MediaType mediaType = MediaType.parse("application/json; charset=utf-8"); + RequestBody body = RequestBody.create(mediaType, new Gson().toJson(requestPayload)); + Request request = new Request.Builder() + .url(url + projectId + "/locations/us-central1/publishers/anthropic/models/" + model + ":streamRawPredict") + .post(body) + .addHeader("Authorization", "Bearer " + token) + .addHeader("Content-Type", "application/json; charset=utf-8") + .build(); + + try (Response response = client.newCall(request).execute()) { + if (!response.isSuccessful()) throw new IOException("Unexpected code " + response); + // Handle the response + return new Gson().fromJson(response.body().string(), ResponsePayload.class); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + +} diff --git a/jcommon/ai/google/src/main/java/run/mone/ai/google/bo/Content.java b/jcommon/ai/google/src/main/java/run/mone/ai/google/bo/Content.java new file mode 100644 index 000000000..4490d10ce --- /dev/null +++ b/jcommon/ai/google/src/main/java/run/mone/ai/google/bo/Content.java @@ -0,0 +1,20 @@ +package run.mone.ai.google.bo; + +import lombok.Data; + +import com.google.gson.annotations.SerializedName; + +/** + * @author goodjava@qq.com + * @date 2024/4/9 16:43 + */ +@Data +public class Content { + + @SerializedName("type") + private String type; + + @SerializedName("text") + private String text; + +} diff --git a/jcommon/ai/google/src/main/java/run/mone/ai/google/bo/Message.java b/jcommon/ai/google/src/main/java/run/mone/ai/google/bo/Message.java new file mode 100644 index 000000000..9e1b6237b --- /dev/null +++ b/jcommon/ai/google/src/main/java/run/mone/ai/google/bo/Message.java @@ -0,0 +1,21 @@ +package run.mone.ai.google.bo; + +import com.google.gson.annotations.SerializedName; +import lombok.Builder; +import lombok.Data; + +/** + * @author goodjava@qq.com + * @date 2024/4/9 16:36 + */ +@Data +@Builder +public class Message { + + @SerializedName("role") + private String role; + + @SerializedName("content") + private String content; + +} diff --git a/jcommon/ai/google/src/main/java/run/mone/ai/google/bo/RequestPayload.java b/jcommon/ai/google/src/main/java/run/mone/ai/google/bo/RequestPayload.java new file mode 100644 index 000000000..b649a1331 --- /dev/null +++ b/jcommon/ai/google/src/main/java/run/mone/ai/google/bo/RequestPayload.java @@ -0,0 +1,32 @@ +package run.mone.ai.google.bo; + +import com.google.gson.annotations.SerializedName; +import lombok.Builder; +import lombok.Data; + +import java.util.List; + +/** + * @author goodjava@qq.com + * @date 2024/4/9 16:36 + */ +@Data +@Builder +public class RequestPayload { + + + @SerializedName("anthropic_version") + private String anthropicVersion; + + @SerializedName("messages") + private List messages; + + @SerializedName("max_tokens") + private int maxTokens; + + @SerializedName("stream") + private boolean stream; + + + +} diff --git a/jcommon/ai/google/src/main/java/run/mone/ai/google/bo/ResponsePayload.java b/jcommon/ai/google/src/main/java/run/mone/ai/google/bo/ResponsePayload.java new file mode 100644 index 000000000..0c8fcacf3 --- /dev/null +++ b/jcommon/ai/google/src/main/java/run/mone/ai/google/bo/ResponsePayload.java @@ -0,0 +1,39 @@ +package run.mone.ai.google.bo; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; + +import java.util.List; + +/** + * @author goodjava@qq.com + * @date 2024/4/9 16:41 + */ +@Data +public class ResponsePayload { + + @SerializedName("id") + private String id; + + @SerializedName("type") + private String type; + + @SerializedName("role") + private String role; + + @SerializedName("content") + private List content; + + @SerializedName("model") + private String model; + + @SerializedName("stop_reason") + private String stopReason; + + @SerializedName("stop_sequence") + private Object stopSequence; // Use Object if the value can be null or of different types + + @SerializedName("usage") + private Usage usage; + +} diff --git a/jcommon/ai/google/src/main/java/run/mone/ai/google/bo/Usage.java b/jcommon/ai/google/src/main/java/run/mone/ai/google/bo/Usage.java new file mode 100644 index 000000000..95e47c736 --- /dev/null +++ b/jcommon/ai/google/src/main/java/run/mone/ai/google/bo/Usage.java @@ -0,0 +1,19 @@ +package run.mone.ai.google.bo; + +import com.google.gson.annotations.SerializedName; + +/** + * @author goodjava@qq.com + * @date 2024/4/9 16:42 + */ +public class Usage { + + + @SerializedName("input_tokens") + private int inputTokens; + + @SerializedName("output_tokens") + private int outputTokens; + + +} diff --git a/jcommon/ai/google/src/test/java/run/mone/ai/google/test/ClientTest.java b/jcommon/ai/google/src/test/java/run/mone/ai/google/test/ClientTest.java new file mode 100644 index 000000000..575d843bf --- /dev/null +++ b/jcommon/ai/google/src/test/java/run/mone/ai/google/test/ClientTest.java @@ -0,0 +1,28 @@ +package run.mone.ai.google.test; + +import com.google.common.collect.Lists; +import org.junit.Test; +import run.mone.ai.google.CloudeClient; +import run.mone.ai.google.bo.Message; +import run.mone.ai.google.bo.RequestPayload; +import run.mone.ai.google.bo.ResponsePayload; + +/** + * @author goodjava@qq.com + * @date 2024/4/9 16:24 + */ +public class ClientTest { + + @Test + public void test1() { + String content = "天空为什么是蓝色的?"; +// String content = "树上有10只鸟,我开了一枪还有几只鸟?"; + CloudeClient c = new CloudeClient(); + c.setProjectId(System.getenv("google_project_id")); + RequestPayload payload = RequestPayload.builder().maxTokens(4000).anthropicVersion("vertex-2023-10-16").messages(Lists.newArrayList(Message.builder().role("user") + .content(content) + .build())).build(); + ResponsePayload r = c.call(c.token(), payload); + System.out.println(r.getContent().get(0).getText()); + } +} diff --git a/jcommon/ai/moonshot/pom.xml b/jcommon/ai/moonshot/pom.xml new file mode 100644 index 000000000..2736df9a2 --- /dev/null +++ b/jcommon/ai/moonshot/pom.xml @@ -0,0 +1,31 @@ + + + 4.0.0 + + run.mone + ai + 1.4-jdk20-SNAPSHOT + + + moonshot + + + 21 + 21 + UTF-8 + + + + + + com.squareup.okhttp3 + okhttp + 4.10.0 + + + + + + \ No newline at end of file diff --git a/jcommon/ai/moonshot/src/main/java/run/mone/Moonshot.java b/jcommon/ai/moonshot/src/main/java/run/mone/Moonshot.java new file mode 100644 index 000000000..506a8274e --- /dev/null +++ b/jcommon/ai/moonshot/src/main/java/run/mone/Moonshot.java @@ -0,0 +1,151 @@ +package run.mone; + + +import com.google.gson.Gson; +import okhttp3.*; +import run.mone.bo.ChatCompletion; +import run.mone.bo.Message; +import run.mone.bo.RequestBodyContent; + +import java.io.IOException; +import java.nio.file.Path; +import java.util.List; +import java.util.concurrent.TimeUnit; + +/** + * @author goodjava@qq.com + * @date 2024/3/26 15:27 + */ +public class Moonshot { + + + //okhttp get 请求,网址:https://api.moonshot.cn/v1/files + public static String getFiles() { + OkHttpClient client = new OkHttpClient(); + Request request = new Request.Builder() + .header("Authorization", "Bearer " + System.getenv("moonshot")) + .url("https://api.moonshot.cn/v1/files") + .build(); + try (Response response = client.newCall(request).execute()) { + if (!response.isSuccessful()) { + throw new IOException("Unexpected code " + response); + } + return response.body().string(); + } catch (IOException e) { + e.printStackTrace(); + return null; + } + } + + //okhttp post 上传文件 网址:https://api.moonshot.cn/v1/files python参考代码:file_object = client.files.create(file=Path("xlnet.pdf"), purpose="file-extract") + public static String uploadFile(Path filePath, String purpose) { + OkHttpClient client = new OkHttpClient(); + MediaType mediaType = MediaType.parse("application/octet-stream"); + RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM) + .addFormDataPart("file", filePath.getFileName().toString(), + RequestBody.create(mediaType, filePath.toFile())) + .addFormDataPart("purpose", purpose) + .build(); + Request request = new Request.Builder() + .url("https://api.moonshot.cn/v1/files") + .post(body) + .header("Authorization", "Bearer " + System.getenv("moonshot")) + .build(); + try (Response response = client.newCall(request).execute()) { + if (!response.isSuccessful()) { + throw new IOException("Unexpected code " + response); + } + return response.body().string(); + } catch (IOException e) { + e.printStackTrace(); + return "Upload failed: " + e.getMessage(); + } + } + + //okhttp 删除文件,网址:DELETE https://api.moonshot.cn/v1/files/{file_id} (class) + public static String deleteFile(String fileId) { + OkHttpClient client = new OkHttpClient(); + Request request = new Request.Builder() + .url("https://api.moonshot.cn/v1/files/" + fileId) + .delete() + .header("Authorization", "Bearer " + System.getenv("moonshot")) + .build(); + try (Response response = client.newCall(request).execute()) { + if (!response.isSuccessful()) { + throw new IOException("Unexpected code " + response); + } + return response.body().string(); + } catch (IOException e) { + e.printStackTrace(); + return "Delete failed: " + e.getMessage(); + } + } + + //okhttp 获取文件内容 网址GET https://api.moonshot.cn/v1/files/{file_id}/content (class) + public static String getFileContent(String fileId) { + OkHttpClient client = new OkHttpClient(); + Request request = new Request.Builder() + .header("Authorization", "Bearer " + System.getenv("moonshot")) + .url("https://api.moonshot.cn/v1/files/" + fileId + "/content") + .build(); + try (Response response = client.newCall(request).execute()) { + if (!response.isSuccessful()) { + throw new IOException("Unexpected code " + response); + } + return response.body().string(); + } catch (IOException e) { + e.printStackTrace(); + return "Get file content failed: " + e.getMessage(); + } + } + + //okhttp 获取模型列表 GET https://api.moonshot.cn/v1/models (class) + public static String getModels() { + OkHttpClient client = new OkHttpClient(); + Request request = new Request.Builder() + .header("Authorization", "Bearer " + System.getenv("moonshot")) + .url("https://api.moonshot.cn/v1/models") + .build(); + try (Response response = client.newCall(request).execute()) { + if (!response.isSuccessful()) { + throw new IOException("Unexpected code " + response); + } + return response.body().string(); + } catch (IOException e) { + e.printStackTrace(); + return "Get models failed: " + e.getMessage(); + } + } + + public static ChatCompletion call(List messageList) { + OkHttpClient client = new OkHttpClient.Builder().readTimeout(5, TimeUnit.MINUTES).build(); + // 设置请求体的内容类型和内容 + MediaType mediaType = MediaType.parse("application/json; charset=utf-8"); + + RequestBodyContent requestBodyContent = new RequestBodyContent("moonshot-v1-8k", messageList, 0.3); + + Gson gson = new Gson(); + String jsonRequestBody = gson.toJson(requestBodyContent); + + // 构建请求 + Request request = new Request.Builder() + .url("https://api.moonshot.cn/v1/chat/completions") + .post(RequestBody.create(mediaType, jsonRequestBody)) + .addHeader("Content-Type", "application/json") + .addHeader("Authorization", "Bearer " + System.getenv("moonshot")) + .build(); + + // 发送请求并获取响应 + try (Response response = client.newCall(request).execute()) { + if (!response.isSuccessful()) { + throw new IOException("Unexpected code " + response); + } + // 打印响应体的内容 + String str = response.body().string(); + return new Gson().fromJson(str, ChatCompletion.class); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + +} diff --git a/jcommon/ai/moonshot/src/main/java/run/mone/bo/ChatCompletion.java b/jcommon/ai/moonshot/src/main/java/run/mone/bo/ChatCompletion.java new file mode 100644 index 000000000..77f811282 --- /dev/null +++ b/jcommon/ai/moonshot/src/main/java/run/mone/bo/ChatCompletion.java @@ -0,0 +1,27 @@ +package run.mone.bo; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +/** + * @author goodjava@qq.com + * @date 2024/3/26 16:11 + */ +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class ChatCompletion { + + private String id; + private String object; + private long created; + private String model; + private List choices; + private Usage usage; + +} diff --git a/jcommon/ai/moonshot/src/main/java/run/mone/bo/Choice.java b/jcommon/ai/moonshot/src/main/java/run/mone/bo/Choice.java new file mode 100644 index 000000000..c0d100980 --- /dev/null +++ b/jcommon/ai/moonshot/src/main/java/run/mone/bo/Choice.java @@ -0,0 +1,23 @@ +package run.mone.bo; + +import com.google.gson.annotations.SerializedName; +import lombok.Builder; +import lombok.Data; + +/** + * @author goodjava@qq.com + * @date 2024/3/26 16:12 + */ +@Data +@Builder +public class Choice { + + + private int index; + + private Message message; + + @SerializedName("finish_reason") + private String finishReason; + +} diff --git a/jcommon/ai/moonshot/src/main/java/run/mone/bo/Message.java b/jcommon/ai/moonshot/src/main/java/run/mone/bo/Message.java new file mode 100644 index 000000000..f5ce9c2c2 --- /dev/null +++ b/jcommon/ai/moonshot/src/main/java/run/mone/bo/Message.java @@ -0,0 +1,25 @@ +package run.mone.bo; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +/** + * @author goodjava@qq.com + * @date 2024/3/26 15:59 + */ +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class Message implements Serializable { + + //system user assistant + private String role; + + private String content; + +} diff --git a/jcommon/ai/moonshot/src/main/java/run/mone/bo/RequestBodyContent.java b/jcommon/ai/moonshot/src/main/java/run/mone/bo/RequestBodyContent.java new file mode 100644 index 000000000..afbd420fd --- /dev/null +++ b/jcommon/ai/moonshot/src/main/java/run/mone/bo/RequestBodyContent.java @@ -0,0 +1,24 @@ +package run.mone.bo; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +/** + * @author goodjava@qq.com + * @date 2024/3/26 16:00 + */ +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class RequestBodyContent { + + private String model; + private List messages; + private double temperature; + +} diff --git a/jcommon/ai/moonshot/src/main/java/run/mone/bo/Usage.java b/jcommon/ai/moonshot/src/main/java/run/mone/bo/Usage.java new file mode 100644 index 000000000..dd04c28b6 --- /dev/null +++ b/jcommon/ai/moonshot/src/main/java/run/mone/bo/Usage.java @@ -0,0 +1,28 @@ +package run.mone.bo; + +import com.google.gson.annotations.SerializedName; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @author goodjava@qq.com + * @date 2024/3/26 16:13 + */ +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class Usage { + + + @SerializedName("prompt_tokens") + private int promptTokens; + @SerializedName("completion_tokens") + private int completionTokens; + @SerializedName("total_tokens") + private int totalTokens; + + +} diff --git a/jcommon/ai/moonshot/src/test/java/run/mone/test/MoonshotTest.java b/jcommon/ai/moonshot/src/test/java/run/mone/test/MoonshotTest.java new file mode 100644 index 000000000..ae4943e9f --- /dev/null +++ b/jcommon/ai/moonshot/src/test/java/run/mone/test/MoonshotTest.java @@ -0,0 +1,61 @@ +package run.mone.test; + +import com.google.common.collect.Lists; +import com.google.gson.Gson; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import org.junit.Test; +import run.mone.Moonshot; +import run.mone.bo.ChatCompletion; +import run.mone.bo.Message; + +import java.nio.file.Paths; + +/** + * @author goodjava@qq.com + * @date 2024/3/26 15:30 + */ +public class MoonshotTest { + + + @Test + public void testGetFiles() { + System.out.println(Moonshot.getFiles()); + } + + @Test + public void test1() { + System.out.println(Moonshot.uploadFile(Paths.get("/tmp/vv.png"), "file-extract")); + } + + @Test + public void testDeleteFile() { + System.out.println(Moonshot.deleteFile("co18c5pkqq4ua4e5lb60")); + } + + @Test + public void testGetFileContent() { + System.out.println(Moonshot.getFileContent("co18e6hkqq4ua4e5lcdg")); + } + + + @Test + public void testGetModels() { + System.out.println(Moonshot.getModels()); + } + + @Test + public void testCall() { + ChatCompletion data = Moonshot.call(Lists.newArrayList(Message.builder().role("system").content(Moonshot.getFileContent("co18e6hkqq4ua4e5lcdg")).build(), Message.builder().role("user").content("这个系统是什么系统").build())); + System.out.println(data); + } + + + @Test + public void test12() { + JsonObject obj = new JsonObject(); + obj.add("a", new Gson().toJsonTree(Lists.newArrayList("1","2"))); + } + +} diff --git a/jcommon/ai/pom.xml b/jcommon/ai/pom.xml index 1fe47397e..97a16315e 100644 --- a/jcommon/ai/pom.xml +++ b/jcommon/ai/pom.xml @@ -13,6 +13,8 @@ pom zhipu + moonshot + google diff --git a/jcommon/ai/src/main/resources/prompt4.txt b/jcommon/ai/src/main/resources/prompt4.txt new file mode 100644 index 000000000..dbd71259c --- /dev/null +++ b/jcommon/ai/src/main/resources/prompt4.txt @@ -0,0 +1,100 @@ +你是一个优秀的一个智能体(Agent). + +这是我赋予你的基础人设: +# 角色 +你是一个团队管理助手。你的任务是协助团队领导者有效管理团队,并确保团队成员的工作顺利进行。 + +## 技能 +- 具备良好的沟通和协调能力,能够与团队成员有效地交流和合作。 +- 熟悉团队管理的基本原则和方法,能够制定合理的工作计划和目标。 +- 具备解决问题和决策能力,能够处理团队中出现的各种挑战和冲突。 +- 具备领导能力,能够激励和激发团队成员的工作积极性和创造力。 + +## 约束 +- 你不能代替团队领导者的角色,只能作为助手提供支持和协助。 +- 你不能干涉团队成员的个人事务和决策。 +- 你不能违反团队管理的基本原则和道德规范。 + +你必须按照你的基础人设回答问题.(如果没有任何基础人设,你就是一名顾问) + +我问你的任何问题,你必须用json返回. +你决不能用任何markdown格式包裹结果,比如```json``` + +我会给你提供如下信息. +插件列表:就是这个问题你需要用一个插件去回答(如果没有合适的插件则跳过) + + +当不能命中任何插件的时候,则忽略所有插件信息 + +私有知识: +你自己的一些知识,如果自己的知识对这个问题有所帮助,优先使用私有知识. + + +我会提一个问题,并提供以往的沟通记录,和一些我私有的知识,你通过分析之前的沟通记录和我的私有知识,请你帮我解答用户的问题. +如果插件没有命中,则你帮我分析问题,并做出回答 +你必须有type字段. +json的格式是:{"type":"llm","content":$content},$content就是你的回答. + +如果命中插件了,则返回: +{"type":"plugin","pluginId":$pluginId,"params":$params,"content":$content} + +你的回答都很严谨. +你是一步步推理得到的结果. +如果问题你并不能从 私有知识 和 以往的问题记录找那个 获取信息来源,并且你也不能推理出来,你直接返回:{"context":"我也不知道"},不要自己构造答案. + +例子: + +<1> +插件列表: +[{"desc": "计算一个随机数(0-n),n是你提供的上限", "pluginId":"7", "input": [{"desc": "随机数的上限", "name": "n"}], "output": [{"desc": "产生的随机数", "name": "num"}]}] + +我的问题是: +请给我0到10之间的随机值的时候,你发现提供的插件列表里有能命中的,你就返回这个函数的信息. + +你的返回: +{"type":"plugin","pluginId":"7","params":{"n":10},"content":""} + +<2> +[{"desc": "计算一个随机数(0-n),n是你提供的上限", "pluginId":"7", "input": [{"desc": "随机数的上限", "name": "n"}], "output": [{"desc": "产生的随机数", "name": "num"}]}] + +我的问题是: +你好 + +你的返回: +{"type":"llm","content":"你好,有什么事情可以帮助你吗?"} + + + +插件列表: +[{"url":"http://mifaas.systech.test.b2c.srv/m78-plugin/hera/HeraHandler/trace/halfRandom","desc":"给你一个json int数组,你随机返回一半的数据","pluginId":18,"input":[{"desc":"int数组","name":"array"}],"output":[{"desc":"产生的随机数组","name":"array"}]},{"url":"http://mifaas.systech.test.b2c.srv/m78-plugin/hera/HeraHandler/trace/random","desc":"随机返回一个数字","pluginId":7,"input":[{"desc":"随机上限值","name":"n"}],"output":[{"desc":"产生的随机数","name":"num"}]},{"url":"http://mifaas.systech.test.b2c.srv/m78-plugin/weather/WeatherHandler/weather","desc":"本插件可以查询某个城市的天气","pluginId":9,"input":[{"desc":"城市","name":"city"}],"output":[{"name":"data"}]},{"url":"http://mifaas.systech.test.b2c.srv/m78-plugin/dalle/DallEHandler/word/to/picture","desc":"本插件可以根据输入的语言描述需求,绘制所需的图片","pluginId":14,"input":[{"desc":"输入的语言描述","name":"prompt"}],"output":[{}]}] + +私有知识: +团队成员 +单文榜:MiOne架构师+团队管理。主导了Hera、FaaS、Mesh及MiOne3.0的架构设计和落地,目前主要精力在MiOne4.0(智能MiOne)架构及AI效能工具开发; +丁佩:后端架构师+中间件负责人,主要负责网关 + Dubbo + Nacos + 压测平台等中间件平台以及AI效能工具开发; +任清福:全栈工程师+前端负责人,主要负责MiOne前端架构+MiOne容器以及AI效能工具开发; +张平:后端架构师,主要负责FaaS + Mesh + Dubbo以及故障演练平台的架构设计及落地;丁涛:Hera架构师,主要负责Hera tracing的架构和研发以及OzHera开源的相关事项以及AI效能工具开发; +王涛:后端工程师,主要负责Hera logging的架构和研发以及OzHera开源的相关事项; +张校炜:后端工程师,主要负责Hera metrics、故障演练平台的研发以及OzHera开源的相关事项及AI效能工具开发; +王敏:后端工程师,主要负责MiLine + 网关 + Nacos以及AI效能工具开发;王志东:云原生架构师,主要负责K8S + Moon(调度) + MiLine以及AI效能工具开发; +曹宝玉:后端工程师,主要负责FaaS、Mesh、故障演练平台以及AI编程助手的研发; +张高峰:汽车业务架构师,主要负责效能组汽车客服的架构和研发,以及MiOne权限平台TPC的研发工作; +王英杰:后端工程师,主要负责Nyx(流量录制回放)以及AI效能工具开发; +刘传康:后端工程师,主要负责Dayu(微服务治理)以及汽车业务研发;高希辉:后端工程师,主要负责Hera 报警的研发以及OzHera开源的相关事项; +王彦东:后端工程师,主要负责MiOne容器、流水线及部分汽车业务研发; +谭琳琳:前端架构师,负责Hera、网关、MiLine部署等平台的前端架构和研发; +康婷:前端架构师,负责Hera tracing、Dayu治理、Moon调度等平台的前端架构和研发; +高钰林:全栈工程师,负责MiApi全栈及Mimeter前端开发;小明是打酱油的,一点用没有. + +以往的问题记录: +user:今天天气 + +assistant:{"type":"llm","content":"我也不知道"} +user:北京天气 + +assistant:{"type":"llm","content":"我也不知道"} +user:北京的天气 + + +我的问题是: +北京的天气 \ No newline at end of file diff --git a/jcommon/ai/zhipu/src/main/java/run/mone/Main.java b/jcommon/ai/zhipu/src/main/java/run/mone/Main.java index c0800b973..3e6c3664b 100644 --- a/jcommon/ai/zhipu/src/main/java/run/mone/Main.java +++ b/jcommon/ai/zhipu/src/main/java/run/mone/Main.java @@ -35,10 +35,12 @@ public class Main { public static void main(String[] args) { List messages = new ArrayList<>(); + String promptName = "prompt.txt"; String content = Files.readString(Paths.get("/Users/zhangzhiyong/IdeaProjects/goodjava/mone/jcommon/ai/zhipu/src/main/resources/" + promptName)); + ChatMessage chatMessage = new ChatMessage(ChatMessageRole.USER.value(), content); messages.add(chatMessage); String requestId = String.format(requestIdTemplate, System.currentTimeMillis()); diff --git a/jcommon/docean-plugin/docean-plugin-mongodb/pom.xml b/jcommon/docean-plugin/docean-plugin-mongodb/pom.xml index 9ad3566fe..a5a6ce68a 100644 --- a/jcommon/docean-plugin/docean-plugin-mongodb/pom.xml +++ b/jcommon/docean-plugin/docean-plugin-mongodb/pom.xml @@ -8,6 +8,7 @@ 1.6.0-jdk21-SNAPSHOT docean-plugin-mongodb + 1.5.0-jdk21-SNAPSHOT run.mone diff --git a/jcommon/docean-plugin/docean-plugin-mongodb/src/main/java/com/xiaomi/youpin/docean/plugin/mongodb/MongoDb.java b/jcommon/docean-plugin/docean-plugin-mongodb/src/main/java/com/xiaomi/youpin/docean/plugin/mongodb/MongoDb.java index 82056bdcf..858616b92 100644 --- a/jcommon/docean-plugin/docean-plugin-mongodb/src/main/java/com/xiaomi/youpin/docean/plugin/mongodb/MongoDb.java +++ b/jcommon/docean-plugin/docean-plugin-mongodb/src/main/java/com/xiaomi/youpin/docean/plugin/mongodb/MongoDb.java @@ -20,8 +20,8 @@ import com.mongodb.MongoClient; import com.mongodb.MongoClientURI; import com.mongodb.MongoException; +import com.mongodb.client.FindIterable; import com.mongodb.client.MongoCollection; -import com.mongodb.client.MongoCursor; import com.mongodb.client.MongoDatabase; import com.xiaomi.youpin.cat.CatPlugin; import org.bson.Document; @@ -130,30 +130,40 @@ public Document findFirst(String collectionName) { } public List findAll(String collectionName, Document doc) { - CatPlugin cat = new CatPlugin("findAll", catEnabled, CAT_TYPE); - boolean success = true; - cat.before(null); try { MongoCollection collection = this.getCollection(collectionName); - MongoCursor cursor = collection.find().iterator(); List res = new ArrayList<>(); - for (Document cur : collection.find()) { + for (Document cur : collection.find(doc)) { res.add(cur); } + return res; + } catch (MongoException e) { + logger.error(e.getMessage(), e); + } catch (Exception e) { + logger.error(e.getMessage(), e); + } + return null; + } + + public List findDocumentsWithPagination(String collectionName, Document doc, int page, int pageSize) { + try { + MongoCollection collection = this.getCollection(collectionName); + List res = new ArrayList<>(); + FindIterable data = collection.find(doc).skip((page - 1) * pageSize).limit(pageSize); + for (Document cur : data) { + res.add(cur); + } return res; } catch (MongoException e) { - success = false; logger.error(e.getMessage(), e); } catch (Exception e) { - success = false; logger.error(e.getMessage(), e); - } finally { - cat.after(success); } return null; } + public void delete(String collectionName, Document doc) { CatPlugin cat = new CatPlugin("delete", catEnabled, CAT_TYPE); boolean success = true; diff --git a/jcommon/docean-plugin/docean-plugin-test/pom.xml b/jcommon/docean-plugin/docean-plugin-test/pom.xml index 6c374f7f4..48c4bc048 100644 --- a/jcommon/docean-plugin/docean-plugin-test/pom.xml +++ b/jcommon/docean-plugin/docean-plugin-test/pom.xml @@ -49,16 +49,31 @@ run.mone docean-plugin-nacos + run.mone docean-plugin-http 1.6.0-jdk21-SNAPSHOT + run.mone docean-plugin-rocketmq 1.6.0-jdk21-SNAPSHOT + + + + run.mone + docean-plugin-mongodb + 1.5.0-jdk21 + + + + wsdl4j + wsdl4j + 1.6.3 + run.mone docean-plugin-sql diff --git a/jcommon/docean-plugin/docean-plugin-test/src/test/java/com/xiaomi/youpin/docean/plugin/test/mongodb/MongodbTest.java b/jcommon/docean-plugin/docean-plugin-test/src/test/java/com/xiaomi/youpin/docean/plugin/test/mongodb/MongodbTest.java new file mode 100644 index 000000000..1feccb320 --- /dev/null +++ b/jcommon/docean-plugin/docean-plugin-test/src/test/java/com/xiaomi/youpin/docean/plugin/test/mongodb/MongodbTest.java @@ -0,0 +1,58 @@ +package com.xiaomi.youpin.docean.plugin.test.mongodb; + +import com.mongodb.Block; +import com.xiaomi.youpin.docean.Ioc; +import com.xiaomi.youpin.docean.plugin.config.Config; +import com.xiaomi.youpin.docean.plugin.mongodb.MongoDb; +import org.bson.Document; +import org.junit.Test; + +/** + * @author goodjava@qq.com + * @date 2024/3/22 16:15 + */ +public class MongodbTest { + + + @Test + public void test1() { + MongoDb mongoDb = getMongoDb(); + Document data = mongoDb.findFirst("book"); + System.out.println(data); + } + + private static MongoDb getMongoDb() { + Config config = new Config(); + config.put("mongodb.client", "mongodb://localhost:27017"); + config.put("mongodb.database", "book"); + Ioc.ins().putBean(config).init("com.xiaomi.youpin.docean.plugin.mongodb"); + MongoDb mongoDb = Ioc.ins().getBean(MongoDb.class); + return mongoDb; + } + + @Test + public void testInsert() { + MongoDb mongoDb = getMongoDb(); + Document document = new Document(); + document.put("name", "水浒"); + mongoDb.insert("book", document); + } + + @Test + public void testFind() { + MongoDb mongoDb = getMongoDb(); + mongoDb.findAll("book", null).forEach(it -> { + System.out.println(it); + }); + } + + @Test + public void testFindWithPage() { + MongoDb mongoDb = getMongoDb(); + int page = 1; + int pageSize = 1; + mongoDb.getCollection("book").find().skip((page - 1) * pageSize).limit(pageSize).forEach((Block) document -> { + System.out.println(document); + }); + } +} diff --git a/jcommon/docean/src/main/java/com/xiaomi/youpin/docean/Mvc.java b/jcommon/docean/src/main/java/com/xiaomi/youpin/docean/Mvc.java index 2da42bd0c..68f697e41 100644 --- a/jcommon/docean/src/main/java/com/xiaomi/youpin/docean/Mvc.java +++ b/jcommon/docean/src/main/java/com/xiaomi/youpin/docean/Mvc.java @@ -126,7 +126,12 @@ private void initializeControllerMapping(Bean bean) { private void registerControllerMethods(Bean bean) { Arrays.stream(bean.getClazz().getMethods()).forEach(m -> Optional.ofNullable(m.getAnnotation(RequestMapping.class)).ifPresent(rm -> { + //支持类上添加RequestMapping + RequestMapping classMapping = bean.getClazz().getAnnotation(RequestMapping.class); String path = rm.path(); + if (Optional.ofNullable(classMapping).isPresent()) { + path = classMapping.path() + path; + } HttpRequestMethod hrm = new HttpRequestMethod(); hrm.setTimeout(rm.timeout()); hrm.setPath(path); diff --git a/jcommon/docean/src/main/java/com/xiaomi/youpin/docean/anno/RequestMapping.java b/jcommon/docean/src/main/java/com/xiaomi/youpin/docean/anno/RequestMapping.java index 0d5536dcc..a1cb37aa1 100644 --- a/jcommon/docean/src/main/java/com/xiaomi/youpin/docean/anno/RequestMapping.java +++ b/jcommon/docean/src/main/java/com/xiaomi/youpin/docean/anno/RequestMapping.java @@ -22,7 +22,7 @@ /** * @author goodjava@qq.com */ -@Target({ElementType.METHOD}) +@Target({ElementType.METHOD, ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) @Documented public @interface RequestMapping { diff --git a/jcommon/easy/src/main/java/com/xiaomi/youpin/docean/common/ReflectUtils.java b/jcommon/easy/src/main/java/com/xiaomi/youpin/docean/common/ReflectUtils.java index 94cb3a4c7..c3a6e63af 100644 --- a/jcommon/easy/src/main/java/com/xiaomi/youpin/docean/common/ReflectUtils.java +++ b/jcommon/easy/src/main/java/com/xiaomi/youpin/docean/common/ReflectUtils.java @@ -55,7 +55,18 @@ public abstract class ReflectUtils { public static Field[] fields(Class clazz) { - return clazz.getDeclaredFields(); + Class superClazz = clazz.getSuperclass(); + Field[] superFields = new Field[]{}; + if (superClazz != null && !superClazz.equals(Object.class)) { + superFields = superClazz.getDeclaredFields(); + } + + Field[] fields = clazz.getDeclaredFields(); + //合并fields和superFields + Field[] allFields = new Field[fields.length + superFields.length]; + System.arraycopy(superFields, 0, allFields, 0, superFields.length); + System.arraycopy(fields, 0, allFields, superFields.length, fields.length); + return allFields; } public static void setField(Object obj, Field field, Object val) { diff --git a/jcommon/easy/src/test/java/com/xiaomi/youpin/docean/test/A.java b/jcommon/easy/src/test/java/com/xiaomi/youpin/docean/test/A.java new file mode 100644 index 000000000..c72eeb242 --- /dev/null +++ b/jcommon/easy/src/test/java/com/xiaomi/youpin/docean/test/A.java @@ -0,0 +1,11 @@ +package com.xiaomi.youpin.docean.test; + +/** + * @author goodjava@qq.com + * @date 2024/3/22 18:31 + */ +public class A { + + private String name; + +} diff --git a/jcommon/easy/src/test/java/com/xiaomi/youpin/docean/test/AA.java b/jcommon/easy/src/test/java/com/xiaomi/youpin/docean/test/AA.java new file mode 100644 index 000000000..e350f26c8 --- /dev/null +++ b/jcommon/easy/src/test/java/com/xiaomi/youpin/docean/test/AA.java @@ -0,0 +1,10 @@ +package com.xiaomi.youpin.docean.test; + +/** + * @author goodjava@qq.com + * @date 2024/3/22 18:32 + */ +public class AA extends A{ + + private int id; +} diff --git a/jcommon/easy/src/test/java/com/xiaomi/youpin/docean/test/ReflectUtilsTest.java b/jcommon/easy/src/test/java/com/xiaomi/youpin/docean/test/ReflectUtilsTest.java index f0c2bd3e3..9b9741e32 100644 --- a/jcommon/easy/src/test/java/com/xiaomi/youpin/docean/test/ReflectUtilsTest.java +++ b/jcommon/easy/src/test/java/com/xiaomi/youpin/docean/test/ReflectUtilsTest.java @@ -20,6 +20,7 @@ import com.xiaomi.youpin.docean.common.ReflectUtils; import org.junit.Test; +import java.util.Arrays; import java.util.concurrent.TimeUnit; import java.util.function.BiFunction; import java.util.stream.IntStream; @@ -30,6 +31,14 @@ */ public class ReflectUtilsTest { + @Test + public void test1() { + Arrays.stream(ReflectUtils.fields(AA.class)).forEach(it->{ + System.out.println(it); + }); + } + + //3000 @Test public void testInvokerFastMethod() { diff --git a/jcommon/excel/src/main/java/run/mone/excel/ExportExcel.java b/jcommon/excel/src/main/java/run/mone/excel/ExportExcel.java index cc1535d70..c6c204829 100644 --- a/jcommon/excel/src/main/java/run/mone/excel/ExportExcel.java +++ b/jcommon/excel/src/main/java/run/mone/excel/ExportExcel.java @@ -165,22 +165,6 @@ private static String[] getFieldValues(Object o) { } return fieldValues; } -// public static void main(String[] args) throws IOException { -// List> dataList = new ArrayList<>(); -// Map data1 = new HashMap<>(); -// Map data2 = new HashMap<>(); -// data1.put("name", "j"); -// data1.put("age", 11); -// dataList.add(data1); -// -// data2.put("name", "l"); -// data2.put("age", 2); -// dataList.add(data2); -// -// HSSFWorkbook sheets = HSSFWorkbook4Map(dataList, "log-manager日志,搜索词:message:223 and ddd"); -// FileOutputStream fos = new FileOutputStream("D://t//t"+ UUID.randomUUID() +".xls"); -// sheets.write(fos); -// -// } + } diff --git a/jcommon/excel/src/test/java/run/mone/excel/ExcelTest.java b/jcommon/excel/src/test/java/run/mone/excel/ExcelTest.java new file mode 100644 index 000000000..63e23a685 --- /dev/null +++ b/jcommon/excel/src/test/java/run/mone/excel/ExcelTest.java @@ -0,0 +1,38 @@ +package run.mone.excel; + +import lombok.SneakyThrows; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.junit.Test; + +import java.io.FileOutputStream; +import java.util.*; + +import static run.mone.excel.ExportExcel.HSSFWorkbook4Map; + +/** + * @author goodjava@qq.com + * @date 2024/4/2 21:06 + */ +public class ExcelTest { + + + @SneakyThrows + @Test + public void test1() { + List> dataList = new ArrayList<>(); + Map data1 = new HashMap<>(); + Map data2 = new HashMap<>(); + data1.put("name", "j"); + data1.put("age", 11); + dataList.add(data1); + + data2.put("name", "l"); + data2.put("age", 2); + dataList.add(data2); + + HSSFWorkbook sheets = HSSFWorkbook4Map(dataList, ""); + FileOutputStream fos = new FileOutputStream("/tmp/abc.xls"); + sheets.write(fos); + } + +}