feat(ai): 调整模型
This commit is contained in:
@@ -9,7 +9,7 @@ spring:
|
|||||||
api-key: ENC(K+Hff9QGC+fcyi510VIDd9CaeK/IN5WBJ9rlkUsHEdDgIidW+stHHJlsK0lLPUXXREha+ToQZqqDXJrqSE+GUKCXklFhelD8bRHFXBIeP/ZzT2cxhzgKUXgjw3S0Qw2R)
|
api-key: ENC(K+Hff9QGC+fcyi510VIDd9CaeK/IN5WBJ9rlkUsHEdDgIidW+stHHJlsK0lLPUXXREha+ToQZqqDXJrqSE+GUKCXklFhelD8bRHFXBIeP/ZzT2cxhzgKUXgjw3S0Qw2R)
|
||||||
chat:
|
chat:
|
||||||
options:
|
options:
|
||||||
model: 'Qwen3-1.7-vllm'
|
model: 'Qwen3/qwen3-1.7b'
|
||||||
mvc:
|
mvc:
|
||||||
async:
|
async:
|
||||||
request-timeout: 3600000
|
request-timeout: 3600000
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
package com.lanyuanxiaoyao.service.ai.chat;
|
package com.lanyuanxiaoyao.service.ai.chat;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.http.HttpClient;
|
import java.net.http.HttpClient;
|
||||||
|
import java.time.Duration;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.noear.solon.ai.rag.Document;
|
import org.noear.solon.ai.rag.Document;
|
||||||
@@ -25,12 +27,12 @@ import org.springframework.web.reactive.function.client.WebClient;
|
|||||||
* @author lanyuanxiaoyao
|
* @author lanyuanxiaoyao
|
||||||
* @version 20250514
|
* @version 20250514
|
||||||
*/
|
*/
|
||||||
public class TestSpringAIToolChat {
|
public class TestModel {
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
testChatModel();
|
// testChatModel();
|
||||||
testVisualModel();
|
testVisualModel();
|
||||||
// testEmbeddingModel();
|
testEmbeddingModel();
|
||||||
// testRerankingModel();
|
testRerankingModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void testChatModel() {
|
private static void testChatModel() {
|
||||||
@@ -41,12 +43,14 @@ public class TestSpringAIToolChat {
|
|||||||
"Qwen3/qwen3-4b-q4km",
|
"Qwen3/qwen3-4b-q4km",
|
||||||
"Qwen3/qwen3-8b-q4km"
|
"Qwen3/qwen3-8b-q4km"
|
||||||
)) {
|
)) {
|
||||||
|
System.out.println(model);
|
||||||
|
long start = System.currentTimeMillis();
|
||||||
ChatClient client = chatClient(model);
|
ChatClient client = chatClient(model);
|
||||||
String content = client.prompt()
|
String content = client.prompt()
|
||||||
.user("你好")
|
.user("你好,详细介绍一下是谁,能帮我做什么?")
|
||||||
.call()
|
.call()
|
||||||
.content();
|
.content();
|
||||||
System.out.println(content);
|
System.out.println(content.length() * 1000.0 / (System.currentTimeMillis() - start));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,19 +59,17 @@ public class TestSpringAIToolChat {
|
|||||||
"Qwen2.5/qwen2.5-vl-7b",
|
"Qwen2.5/qwen2.5-vl-7b",
|
||||||
"Qwen2.5/qwen2.5-vl-7b-q4km",
|
"Qwen2.5/qwen2.5-vl-7b-q4km",
|
||||||
"Qwen2.5/qwen2.5-vl-3b-instruct",
|
"Qwen2.5/qwen2.5-vl-3b-instruct",
|
||||||
"Qwen2.5/qwen2.5-vl-3b-instruct-awq",
|
|
||||||
"Qwen2.5/qwen2.5-vl-7b-instruct",
|
"Qwen2.5/qwen2.5-vl-7b-instruct",
|
||||||
"Qwen2.5/qwen2.5-vl-7b-instruct-awq",
|
|
||||||
"MiniCPM/minicpm-o-2.6-7.6b",
|
"MiniCPM/minicpm-o-2.6-7.6b",
|
||||||
"MiniCPM/minicpm-o-2.6-7.6b-q4km"
|
"MiniCPM/minicpm-o-2.6-7.6b-q4km"
|
||||||
|
|
||||||
)) {
|
)) {
|
||||||
ChatClient client = chatClient(model);
|
ChatClient client = chatClient(model);
|
||||||
String content = client.prompt()
|
String content = client.prompt()
|
||||||
.user(spec -> spec.text("图片中有什么").media(MimeTypeUtils.IMAGE_PNG, new FileSystemResource("/Users/lanyuanxiaoyao/Pictures/deepseek.png")))
|
.user(spec -> spec.text("根据图片中的内容编一个童话小故事").media(MimeTypeUtils.IMAGE_PNG, new FileSystemResource("/Users/lanyuanxiaoyao/Pictures/deepseek.png")))
|
||||||
.call()
|
.call()
|
||||||
.content();
|
.content();
|
||||||
System.out.println(content);
|
System.out.println(StrUtil.trim(content));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,9 +80,7 @@ public class TestSpringAIToolChat {
|
|||||||
"Qwen3/qwen3-embedding-4b-q4km",
|
"Qwen3/qwen3-embedding-4b-q4km",
|
||||||
"Qwen3/qwen3-embedding-8b-q4km",
|
"Qwen3/qwen3-embedding-8b-q4km",
|
||||||
"BGE/bge-m3",
|
"BGE/bge-m3",
|
||||||
"BGE/bge-m3-q4km",
|
"BGE/bge-m3-q4km"
|
||||||
"MiniCPM/minicpm-embedding",
|
|
||||||
"MiniCPM/minicpm-embedding-light"
|
|
||||||
)) {
|
)) {
|
||||||
EmbeddingModel embeddingModel = embeddingModel(model);
|
EmbeddingModel embeddingModel = embeddingModel(model);
|
||||||
float[] worlds = embeddingModel.embed("Hello world");
|
float[] worlds = embeddingModel.embed("Hello world");
|
||||||
@@ -90,12 +90,10 @@ public class TestSpringAIToolChat {
|
|||||||
|
|
||||||
private static void testRerankingModel() throws IOException {
|
private static void testRerankingModel() throws IOException {
|
||||||
for (String model : List.of(
|
for (String model : List.of(
|
||||||
"BGE/beg-reranker-v2",
|
|
||||||
"MiniCPM/minicpm-reranker",
|
|
||||||
"MiniCPM/minicpm-reranker-light",
|
|
||||||
"BGE/beg-reranker-v2",
|
"BGE/beg-reranker-v2",
|
||||||
"BGE/beg-reranker-v2-q4km"
|
"BGE/beg-reranker-v2-q4km"
|
||||||
)) {
|
)) {
|
||||||
|
System.out.println(model);
|
||||||
RerankingModel rerankingModel = rerankingModel(model);
|
RerankingModel rerankingModel = rerankingModel(model);
|
||||||
List<Document> list = rerankingModel.rerank(
|
List<Document> list = rerankingModel.rerank(
|
||||||
"你好",
|
"你好",
|
||||||
@@ -149,6 +147,7 @@ public class TestSpringAIToolChat {
|
|||||||
return RerankingModel.of("http://132.121.206.65:10086/v1/rerank")
|
return RerankingModel.of("http://132.121.206.65:10086/v1/rerank")
|
||||||
.model(model)
|
.model(model)
|
||||||
.apiKey("*XMySqV%>hR&v>>g*NwCs3tpQ5FVMFEF2VHVTj<MYQd$&@$sY7CgqNyea4giJi4")
|
.apiKey("*XMySqV%>hR&v>>g*NwCs3tpQ5FVMFEF2VHVTj<MYQd$&@$sY7CgqNyea4giJi4")
|
||||||
|
.timeout(Duration.ofMinutes(10))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
package com.lanyuanxiaoyao.service.ai.chat;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import java.net.http.HttpClient;
|
||||||
|
import org.springframework.ai.chat.client.ChatClient;
|
||||||
|
import org.springframework.ai.openai.OpenAiChatModel;
|
||||||
|
import org.springframework.ai.openai.OpenAiChatOptions;
|
||||||
|
import org.springframework.ai.openai.api.OpenAiApi;
|
||||||
|
import org.springframework.ai.tool.annotation.Tool;
|
||||||
|
import org.springframework.ai.tool.annotation.ToolParam;
|
||||||
|
import org.springframework.http.client.JdkClientHttpRequestFactory;
|
||||||
|
import org.springframework.http.client.reactive.JdkClientHttpConnector;
|
||||||
|
import org.springframework.web.client.RestClient;
|
||||||
|
import org.springframework.web.reactive.function.client.WebClient;
|
||||||
|
import reactor.core.Disposable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lanyuanxiaoyao
|
||||||
|
* @version 20250613
|
||||||
|
*/
|
||||||
|
public class TestSpringAiTools {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
ChatClient client = ChatClient.builder(
|
||||||
|
OpenAiChatModel.builder()
|
||||||
|
.openAiApi(
|
||||||
|
OpenAiApi.builder()
|
||||||
|
.baseUrl("http://132.121.206.65:10086")
|
||||||
|
.apiKey("*XMySqV%>hR&v>>g*NwCs3tpQ5FVMFEF2VHVTj<MYQd$&@$sY7CgqNyea4giJi4")
|
||||||
|
.restClientBuilder(restClientBuilder())
|
||||||
|
.webClientBuilder(webClientBuilder())
|
||||||
|
.build()
|
||||||
|
)
|
||||||
|
.defaultOptions(
|
||||||
|
OpenAiChatOptions.builder()
|
||||||
|
.model("Qwen3/qwen3-1.7b")
|
||||||
|
.build()
|
||||||
|
)
|
||||||
|
.build()
|
||||||
|
)
|
||||||
|
.build();
|
||||||
|
Disposable disposable = client.prompt()
|
||||||
|
.tools(new TestTool())
|
||||||
|
.user("调用submit工具生成一个关于「猪」的笑话")
|
||||||
|
.stream()
|
||||||
|
.content()
|
||||||
|
.subscribe(System.out::println);
|
||||||
|
while (!disposable.isDisposed()) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static HttpClient httpClient() {
|
||||||
|
return HttpClient.newBuilder()
|
||||||
|
.version(HttpClient.Version.HTTP_1_1)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static RestClient.Builder restClientBuilder() {
|
||||||
|
return RestClient.builder()
|
||||||
|
.requestFactory(new JdkClientHttpRequestFactory(httpClient()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static WebClient.Builder webClientBuilder() {
|
||||||
|
return WebClient.builder()
|
||||||
|
.clientConnector(new JdkClientHttpConnector(httpClient()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final class TestTool {
|
||||||
|
@Tool(description = "传入任意动物名称,返回一个关于这个动物的笑话")
|
||||||
|
public String submit(@ToolParam(description = "动物名称") String animalName) {
|
||||||
|
return StrUtil.format("{}掉沟里了", animalName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -145,7 +145,7 @@ public class LlamaSwapTool extends GeneratorTool {
|
|||||||
arguments.add("--reasoning-parser deepseek_r1");
|
arguments.add("--reasoning-parser deepseek_r1");
|
||||||
}
|
}
|
||||||
return new DockerCmd(
|
return new DockerCmd(
|
||||||
"vllm-server-cpu:0.9.1",
|
"vllm-server-cpu:0.8.5.post1",
|
||||||
name,
|
name,
|
||||||
model,
|
model,
|
||||||
StrUtil.format("http://vllm-{}:${PORT}", displayName(model)),
|
StrUtil.format("http://vllm-{}:${PORT}", displayName(model)),
|
||||||
|
|||||||
@@ -9,10 +9,10 @@ spring:
|
|||||||
api-key: ENC(K+Hff9QGC+fcyi510VIDd9CaeK/IN5WBJ9rlkUsHEdDgIidW+stHHJlsK0lLPUXXREha+ToQZqqDXJrqSE+GUKCXklFhelD8bRHFXBIeP/ZzT2cxhzgKUXgjw3S0Qw2R)
|
api-key: ENC(K+Hff9QGC+fcyi510VIDd9CaeK/IN5WBJ9rlkUsHEdDgIidW+stHHJlsK0lLPUXXREha+ToQZqqDXJrqSE+GUKCXklFhelD8bRHFXBIeP/ZzT2cxhzgKUXgjw3S0Qw2R)
|
||||||
chat:
|
chat:
|
||||||
options:
|
options:
|
||||||
model: 'Qwen3-1.7-vllm'
|
model: 'Qwen3/qwen3-1.7b'
|
||||||
embedding:
|
embedding:
|
||||||
options:
|
options:
|
||||||
model: 'Bge-m3-vllm'
|
model: 'Qwen3/qwen3-embedding-4b'
|
||||||
vectorstore:
|
vectorstore:
|
||||||
qdrant:
|
qdrant:
|
||||||
host: 132.121.206.65
|
host: 132.121.206.65
|
||||||
|
|||||||
Reference in New Issue
Block a user