-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
15 changed files
with
491 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>run.mone</groupId> | ||
<artifactId>jcommon</artifactId> | ||
<version>1.4-jdk20-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>ai</artifactId> | ||
<packaging>pom</packaging> | ||
<modules> | ||
<module>zhipu</module> | ||
</modules> | ||
|
||
<properties> | ||
<maven.compiler.source>21</maven.compiler.source> | ||
<maven.compiler.target>21</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
你是一名高级groovy工程师. | ||
你要完成的好,我会给你100$小费. | ||
我会给你提供一些代码只是和业务需求,请帮我生成相应的$code(groovy代码)代码和$params和$out. | ||
你只需要返回一个方法和参数列表,方法的名字统一叫execute,参数: 第一个是 | ||
JsonObject input, 第二个是Object context | ||
JsonObject必须用Gson中的库 | ||
不要生成任何测试代码 | ||
不要生成任何说明,只需要返回一个json结构的内容即可 | ||
你要生成一些必要的import | ||
你给我返回的是一个JsonObject(Gson中的类) | ||
你的返回结果里决不能用任何markdown格式包裹(比如:```json ``` ```groovy ```) | ||
不要输出换行符 比如 \n \r等 | ||
$code就是你要生成的代码内容 | ||
$params就是参数名列表 | ||
$outs就是返回结果的列表 | ||
|
||
最终你产生的结果 | ||
{"code":$code,"params":$params,"outs":$outs} | ||
|
||
$params的格式举例:[{"name":"a","tpye":"int"}] | ||
$outs的格式举例:[{"name":"sum","type":"int"}] | ||
|
||
一些工具库使用,你可以借鉴: | ||
|
||
|
||
DbUtils里边有些工具方法可以操作数据库 | ||
|
||
/** | ||
* 将提供的键值对数据插入到指定的数据库表中。 | ||
*/ | ||
public Long insert(String tableName, Map<String, Object> data) | ||
|
||
/** | ||
* 更新指定表的指定ID的记录,通过传入的键值对映射来设置新的列值 | ||
*/ | ||
public void update(String tableName, String primaryKeyName, Map<String, Object> data) | ||
|
||
// 根据id列表批量删除 | ||
public void deleteByIds(String tableName, String idName, List<Long> ids) | ||
|
||
|
||
你尽量使用我给你提供的工具类,DbUtils 直接可以从context中获取 context.getDbUtils | ||
|
||
|
||
我给你一个例子: | ||
|
||
需求: | ||
计算两数和 | ||
|
||
|
||
返回: | ||
{ | ||
"code": "def execute(JsonObject input, Object context) {\n if (!input.has('a') || !input.has('b')) {\n throw new IllegalArgumentException(\"JSON对象必须包含键'a'和'b'。\");\n }\n int a = input.get('a').getAsInt();\n int b = input.get('b').getAsInt();\n int sum = a + b;\n JsonObject result = new JsonObject();\n result.addProperty(\"sum\", sum);\n return result;\n}", | ||
"params": [ | ||
{ | ||
"name": "a", | ||
"type": "int" | ||
}, | ||
{ | ||
"name": "b", | ||
"type": "int" | ||
} | ||
], | ||
"outs": [ | ||
{ | ||
"name": "sum", | ||
"type": "int" | ||
} | ||
] | ||
} | ||
|
||
例子结束 | ||
|
||
|
||
|
||
需求: | ||
给定一个List<Integer>,返回这个list中的最大值和最小值 | ||
|
||
返回: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
你是一名高级groovy工程师. | ||
你要完成的好,我会给你100$小费. | ||
我会给你提供一个groovy方法,你帮我生成这个方法的描述(必须少于15个字). | ||
你的返回结果永远是一个json格式的数据. | ||
你的返回结果里决不能用任何markdown格式包裹(比如:```groovy ```) | ||
不要生成任何说明,只需要返回一个json结构的内容即可 | ||
|
||
$comment就是你生成的注释 | ||
|
||
{"comment":"$comment"} | ||
|
||
|
||
|
||
|
||
我给你一个例子: | ||
|
||
code: | ||
def execute(JsonObject input, Object context) { | ||
if (!input.has('a') || !input.has('b')) { | ||
throw new IllegalArgumentException("JSON对象必须包含键'a'和'b'。"); | ||
} | ||
int a = input.get('a').getAsInt(); | ||
int b = input.get('b').getAsInt(); | ||
int sum = a + b; | ||
JsonObject result = new JsonObject(); | ||
result.addProperty("result", sum); | ||
return result; | ||
} | ||
|
||
|
||
你返回的: | ||
{"comment":"计算两数和"} | ||
|
||
|
||
|
||
例子结束 | ||
|
||
|
||
|
||
|
||
|
||
|
||
code: | ||
int a(int a, int b) { return a * b; } | ||
|
||
你的返回: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
李清照最好的6首词,并且给我解读 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>run.mone</groupId> | ||
<artifactId>ai</artifactId> | ||
<version>1.4-jdk20-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>zhipu</artifactId> | ||
|
||
<properties> | ||
<maven.compiler.source>21</maven.compiler.source> | ||
<maven.compiler.target>21</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>cn.bigmodel.openapi</groupId> | ||
<artifactId>oapi-java-sdk</artifactId> | ||
<version>release-V4-2.0.0</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.google.code.gson</groupId> | ||
<artifactId>gson</artifactId> | ||
<version>2.8.5</version> | ||
</dependency> | ||
|
||
|
||
</dependencies> | ||
|
||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package run.mone; | ||
|
||
import com.zhipu.oapi.ClientV4; | ||
import com.zhipu.oapi.Constants; | ||
import com.zhipu.oapi.service.v4.model.ChatCompletionRequest; | ||
import com.zhipu.oapi.service.v4.model.ChatMessage; | ||
import com.zhipu.oapi.service.v4.model.ChatMessageRole; | ||
import com.zhipu.oapi.service.v4.model.ModelApiResponse; | ||
import lombok.SneakyThrows; | ||
|
||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* @author [email protected] | ||
* @date 2024/3/10 07:55 | ||
*/ | ||
public class Main { | ||
|
||
private static final String requestIdTemplate = "myoz-%d"; | ||
|
||
|
||
private static final String KEY = System.getenv("zhipu"); | ||
|
||
private static final String API_KEY = KEY.split("\\.")[0]; | ||
|
||
private static final String API_SECRET = KEY.split("\\.")[1]; | ||
|
||
private static final ClientV4 client = new ClientV4.Builder(API_KEY, API_SECRET).build(); | ||
|
||
|
||
@SneakyThrows | ||
public static void main(String[] args) { | ||
List<ChatMessage> 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()); | ||
ChatCompletionRequest chatCompletionRequest = ChatCompletionRequest.builder() | ||
.model(Constants.ModelChatGLM4) | ||
.stream(Boolean.FALSE) | ||
.invokeMethod(Constants.invokeMethod) | ||
.messages(messages) | ||
.requestId(requestId) | ||
.build(); | ||
ModelApiResponse invokeModelApiResp = client.invokeModelApi(chatCompletionRequest); | ||
String resContent = invokeModelApiResp.getData().getChoices().get(0).getMessage().getContent().toString(); | ||
System.out.println(resContent); | ||
// System.out.println("model output:"+ new Gson().toJson(invokeModelApiResp)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
jcommon/docean/src/main/java/com/xiaomi/youpin/docean/anno/IocConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.xiaomi.youpin.docean.anno; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* @author [email protected] | ||
* @date 2024/3/3 09:19 | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.TYPE) // 应用于类 | ||
public @interface IocConfiguration { | ||
String[] basePackage(); | ||
} |
21 changes: 21 additions & 0 deletions
21
jcommon/docean/src/test/java/com/xiaomi/youpin/docean/test/TestRun.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.xiaomi.youpin.docean.test; | ||
|
||
import com.xiaomi.youpin.docean.Ioc; | ||
import com.xiaomi.youpin.docean.anno.IocConfiguration; | ||
import com.xiaomi.youpin.docean.test.demo.DemoDao; | ||
|
||
/** | ||
* @author [email protected] | ||
* @date 2024/3/5 14:47 | ||
* <p> | ||
* Evaluating the efficacy of @IocConfiguration. | ||
*/ | ||
@IocConfiguration(basePackage = {"com.xiaomi.youpin.docean.test.demo"}) | ||
public class TestRun { | ||
|
||
public static void main(String[] args) { | ||
DemoDao demoA = Ioc.run(TestRun.class, args).getBean(DemoDao.class); | ||
System.out.println(demoA.get()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.