forked from XiaoMi/mone
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ai support Use local LLM(claude3) close XiaoMi#827
- Loading branch information
Showing
14 changed files
with
545 additions
and
265 deletions.
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,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>aws</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>software.amazon.awssdk</groupId> | ||
<artifactId>bedrockruntime</artifactId> | ||
<version>2.25.29</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.json</groupId> | ||
<artifactId>json</artifactId> | ||
<version>20240303</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,19 @@ | ||
package run.mone; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
import lombok.Data; | ||
|
||
/** | ||
* @author goodjava@qq.com | ||
* @date 2024/4/9 16:43 | ||
*/ | ||
@Data | ||
public class Content { | ||
|
||
@SerializedName("type") | ||
private String type; | ||
|
||
@SerializedName("text") | ||
private String text; | ||
|
||
} |
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,19 @@ | ||
package run.mone; | ||
|
||
import lombok.Builder; | ||
import lombok.Data; | ||
|
||
/** | ||
* @author goodjava@qq.com | ||
* @date 2024/4/12 15:04 | ||
*/ | ||
@Data | ||
@Builder | ||
public class Key { | ||
|
||
private String keyId; | ||
|
||
private String key; | ||
|
||
|
||
} |
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,20 @@ | ||
package run.mone; | ||
|
||
/** | ||
* @author goodjava@qq.com | ||
* @date 2024/4/12 14:59 | ||
*/ | ||
public enum ModelEnum { | ||
|
||
|
||
Sonnet("anthropic.claude-3-sonnet-20240229-v1:0"), | ||
Haiku("anthropic.claude-3-haiku-20240307-v1:0"); | ||
|
||
|
||
public String modelName; | ||
|
||
ModelEnum(String name) { | ||
this.modelName = name; | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
jcommon/ai/aws/src/main/java/run/mone/ResponsePayload.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,39 @@ | ||
package run.mone; | ||
|
||
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> 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; | ||
|
||
} |
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,19 @@ | ||
package run.mone; | ||
|
||
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; | ||
|
||
|
||
} |
34 changes: 34 additions & 0 deletions
34
jcommon/ai/aws/src/test/java/run/mone/aws/client/test/AwsClientTest.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,34 @@ | ||
package run.mone.aws.client.test; | ||
|
||
import org.json.JSONArray; | ||
import org.json.JSONObject; | ||
import org.junit.Test; | ||
import run.mone.AwsClient; | ||
import run.mone.Key; | ||
import run.mone.ModelEnum; | ||
import run.mone.ResponsePayload; | ||
import software.amazon.awssdk.regions.Region; | ||
|
||
/** | ||
* @author goodjava@qq.com | ||
* @date 2024/4/12 14:57 | ||
*/ | ||
public class AwsClientTest { | ||
|
||
|
||
@Test | ||
public void test1() { | ||
JSONObject payload = new JSONObject() | ||
.put("anthropic_version", "bedrock-2023-05-31") | ||
.put("max_tokens", 1000) | ||
.put("messages", new JSONArray() | ||
.put(new JSONObject().put("role", "user") | ||
.put("content", "天空为什么是蓝色的?" | ||
) | ||
) | ||
); | ||
ResponsePayload res = AwsClient.call(payload, Region.EU_WEST_3, ModelEnum.Haiku.modelName, Key.builder().keyId("").key("").build()); | ||
System.out.println(res.getContent().get(0).getText()); | ||
} | ||
|
||
} |
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
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
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
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.