根据规范建议优化

This commit is contained in:
choweli 2025-03-26 16:46:12 +08:00
parent 23dfb5c88d
commit e291654d8c
46 changed files with 889 additions and 133 deletions

View File

@ -1,3 +1,19 @@
/*
* Copyright (c) 2025 Hutool Team and hutool.cn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dromara.hutool.ai; package org.dromara.hutool.ai;
import org.dromara.hutool.core.exception.HutoolException; import org.dromara.hutool.core.exception.HutoolException;

View File

@ -1,3 +1,19 @@
/*
* Copyright (c) 2025 Hutool Team and hutool.cn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dromara.hutool.ai; package org.dromara.hutool.ai;
import org.dromara.hutool.ai.core.AIConfig; import org.dromara.hutool.ai.core.AIConfig;

View File

@ -1,3 +1,19 @@
/*
* Copyright (c) 2025 Hutool Team and hutool.cn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dromara.hutool.ai; package org.dromara.hutool.ai;
import org.dromara.hutool.ai.core.AIConfig; import org.dromara.hutool.ai.core.AIConfig;

View File

@ -1,3 +1,19 @@
/*
* Copyright (c) 2025 Hutool Team and hutool.cn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dromara.hutool.ai; package org.dromara.hutool.ai;
/** /**

View File

@ -1,3 +1,19 @@
/*
* Copyright (c) 2025 Hutool Team and hutool.cn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dromara.hutool.ai; package org.dromara.hutool.ai;
/** /**

View File

@ -1,3 +1,19 @@
/*
* Copyright (c) 2025 Hutool Team and hutool.cn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dromara.hutool.ai.core; package org.dromara.hutool.ai.core;
import java.util.Map; import java.util.Map;

View File

@ -1,3 +1,19 @@
/*
* Copyright (c) 2025 Hutool Team and hutool.cn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dromara.hutool.ai.core; package org.dromara.hutool.ai.core;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;

View File

@ -1,3 +1,19 @@
/*
* Copyright (c) 2025 Hutool Team and hutool.cn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dromara.hutool.ai.core; package org.dromara.hutool.ai.core;
import org.dromara.hutool.core.map.concurrent.SafeConcurrentHashMap; import org.dromara.hutool.core.map.concurrent.SafeConcurrentHashMap;

View File

@ -1,3 +1,19 @@
/*
* Copyright (c) 2025 Hutool Team and hutool.cn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dromara.hutool.ai.core; package org.dromara.hutool.ai.core;
import java.util.List; import java.util.List;
@ -26,6 +42,6 @@ public interface AIService {
* @return AI回答 * @return AI回答
* @since 6.0.0 * @since 6.0.0
*/ */
String chat(List<Message> messages); String chat(final List<Message> messages);
} }

View File

@ -1,3 +1,19 @@
/*
* Copyright (c) 2025 Hutool Team and hutool.cn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dromara.hutool.ai.core; package org.dromara.hutool.ai.core;
/** /**
@ -20,9 +36,9 @@ public interface AIServiceProvider {
* 创建AI服务实例 * 创建AI服务实例
* *
* @param config AIConfig配置 * @param config AIConfig配置
* @param <T> AIService * @param <T> AIService实现
* @return AI服务实例 * @return AI服务实例
* @since 6.0.0 * @since 6.0.0
*/ */
<T extends AIService> T create(AIConfig config); <T extends AIService> T create(final AIConfig config);
} }

View File

@ -1,3 +1,19 @@
/*
* Copyright (c) 2025 Hutool Team and hutool.cn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dromara.hutool.ai.core; package org.dromara.hutool.ai.core;
import org.dromara.hutool.ai.AIException; import org.dromara.hutool.ai.AIException;
@ -28,6 +44,11 @@ public class BaseAIService {
this.config = config; this.config = config;
} }
/**
* 发送Get请求
* @param endpoint 请求节点
* @return 请求响应
*/
protected Response sendGet(final String endpoint) { protected Response sendGet(final String endpoint) {
//链式构建请求 //链式构建请求
try { try {
@ -42,6 +63,12 @@ public class BaseAIService {
} }
} }
/**
* 发送Post请求
* @param endpoint 请求节点
* @param paramJson 请求参数json
* @return 请求响应
*/
protected Response sendPost(final String endpoint, final String paramJson) { protected Response sendPost(final String endpoint, final String paramJson) {
//链式构建请求 //链式构建请求
try { try {
@ -59,6 +86,12 @@ public class BaseAIService {
} }
/**
* 发送表单请求
* @param endpoint 请求节点
* @param paramMap 请求参数map
* @return 请求响应
*/
protected Response sendFormData(final String endpoint, final Map<String, Object> paramMap) { protected Response sendFormData(final String endpoint, final Map<String, Object> paramMap) {
//链式构建请求 //链式构建请求
try { try {

View File

@ -1,5 +1,20 @@
package org.dromara.hutool.ai.core; /*
* Copyright (c) 2025 Hutool Team and hutool.cn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dromara.hutool.ai.core;
import org.dromara.hutool.core.map.concurrent.SafeConcurrentHashMap; import org.dromara.hutool.core.map.concurrent.SafeConcurrentHashMap;

View File

@ -1,3 +1,19 @@
/*
* Copyright (c) 2025 Hutool Team and hutool.cn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dromara.hutool.ai.core; package org.dromara.hutool.ai.core;
/** /**

View File

@ -18,5 +18,7 @@
* AI相关基础类 * AI相关基础类
* *
* @author elichow * @author elichow
* @since 6.0.0
*/ */
package org.dromara.hutool.ai.core; package org.dromara.hutool.ai.core;

View File

@ -1,3 +1,19 @@
/*
* Copyright (c) 2025 Hutool Team and hutool.cn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dromara.hutool.ai.model.deepseek; package org.dromara.hutool.ai.model.deepseek;
/** /**

View File

@ -1,3 +1,19 @@
/*
* Copyright (c) 2025 Hutool Team and hutool.cn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dromara.hutool.ai.model.deepseek; package org.dromara.hutool.ai.model.deepseek;
import org.dromara.hutool.ai.Models; import org.dromara.hutool.ai.Models;

View File

@ -1,5 +1,20 @@
package org.dromara.hutool.ai.model.deepseek; /*
* Copyright (c) 2025 Hutool Team and hutool.cn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dromara.hutool.ai.model.deepseek;
import org.dromara.hutool.ai.core.AIConfig; import org.dromara.hutool.ai.core.AIConfig;
import org.dromara.hutool.ai.core.AIServiceProvider; import org.dromara.hutool.ai.core.AIServiceProvider;
@ -18,7 +33,7 @@ public class DeepSeekProvider implements AIServiceProvider {
} }
@Override @Override
public DeepSeekService create(AIConfig config) { public DeepSeekService create(final AIConfig config) {
return new DeepSeekServiceImpl(config); return new DeepSeekServiceImpl(config);
} }
} }

View File

@ -1,3 +1,19 @@
/*
* Copyright (c) 2025 Hutool Team and hutool.cn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dromara.hutool.ai.model.deepseek; package org.dromara.hutool.ai.model.deepseek;
import org.dromara.hutool.ai.core.AIService; import org.dromara.hutool.ai.core.AIService;

View File

@ -1,3 +1,19 @@
/*
* Copyright (c) 2025 Hutool Team and hutool.cn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dromara.hutool.ai.model.deepseek; package org.dromara.hutool.ai.model.deepseek;
import org.dromara.hutool.ai.core.AIConfig; import org.dromara.hutool.ai.core.AIConfig;
@ -28,7 +44,7 @@ public class DeepSeekServiceImpl extends BaseAIService implements DeepSeekServic
//余额查询 //余额查询
private final String BALANCE_ENDPOINT = "/user/balance"; private final String BALANCE_ENDPOINT = "/user/balance";
public DeepSeekServiceImpl(AIConfig config) { public DeepSeekServiceImpl(final AIConfig config) {
//初始化DeepSeek客户端 //初始化DeepSeek客户端
super(config); super(config);
} }
@ -36,14 +52,14 @@ public class DeepSeekServiceImpl extends BaseAIService implements DeepSeekServic
@Override @Override
public String chat(String prompt) { public String chat(String prompt) {
// 定义消息结构 // 定义消息结构
List<Message> messages = new ArrayList<>(); final List<Message> messages = new ArrayList<>();
messages.add(new Message("system", "You are a helpful assistant")); messages.add(new Message("system", "You are a helpful assistant"));
messages.add(new Message("user", prompt)); messages.add(new Message("user", prompt));
return chat(messages); return chat(messages);
} }
@Override @Override
public String chat(List<Message> messages) { public String chat(final List<Message> messages) {
String paramJson = buildChatRequestBody(messages); String paramJson = buildChatRequestBody(messages);
Response response = sendPost(CHAT_ENDPOINT, paramJson); Response response = sendPost(CHAT_ENDPOINT, paramJson);
return response.bodyStr(); return response.bodyStr();
@ -69,9 +85,9 @@ public class DeepSeekServiceImpl extends BaseAIService implements DeepSeekServic
} }
// 构建chat请求体 // 构建chat请求体
private String buildChatRequestBody(List<Message> messages) { private String buildChatRequestBody(final List<Message> messages) {
//使用JSON工具 //使用JSON工具
Map<String, Object> paramMap = new HashMap<>(); final Map<String, Object> paramMap = new HashMap<>();
paramMap.put("model", config.getModel()); paramMap.put("model", config.getModel());
paramMap.put("messages", messages); paramMap.put("messages", messages);
//合并其他参数 //合并其他参数
@ -84,7 +100,7 @@ public class DeepSeekServiceImpl extends BaseAIService implements DeepSeekServic
private String buildBetaRequestBody(String prompt) { private String buildBetaRequestBody(String prompt) {
// 定义消息结构 // 定义消息结构
//使用JSON工具 //使用JSON工具
Map<String, Object> paramMap = new HashMap<>(); final Map<String, Object> paramMap = new HashMap<>();
paramMap.put("model", config.getModel()); paramMap.put("model", config.getModel());
paramMap.put("prompt", prompt); paramMap.put("prompt", prompt);
// //合并其他参数 // //合并其他参数

View File

@ -0,0 +1,24 @@
/*
* Copyright (c) 2025 Hutool Team and hutool.cn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* 对deepSeek的封装实现
*
* @author elichow
* @since 6.0.0
*/
package org.dromara.hutool.ai.model.deepseek;

View File

@ -1,3 +1,19 @@
/*
* Copyright (c) 2025 Hutool Team and hutool.cn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dromara.hutool.ai.model.doubao; package org.dromara.hutool.ai.model.doubao;
/** /**
@ -25,7 +41,7 @@ public class DoubaoCommon {
} }
} }
//豆包视觉参数 //doubao视觉参数
public enum DoubaoVision { public enum DoubaoVision {
AUTO("auto"), AUTO("auto"),

View File

@ -1,3 +1,19 @@
/*
* Copyright (c) 2025 Hutool Team and hutool.cn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dromara.hutool.ai.model.doubao; package org.dromara.hutool.ai.model.doubao;
import org.dromara.hutool.ai.Models; import org.dromara.hutool.ai.Models;

View File

@ -1,3 +1,19 @@
/*
* Copyright (c) 2025 Hutool Team and hutool.cn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dromara.hutool.ai.model.doubao; package org.dromara.hutool.ai.model.doubao;
import org.dromara.hutool.ai.core.AIConfig; import org.dromara.hutool.ai.core.AIConfig;
@ -17,7 +33,7 @@ public class DoubaoProvider implements AIServiceProvider {
} }
@Override @Override
public DoubaoService create(AIConfig config) { public DoubaoService create(final AIConfig config) {
return new DoubaoServiceImpl(config); return new DoubaoServiceImpl(config);
} }
} }

View File

@ -1,3 +1,19 @@
/*
* Copyright (c) 2025 Hutool Team and hutool.cn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dromara.hutool.ai.model.doubao; package org.dromara.hutool.ai.model.doubao;
import org.dromara.hutool.ai.core.AIService; import org.dromara.hutool.ai.core.AIService;
@ -22,7 +38,7 @@ public interface DoubaoService extends AIService {
* @return AI回答 * @return AI回答
* @since 6.0.0 * @since 6.0.0
*/ */
String chatVision(String prompt, List<String> images, String detail); String chatVision(String prompt, final List<String> images, String detail);
/** /**
* 图像理解模型会依据传入的图片信息以及问题给出回复 * 图像理解模型会依据传入的图片信息以及问题给出回复
@ -32,7 +48,7 @@ public interface DoubaoService extends AIService {
* @return AI回答 * @return AI回答
* @since 6.0.0 * @since 6.0.0
*/ */
default String chatVision(String prompt, List<String> images) { default String chatVision(String prompt, final List<String> images) {
return chatVision(prompt, images, DoubaoCommon.DoubaoVision.AUTO.getDetail()); return chatVision(prompt, images, DoubaoCommon.DoubaoVision.AUTO.getDetail());
} }
@ -46,7 +62,7 @@ public interface DoubaoService extends AIService {
* @return 生成任务id * @return 生成任务id
* @since 6.0.0 * @since 6.0.0
*/ */
String videoTasks(String text, String image, List<DoubaoCommon.DoubaoVideo> videoParams); String videoTasks(String text, String image, final List<DoubaoCommon.DoubaoVideo> videoParams);
/** /**
* 创建视频生成任务 * 创建视频生成任务
@ -96,7 +112,7 @@ public interface DoubaoService extends AIService {
* @return AI回答 * @return AI回答
* @since 6.0.0 * @since 6.0.0
*/ */
String botsChat(List<Message> messages); String botsChat(final List<Message> messages);
/** /**
* 分词可以将文本转换为模型可理解的 token id并返回文本的 tokens 数量token id token 在原始文本中的偏移量等信息 * 分词可以将文本转换为模型可理解的 token id并返回文本的 tokens 数量token id token 在原始文本中的偏移量等信息
@ -127,7 +143,7 @@ public interface DoubaoService extends AIService {
* @return AI回答 * @return AI回答
* @since 6.0.0 * @since 6.0.0
*/ */
String batchChat(List<Message> messages); String batchChat(final List<Message> messages);
/** /**
* 创建上下文缓存 创建上下文缓存获得缓存 id字段后在上下文缓存对话 API中使用 * 创建上下文缓存 创建上下文缓存获得缓存 id字段后在上下文缓存对话 API中使用
@ -139,7 +155,7 @@ public interface DoubaoService extends AIService {
* @return 返回的缓存id * @return 返回的缓存id
* @since 6.0.0 * @since 6.0.0
*/ */
String createContext(List<Message> messages, String mode); String createContext(final List<Message> messages, String mode);
/** /**
* 创建上下文缓存 创建上下文缓存获得缓存 id字段后在上下文缓存对话 API中使用 * 创建上下文缓存 创建上下文缓存获得缓存 id字段后在上下文缓存对话 API中使用
@ -150,7 +166,7 @@ public interface DoubaoService extends AIService {
* @return 返回的缓存id * @return 返回的缓存id
* @since 6.0.0 * @since 6.0.0
*/ */
default String createContext(List<Message> messages) { default String createContext(final List<Message> messages) {
return createContext(messages, DoubaoCommon.DoubaoContext.SESSION.getMode()); return createContext(messages, DoubaoCommon.DoubaoContext.SESSION.getMode());
} }
@ -174,6 +190,6 @@ public interface DoubaoService extends AIService {
* @return AI的回答 * @return AI的回答
* @since 6.0.0 * @since 6.0.0
*/ */
String chatContext(List<Message> messages, String contextId); String chatContext(final List<Message> messages, String contextId);
} }

View File

@ -1,3 +1,19 @@
/*
* Copyright (c) 2025 Hutool Team and hutool.cn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dromara.hutool.ai.model.doubao; package org.dromara.hutool.ai.model.doubao;
import org.dromara.hutool.ai.core.AIConfig; import org.dromara.hutool.ai.core.AIConfig;
@ -39,7 +55,7 @@ public class DoubaoServiceImpl extends BaseAIService implements DoubaoService {
//创建视频生成任务 //创建视频生成任务
private final String CREATE_VIDEO = "/contents/generations/tasks"; private final String CREATE_VIDEO = "/contents/generations/tasks";
public DoubaoServiceImpl(AIConfig config) { public DoubaoServiceImpl(final AIConfig config) {
//初始化doubao客户端 //初始化doubao客户端
super(config); super(config);
} }
@ -47,28 +63,28 @@ public class DoubaoServiceImpl extends BaseAIService implements DoubaoService {
@Override @Override
public String chat(String prompt) { public String chat(String prompt) {
// 定义消息结构 // 定义消息结构
List<Message> messages = new ArrayList<>(); final List<Message> messages = new ArrayList<>();
messages.add(new Message("system", "You are a helpful assistant")); messages.add(new Message("system", "You are a helpful assistant"));
messages.add(new Message("user", prompt)); messages.add(new Message("user", prompt));
return chat(messages); return chat(messages);
} }
@Override @Override
public String chat(List<Message> messages) { public String chat(final List<Message> messages) {
String paramJson = buildChatRequestBody(messages); String paramJson = buildChatRequestBody(messages);
Response response = sendPost(CHAT_ENDPOINT, paramJson); Response response = sendPost(CHAT_ENDPOINT, paramJson);
return response.bodyStr(); return response.bodyStr();
} }
@Override @Override
public String chatVision(String prompt, List<String> images, String detail) { public String chatVision(String prompt, final List<String> images, String detail) {
String paramJson = buildChatVisionRequestBody(prompt, images, detail); String paramJson = buildChatVisionRequestBody(prompt, images, detail);
Response response = sendPost(CHAT_ENDPOINT, paramJson); Response response = sendPost(CHAT_ENDPOINT, paramJson);
return response.bodyStr(); return response.bodyStr();
} }
@Override @Override
public String videoTasks(String text, String image, List<DoubaoCommon.DoubaoVideo> videoParams) { public String videoTasks(String text, String image, final List<DoubaoCommon.DoubaoVideo> videoParams) {
String paramJson = buildGenerationsTasksRequestBody(text, image, videoParams); String paramJson = buildGenerationsTasksRequestBody(text, image, videoParams);
Response response = sendPost(CREATE_VIDEO, paramJson); Response response = sendPost(CREATE_VIDEO, paramJson);
return response.bodyStr(); return response.bodyStr();
@ -96,9 +112,8 @@ public class DoubaoServiceImpl extends BaseAIService implements DoubaoService {
} }
@Override @Override
public String botsChat(List<Message> messages) { public String botsChat(final List<Message> messages) {
String paramJson = buildBotsChatRequestBody(messages); String paramJson = buildBotsChatRequestBody(messages);
System.out.println(paramJson);
Response response = sendPost(BOTS_CHAT, paramJson); Response response = sendPost(BOTS_CHAT, paramJson);
return response.bodyStr(); return response.bodyStr();
} }
@ -113,24 +128,22 @@ public class DoubaoServiceImpl extends BaseAIService implements DoubaoService {
@Override @Override
public String batchChat(String prompt) { public String batchChat(String prompt) {
// 定义消息结构 // 定义消息结构
List<Message> messages = new ArrayList<>(); final List<Message> messages = new ArrayList<>();
messages.add(new Message("system", "You are a helpful assistant")); messages.add(new Message("system", "You are a helpful assistant"));
messages.add(new Message("user", prompt)); messages.add(new Message("user", prompt));
return batchChat(messages); return batchChat(messages);
} }
@Override @Override
public String batchChat(List<Message> messages) { public String batchChat(final List<Message> messages) {
String paramJson = buildBatchChatRequestBody(messages); String paramJson = buildBatchChatRequestBody(messages);
System.out.println(paramJson);
Response response = sendPost(BATCH_CHAT, paramJson); Response response = sendPost(BATCH_CHAT, paramJson);
return response.bodyStr(); return response.bodyStr();
} }
@Override @Override
public String createContext(List<Message> messages, String mode) { public String createContext(final List<Message> messages, String mode) {
String paramJson = buildCreateContextRequest(messages, mode); String paramJson = buildCreateContextRequest(messages, mode);
System.out.println(paramJson);
Response response = sendPost(CREATE_CONTEXT, paramJson); Response response = sendPost(CREATE_CONTEXT, paramJson);
return response.bodyStr(); return response.bodyStr();
} }
@ -138,22 +151,22 @@ public class DoubaoServiceImpl extends BaseAIService implements DoubaoService {
@Override @Override
public String chatContext(String prompt, String contextId) { public String chatContext(String prompt, String contextId) {
// 定义消息结构 // 定义消息结构
List<Message> messages = new ArrayList<>(); final List<Message> messages = new ArrayList<>();
messages.add(new Message("user", prompt)); messages.add(new Message("user", prompt));
return chatContext(messages, contextId); return chatContext(messages, contextId);
} }
@Override @Override
public String chatContext(List<Message> messages, String contextId) { public String chatContext(final List<Message> messages, String contextId) {
String paramJson = buildChatContentRequestBody(messages, contextId); String paramJson = buildChatContentRequestBody(messages, contextId);
Response response = sendPost(CHAT_CONTEXT, paramJson); Response response = sendPost(CHAT_CONTEXT, paramJson);
return response.bodyStr(); return response.bodyStr();
} }
// 构建chat请求体 // 构建chat请求体
private String buildChatRequestBody(List<Message> messages) { private String buildChatRequestBody(final List<Message> messages) {
//使用JSON工具 //使用JSON工具
Map<String, Object> paramMap = new HashMap<>(); final Map<String, Object> paramMap = new HashMap<>();
paramMap.put("model", config.getModel()); paramMap.put("model", config.getModel());
paramMap.put("messages", messages); paramMap.put("messages", messages);
//合并其他参数 //合并其他参数
@ -163,12 +176,12 @@ public class DoubaoServiceImpl extends BaseAIService implements DoubaoService {
} }
//构建chatVision请求体 //构建chatVision请求体
private String buildChatVisionRequestBody(String prompt, List<String> images, String detail) { private String buildChatVisionRequestBody(String prompt, final List<String> images, String detail) {
// 定义消息结构 // 定义消息结构
List<Message> messages = new ArrayList<>(); final List<Message> messages = new ArrayList<>();
List<Object> content = new ArrayList<>(); final List<Object> content = new ArrayList<>();
Map<String, String> contentMap = new HashMap<>(); final Map<String, String> contentMap = new HashMap<>();
contentMap.put("type", "text"); contentMap.put("type", "text");
contentMap.put("text", prompt); contentMap.put("text", prompt);
content.add(contentMap); content.add(contentMap);
@ -185,7 +198,7 @@ public class DoubaoServiceImpl extends BaseAIService implements DoubaoService {
messages.add(new Message("user", content)); messages.add(new Message("user", content));
//使用JSON工具 //使用JSON工具
Map<String, Object> paramMap = new HashMap<>(); final Map<String, Object> paramMap = new HashMap<>();
paramMap.put("model", config.getModel()); paramMap.put("model", config.getModel());
paramMap.put("messages", messages); paramMap.put("messages", messages);
//合并其他参数 //合并其他参数
@ -196,7 +209,7 @@ public class DoubaoServiceImpl extends BaseAIService implements DoubaoService {
//构建文本向量化请求体 //构建文本向量化请求体
private String buildEmbeddingTextRequestBody(String[] input) { private String buildEmbeddingTextRequestBody(String[] input) {
//使用JSON工具 //使用JSON工具
Map<String, Object> paramMap = new HashMap<>(); final Map<String, Object> paramMap = new HashMap<>();
paramMap.put("model", config.getModel()); paramMap.put("model", config.getModel());
paramMap.put("input", input); paramMap.put("input", input);
//合并其他参数 //合并其他参数
@ -207,22 +220,22 @@ public class DoubaoServiceImpl extends BaseAIService implements DoubaoService {
//构建图文向量化请求体 //构建图文向量化请求体
private String buildEmbeddingVisionRequestBody(String text, String image) { private String buildEmbeddingVisionRequestBody(String text, String image) {
//使用JSON工具 //使用JSON工具
Map<String, Object> paramMap = new HashMap<>(); final Map<String, Object> paramMap = new HashMap<>();
paramMap.put("model", config.getModel()); paramMap.put("model", config.getModel());
List<Object> input = new ArrayList<>(); final List<Object> input = new ArrayList<>();
//添加文本参数 //添加文本参数
if (!StrUtil.isBlank(text)) { if (!StrUtil.isBlank(text)) {
Map<String, String> textMap = new HashMap<>(); final Map<String, String> textMap = new HashMap<>();
textMap.put("type", "text"); textMap.put("type", "text");
textMap.put("text", text); textMap.put("text", text);
input.add(textMap); input.add(textMap);
} }
//添加图片参数 //添加图片参数
if (!StrUtil.isBlank(image)) { if (!StrUtil.isBlank(image)) {
HashMap<String, Object> imgUrlMap = new HashMap<>(); final Map<String, Object> imgUrlMap = new HashMap<>();
imgUrlMap.put("type", "image_url"); imgUrlMap.put("type", "image_url");
HashMap<String, String> urlMap = new HashMap<>(); final Map<String, String> urlMap = new HashMap<>();
urlMap.put("url", image); urlMap.put("url", image);
imgUrlMap.put("image_url", urlMap); imgUrlMap.put("image_url", urlMap);
input.add(imgUrlMap); input.add(imgUrlMap);
@ -236,26 +249,26 @@ public class DoubaoServiceImpl extends BaseAIService implements DoubaoService {
} }
//构建应用chat请求体 //构建应用chat请求体
private String buildBotsChatRequestBody(List<Message> messages) { private String buildBotsChatRequestBody(final List<Message> messages) {
return buildChatRequestBody(messages); return buildChatRequestBody(messages);
} }
//构建分词请求体 //构建分词请求体
private String buildTokenizationRequestBody(String[] text) { private String buildTokenizationRequestBody(String[] text) {
Map<String, Object> paramMap = new HashMap<>(); final Map<String, Object> paramMap = new HashMap<>();
paramMap.put("model", config.getModel()); paramMap.put("model", config.getModel());
paramMap.put("text", text); paramMap.put("text", text);
return JSONUtil.toJsonStr(paramMap); return JSONUtil.toJsonStr(paramMap);
} }
//构建批量推理chat请求体 //构建批量推理chat请求体
private String buildBatchChatRequestBody(List<Message> messages) { private String buildBatchChatRequestBody(final List<Message> messages) {
return buildChatRequestBody(messages); return buildChatRequestBody(messages);
} }
//构建创建上下文缓存请求体 //构建创建上下文缓存请求体
private String buildCreateContextRequest(List<Message> messages, String mode) { private String buildCreateContextRequest(final List<Message> messages, String mode) {
Map<String, Object> paramMap = new HashMap<>(); final Map<String, Object> paramMap = new HashMap<>();
paramMap.put("messages", messages); paramMap.put("messages", messages);
paramMap.put("model", config.getModel()); paramMap.put("model", config.getModel());
paramMap.put("mode", mode); paramMap.put("mode", mode);
@ -266,9 +279,9 @@ public class DoubaoServiceImpl extends BaseAIService implements DoubaoService {
} }
//构建上下文缓存对话请求体 //构建上下文缓存对话请求体
private String buildChatContentRequestBody(List<Message> messages, String contextId) { private String buildChatContentRequestBody(final List<Message> messages, String contextId) {
//使用JSON工具 //使用JSON工具
Map<String, Object> paramMap = new HashMap<>(); final Map<String, Object> paramMap = new HashMap<>();
paramMap.put("model", config.getModel()); paramMap.put("model", config.getModel());
paramMap.put("messages", messages); paramMap.put("messages", messages);
paramMap.put("context_id", contextId); paramMap.put("context_id", contextId);
@ -279,14 +292,14 @@ public class DoubaoServiceImpl extends BaseAIService implements DoubaoService {
} }
//构建创建视频任务请求体 //构建创建视频任务请求体
private String buildGenerationsTasksRequestBody(String text, String image, List<DoubaoCommon.DoubaoVideo> videoParams) { private String buildGenerationsTasksRequestBody(String text, String image, final List<DoubaoCommon.DoubaoVideo> videoParams) {
//使用JSON工具 //使用JSON工具
Map<String, Object> paramMap = new HashMap<>(); final Map<String, Object> paramMap = new HashMap<>();
paramMap.put("model", config.getModel()); paramMap.put("model", config.getModel());
List<Object> content = new ArrayList<>(); final List<Object> content = new ArrayList<>();
//添加文本参数 //添加文本参数
Map<String, String> textMap = new HashMap<>(); final Map<String, String> textMap = new HashMap<>();
if (!StrUtil.isBlank(text)) { if (!StrUtil.isBlank(text)) {
textMap.put("type", "text"); textMap.put("type", "text");
textMap.put("text", text); textMap.put("text", text);
@ -294,9 +307,9 @@ public class DoubaoServiceImpl extends BaseAIService implements DoubaoService {
} }
//添加图片参数 //添加图片参数
if (!StrUtil.isNotBlank(image)) { if (!StrUtil.isNotBlank(image)) {
Map<String, Object> imgUrlMap = new HashMap<>(); final Map<String, Object> imgUrlMap = new HashMap<>();
imgUrlMap.put("type", "image_url"); imgUrlMap.put("type", "image_url");
HashMap<String, String> urlMap = new HashMap<>(); final Map<String, String> urlMap = new HashMap<>();
urlMap.put("url", image); urlMap.put("url", image);
imgUrlMap.put("image_url", urlMap); imgUrlMap.put("image_url", urlMap);
content.add(imgUrlMap); content.add(imgUrlMap);

View File

@ -0,0 +1,24 @@
/*
* Copyright (c) 2025 Hutool Team and hutool.cn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* 对doubao的封装实现
*
* @author elichow
* @since 6.0.0
*/
package org.dromara.hutool.ai.model.doubao;

View File

@ -1,3 +1,19 @@
/*
* Copyright (c) 2025 Hutool Team and hutool.cn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dromara.hutool.ai.model.grok; package org.dromara.hutool.ai.model.grok;
/** /**

View File

@ -1,3 +1,19 @@
/*
* Copyright (c) 2025 Hutool Team and hutool.cn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dromara.hutool.ai.model.grok; package org.dromara.hutool.ai.model.grok;
import org.dromara.hutool.ai.Models; import org.dromara.hutool.ai.Models;

View File

@ -1,3 +1,19 @@
/*
* Copyright (c) 2025 Hutool Team and hutool.cn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dromara.hutool.ai.model.grok; package org.dromara.hutool.ai.model.grok;
import org.dromara.hutool.ai.core.AIConfig; import org.dromara.hutool.ai.core.AIConfig;
@ -17,7 +33,7 @@ public class GrokProvider implements AIServiceProvider {
} }
@Override @Override
public GrokService create(AIConfig config) { public GrokService create(final AIConfig config) {
return new GrokServiceImpl(config); return new GrokServiceImpl(config);
} }
} }

View File

@ -1,3 +1,19 @@
/*
* Copyright (c) 2025 Hutool Team and hutool.cn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dromara.hutool.ai.model.grok; package org.dromara.hutool.ai.model.grok;
import org.dromara.hutool.ai.core.AIService; import org.dromara.hutool.ai.core.AIService;
@ -31,7 +47,7 @@ public interface GrokService extends AIService {
* @return AI回答 * @return AI回答
* @since 6.0.0 * @since 6.0.0
*/ */
String chatVision(String prompt, List<String> images, String detail); String chatVision(String prompt, final List<String> images, String detail);
/** /**
* 图像理解模型会依据传入的图片信息以及问题给出回复 * 图像理解模型会依据传入的图片信息以及问题给出回复
@ -41,7 +57,7 @@ public interface GrokService extends AIService {
* @return AI回答 * @return AI回答
* @since 6.0.0 * @since 6.0.0
*/ */
default String chatVision(String prompt, List<String> images) { default String chatVision(String prompt, final List<String> images) {
return chatVision(prompt, images, GrokCommon.GrokVision.AUTO.getDetail()); return chatVision(prompt, images, GrokCommon.GrokVision.AUTO.getDetail());
} }

View File

@ -1,3 +1,19 @@
/*
* Copyright (c) 2025 Hutool Team and hutool.cn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dromara.hutool.ai.model.grok; package org.dromara.hutool.ai.model.grok;
import org.dromara.hutool.ai.core.AIConfig; import org.dromara.hutool.ai.core.AIConfig;
@ -32,7 +48,7 @@ public class GrokServiceImpl extends BaseAIService implements GrokService {
//获取延迟对话 //获取延迟对话
private final String DEFERRED_COMPLETION = "/chat/deferred-completion"; private final String DEFERRED_COMPLETION = "/chat/deferred-completion";
public GrokServiceImpl(AIConfig config) { public GrokServiceImpl(final AIConfig config) {
//初始化grok客户端 //初始化grok客户端
super(config); super(config);
} }
@ -40,14 +56,14 @@ public class GrokServiceImpl extends BaseAIService implements GrokService {
@Override @Override
public String chat(String prompt) { public String chat(String prompt) {
// 定义消息结构 // 定义消息结构
List<Message> messages = new ArrayList<>(); final List<Message> messages = new ArrayList<>();
messages.add(new Message("system", "You are a helpful assistant")); messages.add(new Message("system", "You are a helpful assistant"));
messages.add(new Message("user", prompt)); messages.add(new Message("user", prompt));
return chat(messages); return chat(messages);
} }
@Override @Override
public String chat(List<Message> messages) { public String chat(final List<Message> messages) {
String paramJson = buildChatRequestBody(messages); String paramJson = buildChatRequestBody(messages);
Response response = sendPost(CHAT_ENDPOINT, paramJson); Response response = sendPost(CHAT_ENDPOINT, paramJson);
return response.bodyStr(); return response.bodyStr();
@ -56,7 +72,7 @@ public class GrokServiceImpl extends BaseAIService implements GrokService {
@Override @Override
public String message(String prompt, int maxToken) { public String message(String prompt, int maxToken) {
// 定义消息结构 // 定义消息结构
List<Message> messages = new ArrayList<>(); final List<Message> messages = new ArrayList<>();
messages.add(new Message("system", "You are a helpful assistant")); messages.add(new Message("system", "You are a helpful assistant"));
messages.add(new Message("user", prompt)); messages.add(new Message("user", prompt));
String paramJson = buildMessageRequestBody(messages, maxToken); String paramJson = buildMessageRequestBody(messages, maxToken);
@ -65,7 +81,7 @@ public class GrokServiceImpl extends BaseAIService implements GrokService {
} }
@Override @Override
public String chatVision(String prompt, List<String> images, String detail) { public String chatVision(String prompt, final List<String> images, String detail) {
String paramJson = buildChatVisionRequestBody(prompt, images, detail); String paramJson = buildChatVisionRequestBody(prompt, images, detail);
Response response = sendPost(CHAT_ENDPOINT, paramJson); Response response = sendPost(CHAT_ENDPOINT, paramJson);
return response.bodyStr(); return response.bodyStr();
@ -109,9 +125,9 @@ public class GrokServiceImpl extends BaseAIService implements GrokService {
} }
// 构建chat请求体 // 构建chat请求体
private String buildChatRequestBody(List<Message> messages) { private String buildChatRequestBody(final List<Message> messages) {
//使用JSON工具 //使用JSON工具
Map<String, Object> paramMap = new HashMap<>(); final Map<String, Object> paramMap = new HashMap<>();
paramMap.put("model", config.getModel()); paramMap.put("model", config.getModel());
paramMap.put("messages", messages); paramMap.put("messages", messages);
//合并其他参数 //合并其他参数
@ -121,12 +137,12 @@ public class GrokServiceImpl extends BaseAIService implements GrokService {
} }
//构建chatVision请求体 //构建chatVision请求体
private String buildChatVisionRequestBody(String prompt, List<String> images, String detail) { private String buildChatVisionRequestBody(String prompt, final List<String> images, String detail) {
// 定义消息结构 // 定义消息结构
List<Message> messages = new ArrayList<>(); final List<Message> messages = new ArrayList<>();
List<Object> content = new ArrayList<>(); final List<Object> content = new ArrayList<>();
Map<String, String> contentMap = new HashMap<>(); final Map<String, String> contentMap = new HashMap<>();
contentMap.put("type", "text"); contentMap.put("type", "text");
contentMap.put("text", prompt); contentMap.put("text", prompt);
content.add(contentMap); content.add(contentMap);
@ -143,7 +159,7 @@ public class GrokServiceImpl extends BaseAIService implements GrokService {
messages.add(new Message("user", content)); messages.add(new Message("user", content));
//使用JSON工具 //使用JSON工具
Map<String, Object> paramMap = new HashMap<>(); final Map<String, Object> paramMap = new HashMap<>();
paramMap.put("model", config.getModel()); paramMap.put("model", config.getModel());
paramMap.put("messages", messages); paramMap.put("messages", messages);
//合并其他参数 //合并其他参数
@ -152,8 +168,8 @@ public class GrokServiceImpl extends BaseAIService implements GrokService {
} }
//构建消息回复请求体 //构建消息回复请求体
private String buildMessageRequestBody(List<Message> messages, int maxToken) { private String buildMessageRequestBody(final List<Message> messages, int maxToken) {
Map<String, Object> paramMap = new HashMap<>(); final Map<String, Object> paramMap = new HashMap<>();
paramMap.put("model", config.getModel()); paramMap.put("model", config.getModel());
paramMap.put("messages", messages); paramMap.put("messages", messages);
paramMap.put("max_tokens", maxToken); paramMap.put("max_tokens", maxToken);
@ -166,7 +182,7 @@ public class GrokServiceImpl extends BaseAIService implements GrokService {
//构建分词请求体 //构建分词请求体
private String buildTokenizeRequestBody(String text) { private String buildTokenizeRequestBody(String text) {
//使用JSON工具 //使用JSON工具
Map<String, Object> paramMap = new HashMap<>(); final Map<String, Object> paramMap = new HashMap<>();
paramMap.put("model", config.getModel()); paramMap.put("model", config.getModel());
paramMap.put("text", text); paramMap.put("text", text);
//合并其他参数 //合并其他参数

View File

@ -0,0 +1,24 @@
/*
* Copyright (c) 2025 Hutool Team and hutool.cn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* 对grok的封装实现
*
* @author elichow
* @since 6.0.0
*/
package org.dromara.hutool.ai.model.grok;

View File

@ -1,3 +1,19 @@
/*
* Copyright (c) 2025 Hutool Team and hutool.cn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dromara.hutool.ai.model.openai; package org.dromara.hutool.ai.model.openai;
/** /**

View File

@ -1,5 +1,20 @@
package org.dromara.hutool.ai.model.openai; /*
* Copyright (c) 2025 Hutool Team and hutool.cn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dromara.hutool.ai.model.openai;
import org.dromara.hutool.ai.Models; import org.dromara.hutool.ai.Models;
import org.dromara.hutool.ai.core.BaseConfig; import org.dromara.hutool.ai.core.BaseConfig;

View File

@ -1,5 +1,20 @@
package org.dromara.hutool.ai.model.openai; /*
* Copyright (c) 2025 Hutool Team and hutool.cn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dromara.hutool.ai.model.openai;
import org.dromara.hutool.ai.core.AIConfig; import org.dromara.hutool.ai.core.AIConfig;
import org.dromara.hutool.ai.core.AIServiceProvider; import org.dromara.hutool.ai.core.AIServiceProvider;
@ -18,7 +33,7 @@ public class OpenaiProvider implements AIServiceProvider {
} }
@Override @Override
public OpenaiService create(AIConfig config) { public OpenaiService create(final AIConfig config) {
return new OpenaiServiceImpl(config); return new OpenaiServiceImpl(config);
} }
} }

View File

@ -1,3 +1,19 @@
/*
* Copyright (c) 2025 Hutool Team and hutool.cn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dromara.hutool.ai.model.openai; package org.dromara.hutool.ai.model.openai;
import org.dromara.hutool.ai.core.AIService; import org.dromara.hutool.ai.core.AIService;
@ -24,7 +40,7 @@ public interface OpenaiService extends AIService {
* @return AI回答 * @return AI回答
* @since 6.0.0 * @since 6.0.0
*/ */
String chatVision(String prompt, List<String> images, String detail); String chatVision(String prompt, final List<String> images, String detail);
/** /**
* 图像理解模型会依据传入的图片信息以及问题给出回复 * 图像理解模型会依据传入的图片信息以及问题给出回复
@ -34,7 +50,7 @@ public interface OpenaiService extends AIService {
* @return AI回答 * @return AI回答
* @since 6.0.0 * @since 6.0.0
*/ */
default String chatVision(String prompt, List<String> images) { default String chatVision(String prompt, final List<String> images) {
return chatVision(prompt, images, OpenaiCommon.OpenaiVision.AUTO.getDetail()); return chatVision(prompt, images, OpenaiCommon.OpenaiVision.AUTO.getDetail());
} }
@ -56,7 +72,7 @@ public interface OpenaiService extends AIService {
* @return 包含生成图片的url * @return 包含生成图片的url
* @since 6.0.0 * @since 6.0.0
*/ */
String imagesEdits(String prompt, File image, File mask); String imagesEdits(String prompt, final File image, final File mask);
/** /**
* 图片编辑 该方法仅支持 DALL·E 2 model * 图片编辑 该方法仅支持 DALL·E 2 model
@ -66,7 +82,7 @@ public interface OpenaiService extends AIService {
* @return 包含生成图片的url * @return 包含生成图片的url
* @since 6.0.0 * @since 6.0.0
*/ */
default String imagesEdits(String prompt, File image) { default String imagesEdits(String prompt, final File image) {
return imagesEdits(prompt, image, null); return imagesEdits(prompt, image, null);
} }
@ -77,7 +93,7 @@ public interface OpenaiService extends AIService {
* @return 包含生成图片的url * @return 包含生成图片的url
* @since 6.0.0 * @since 6.0.0
*/ */
String imagesVariations(File image); String imagesVariations(final File image);
/** /**
* TTS文本转语音 请设置config中model为支持TTS功能的模型 TTS系列 * TTS文本转语音 请设置config中model为支持TTS功能的模型 TTS系列
@ -87,7 +103,7 @@ public interface OpenaiService extends AIService {
* @return 返回的音频mp3文件流 * @return 返回的音频mp3文件流
* @since 6.0.0 * @since 6.0.0
*/ */
InputStream textToSpeech(String input, OpenaiCommon.OpenaiSpeech voice); InputStream textToSpeech(String input, final OpenaiCommon.OpenaiSpeech voice);
/** /**
* TTS文本转语音 请设置config中model为支持TTS功能的模型 TTS系列 * TTS文本转语音 请设置config中model为支持TTS功能的模型 TTS系列
@ -107,7 +123,7 @@ public interface OpenaiService extends AIService {
* @return 返回的文本内容 * @return 返回的文本内容
* @since 6.0.0 * @since 6.0.0
*/ */
String speechToText(File file); String speechToText(final File file);
/** /**
* 文本向量化 请设置config中model为支持文本向量化功能的模型 text-embedding系列 * 文本向量化 请设置config中model为支持文本向量化功能的模型 text-embedding系列
@ -173,7 +189,7 @@ public interface OpenaiService extends AIService {
* @return AI回答 * @return AI回答
* @since 6.0.0 * @since 6.0.0
*/ */
String chatReasoning(List<Message> messages, String reasoningEffort); String chatReasoning(final List<Message> messages, String reasoningEffort);
/** /**
* 推理chat * 推理chat
@ -183,7 +199,7 @@ public interface OpenaiService extends AIService {
* @return AI回答 * @return AI回答
* @since 6.0.0 * @since 6.0.0
*/ */
default String chatReasoning(List<Message> messages) { default String chatReasoning(final List<Message> messages) {
return chatReasoning(messages, OpenaiCommon.OpenaiReasoning.MEDIUM.getEffort()); return chatReasoning(messages, OpenaiCommon.OpenaiReasoning.MEDIUM.getEffort());
} }

View File

@ -1,3 +1,19 @@
/*
* Copyright (c) 2025 Hutool Team and hutool.cn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dromara.hutool.ai.model.openai; package org.dromara.hutool.ai.model.openai;
import org.dromara.hutool.ai.core.AIConfig; import org.dromara.hutool.ai.core.AIConfig;
@ -39,7 +55,7 @@ public class OpenaiServiceImpl extends BaseAIService implements OpenaiService {
//检查文本或图片 //检查文本或图片
private final String MODERATIONS = "/moderations"; private final String MODERATIONS = "/moderations";
public OpenaiServiceImpl(AIConfig config) { public OpenaiServiceImpl(final AIConfig config) {
//初始化Openai客户端 //初始化Openai客户端
super(config); super(config);
} }
@ -47,21 +63,21 @@ public class OpenaiServiceImpl extends BaseAIService implements OpenaiService {
@Override @Override
public String chat(String prompt) { public String chat(String prompt) {
// 定义消息结构 // 定义消息结构
List<Message> messages = new ArrayList<>(); final List<Message> messages = new ArrayList<>();
messages.add(new Message("system", "You are a helpful assistant")); messages.add(new Message("system", "You are a helpful assistant"));
messages.add(new Message("user", prompt)); messages.add(new Message("user", prompt));
return chat(messages); return chat(messages);
} }
@Override @Override
public String chat(List<Message> messages) { public String chat(final List<Message> messages) {
String paramJson = buildChatRequestBody(messages); String paramJson = buildChatRequestBody(messages);
Response response = sendPost(CHAT_ENDPOINT, paramJson); Response response = sendPost(CHAT_ENDPOINT, paramJson);
return response.bodyStr(); return response.bodyStr();
} }
@Override @Override
public String chatVision(String prompt, List<String> images, String detail) { public String chatVision(String prompt, final List<String> images, String detail) {
String paramJson = buildChatVisionRequestBody(prompt, images, detail); String paramJson = buildChatVisionRequestBody(prompt, images, detail);
Response response = sendPost(CHAT_ENDPOINT, paramJson); Response response = sendPost(CHAT_ENDPOINT, paramJson);
return response.bodyStr(); return response.bodyStr();
@ -75,29 +91,29 @@ public class OpenaiServiceImpl extends BaseAIService implements OpenaiService {
} }
@Override @Override
public String imagesEdits(String prompt, File image, File mask) { public String imagesEdits(String prompt, final File image, final File mask) {
Map<String, Object> paramMap = buildImagesEditsRequestBody(prompt, image, mask); final Map<String, Object> paramMap = buildImagesEditsRequestBody(prompt, image, mask);
Response response = sendFormData(IMAGES_EDITS, paramMap); Response response = sendFormData(IMAGES_EDITS, paramMap);
return response.bodyStr(); return response.bodyStr();
} }
@Override @Override
public String imagesVariations(File image) { public String imagesVariations(final File image) {
Map<String, Object> paramMap = buildImagesVariationsRequestBody(image); final Map<String, Object> paramMap = buildImagesVariationsRequestBody(image);
Response response = sendFormData(IMAGES_VARIATIONS, paramMap); Response response = sendFormData(IMAGES_VARIATIONS, paramMap);
return response.bodyStr(); return response.bodyStr();
} }
@Override @Override
public InputStream textToSpeech(String input, OpenaiCommon.OpenaiSpeech voice) { public InputStream textToSpeech(String input, final OpenaiCommon.OpenaiSpeech voice) {
String paramJson = buildTTSRequestBody(input, voice.getVoice()); String paramJson = buildTTSRequestBody(input, voice.getVoice());
Response response = sendPost(TTS, paramJson); Response response = sendPost(TTS, paramJson);
return response.bodyStream(); return response.bodyStream();
} }
@Override @Override
public String speechToText(File file) { public String speechToText(final File file) {
Map<String, Object> paramMap = buildSTTRequestBody(file); final Map<String, Object> paramMap = buildSTTRequestBody(file);
Response response = sendFormData(STT, paramMap); Response response = sendFormData(STT, paramMap);
return response.bodyStr(); return response.bodyStr();
} }
@ -119,23 +135,23 @@ public class OpenaiServiceImpl extends BaseAIService implements OpenaiService {
@Override @Override
public String chatReasoning(String prompt, String reasoningEffort) { public String chatReasoning(String prompt, String reasoningEffort) {
// 定义消息结构 // 定义消息结构
List<Message> messages = new ArrayList<>(); final List<Message> messages = new ArrayList<>();
messages.add(new Message("system", "You are a helpful assistant")); messages.add(new Message("system", "You are a helpful assistant"));
messages.add(new Message("user", prompt)); messages.add(new Message("user", prompt));
return chat(messages); return chat(messages);
} }
@Override @Override
public String chatReasoning(List<Message> messages, String reasoningEffort) { public String chatReasoning(final List<Message> messages, String reasoningEffort) {
String paramJson = buildChatReasoningRequestBody(messages, reasoningEffort); String paramJson = buildChatReasoningRequestBody(messages, reasoningEffort);
Response response = sendPost(CHAT_ENDPOINT, paramJson); Response response = sendPost(CHAT_ENDPOINT, paramJson);
return response.bodyStr(); return response.bodyStr();
} }
// 构建chat请求体 // 构建chat请求体
private String buildChatRequestBody(List<Message> messages) { private String buildChatRequestBody(final List<Message> messages) {
//使用JSON工具 //使用JSON工具
Map<String, Object> paramMap = new HashMap<>(); final Map<String, Object> paramMap = new HashMap<>();
paramMap.put("model", config.getModel()); paramMap.put("model", config.getModel());
paramMap.put("messages", messages); paramMap.put("messages", messages);
//合并其他参数 //合并其他参数
@ -145,19 +161,19 @@ public class OpenaiServiceImpl extends BaseAIService implements OpenaiService {
} }
//构建chatVision请求体 //构建chatVision请求体
private String buildChatVisionRequestBody(String prompt, List<String> images, String detail) { private String buildChatVisionRequestBody(String prompt, final List<String> images, String detail) {
// 定义消息结构 // 定义消息结构
List<Message> messages = new ArrayList<>(); final List<Message> messages = new ArrayList<>();
List<Object> content = new ArrayList<>(); final List<Object> content = new ArrayList<>();
Map<String, String> contentMap = new HashMap<>(); final Map<String, String> contentMap = new HashMap<>();
contentMap.put("type", "text"); contentMap.put("type", "text");
contentMap.put("text", prompt); contentMap.put("text", prompt);
content.add(contentMap); content.add(contentMap);
for (String img : images) { for (String img : images) {
HashMap<String, Object> imgUrlMap = new HashMap<>(); final Map<String, Object> imgUrlMap = new HashMap<>();
imgUrlMap.put("type", "image_url"); imgUrlMap.put("type", "image_url");
HashMap<String, String> urlMap = new HashMap<>(); final Map<String, String> urlMap = new HashMap<>();
urlMap.put("url", img); urlMap.put("url", img);
urlMap.put("detail", detail); urlMap.put("detail", detail);
imgUrlMap.put("image_url", urlMap); imgUrlMap.put("image_url", urlMap);
@ -167,7 +183,7 @@ public class OpenaiServiceImpl extends BaseAIService implements OpenaiService {
messages.add(new Message("user", content)); messages.add(new Message("user", content));
//使用JSON工具 //使用JSON工具
Map<String, Object> paramMap = new HashMap<>(); final Map<String, Object> paramMap = new HashMap<>();
paramMap.put("model", config.getModel()); paramMap.put("model", config.getModel());
paramMap.put("messages", messages); paramMap.put("messages", messages);
//合并其他参数 //合并其他参数
@ -177,7 +193,7 @@ public class OpenaiServiceImpl extends BaseAIService implements OpenaiService {
//构建文生图请求体 //构建文生图请求体
private String buildImagesGenerationsRequestBody(String prompt) { private String buildImagesGenerationsRequestBody(String prompt) {
Map<String, Object> paramMap = new HashMap<>(); final Map<String, Object> paramMap = new HashMap<>();
paramMap.put("model", config.getModel()); paramMap.put("model", config.getModel());
paramMap.put("prompt", prompt); paramMap.put("prompt", prompt);
//合并其他参数 //合并其他参数
@ -187,8 +203,8 @@ public class OpenaiServiceImpl extends BaseAIService implements OpenaiService {
} }
//构建图片编辑请求体 //构建图片编辑请求体
private Map<String, Object> buildImagesEditsRequestBody(String prompt, File image, File mask) { private Map<String, Object> buildImagesEditsRequestBody(String prompt, final File image, final File mask) {
Map<String, Object> paramMap = new HashMap<>(); final Map<String, Object> paramMap = new HashMap<>();
paramMap.put("model", config.getModel()); paramMap.put("model", config.getModel());
paramMap.put("prompt", prompt); paramMap.put("prompt", prompt);
paramMap.put("image", image); paramMap.put("image", image);
@ -202,8 +218,8 @@ public class OpenaiServiceImpl extends BaseAIService implements OpenaiService {
} }
//构建图片变形请求体 //构建图片变形请求体
private Map<String, Object> buildImagesVariationsRequestBody(File image) { private Map<String, Object> buildImagesVariationsRequestBody(final File image) {
Map<String, Object> paramMap = new HashMap<>(); final Map<String, Object> paramMap = new HashMap<>();
paramMap.put("model", config.getModel()); paramMap.put("model", config.getModel());
paramMap.put("image", image); paramMap.put("image", image);
//合并其他参数 //合并其他参数
@ -214,7 +230,7 @@ public class OpenaiServiceImpl extends BaseAIService implements OpenaiService {
//构建TTS请求体 //构建TTS请求体
private String buildTTSRequestBody(String input, String voice) { private String buildTTSRequestBody(String input, String voice) {
Map<String, Object> paramMap = new HashMap<>(); final Map<String, Object> paramMap = new HashMap<>();
paramMap.put("model", config.getModel()); paramMap.put("model", config.getModel());
paramMap.put("input", input); paramMap.put("input", input);
paramMap.put("voice", voice); paramMap.put("voice", voice);
@ -225,8 +241,8 @@ public class OpenaiServiceImpl extends BaseAIService implements OpenaiService {
} }
//构建STT请求体 //构建STT请求体
private Map<String, Object> buildSTTRequestBody(File file) { private Map<String, Object> buildSTTRequestBody(final File file) {
Map<String, Object> paramMap = new HashMap<>(); final Map<String, Object> paramMap = new HashMap<>();
paramMap.put("model", config.getModel()); paramMap.put("model", config.getModel());
paramMap.put("file", file); paramMap.put("file", file);
//合并其他参数 //合并其他参数
@ -238,7 +254,7 @@ public class OpenaiServiceImpl extends BaseAIService implements OpenaiService {
//构建文本向量化请求体 //构建文本向量化请求体
private String buildEmbeddingTextRequestBody(String input) { private String buildEmbeddingTextRequestBody(String input) {
//使用JSON工具 //使用JSON工具
Map<String, Object> paramMap = new HashMap<>(); final Map<String, Object> paramMap = new HashMap<>();
paramMap.put("model", config.getModel()); paramMap.put("model", config.getModel());
paramMap.put("input", input); paramMap.put("input", input);
//合并其他参数 //合并其他参数
@ -249,22 +265,22 @@ public class OpenaiServiceImpl extends BaseAIService implements OpenaiService {
//构建检查图片或文字请求体 //构建检查图片或文字请求体
private String buileModerationsRequestBody(String text, String imgUrl) { private String buileModerationsRequestBody(String text, String imgUrl) {
//使用JSON工具 //使用JSON工具
Map<String, Object> paramMap = new HashMap<>(); final Map<String, Object> paramMap = new HashMap<>();
paramMap.put("model", config.getModel()); paramMap.put("model", config.getModel());
List<Object> input = new ArrayList<>(); final List<Object> input = new ArrayList<>();
//添加文本参数 //添加文本参数
if (!StrUtil.isBlank(text)) { if (!StrUtil.isBlank(text)) {
Map<String, String> textMap = new HashMap<>(); final Map<String, String> textMap = new HashMap<>();
textMap.put("type", "text"); textMap.put("type", "text");
textMap.put("text", text); textMap.put("text", text);
input.add(textMap); input.add(textMap);
} }
//添加图片参数 //添加图片参数
if (!StrUtil.isBlank(imgUrl)) { if (!StrUtil.isBlank(imgUrl)) {
HashMap<String, Object> imgUrlMap = new HashMap<>(); final Map<String, Object> imgUrlMap = new HashMap<>();
imgUrlMap.put("type", "image_url"); imgUrlMap.put("type", "image_url");
HashMap<String, String> urlMap = new HashMap<>(); final Map<String, String> urlMap = new HashMap<>();
urlMap.put("url", imgUrl); urlMap.put("url", imgUrl);
imgUrlMap.put("image_url", urlMap); imgUrlMap.put("image_url", urlMap);
input.add(imgUrlMap); input.add(imgUrlMap);
@ -278,8 +294,8 @@ public class OpenaiServiceImpl extends BaseAIService implements OpenaiService {
} }
//构建推理请求体 //构建推理请求体
private String buildChatReasoningRequestBody(List<Message> messages, String reasoningEffort) { private String buildChatReasoningRequestBody(final List<Message> messages, String reasoningEffort) {
Map<String, Object> paramMap = new HashMap<>(); final Map<String, Object> paramMap = new HashMap<>();
paramMap.put("model", config.getModel()); paramMap.put("model", config.getModel());
paramMap.put("messages", messages); paramMap.put("messages", messages);
paramMap.put("reasoning_effort", reasoningEffort); paramMap.put("reasoning_effort", reasoningEffort);

View File

@ -0,0 +1,24 @@
/*
* Copyright (c) 2025 Hutool Team and hutool.cn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* 对openai的封装实现
*
* @author elichow
* @since 6.0.0
*/
package org.dromara.hutool.ai.model.openai;

View File

@ -0,0 +1,24 @@
/*
* Copyright (c) 2025 Hutool Team and hutool.cn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* 对各个AI大模型的相关封装
*
* @author elichow
* @since 6.0.0
*/
package org.dromara.hutool.ai.model;

View File

@ -15,8 +15,10 @@
*/ */
/** /**
* AI模块 * Hutool-ai主要用于AI大模型的封装只需要对AI模型最基本的设置即可调用AI大模型
* *
* @author elichow * @author elichow
* @since 6.0.0
*/ */
package org.dromara.hutool.ai; package org.dromara.hutool.ai;

View File

@ -1,3 +1,19 @@
/*
* Copyright (c) 2025 Hutool Team and hutool.cn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dromara.hutool.ai; package org.dromara.hutool.ai;
import org.dromara.hutool.ai.core.AIConfigBuilder; import org.dromara.hutool.ai.core.AIConfigBuilder;

View File

@ -1,3 +1,19 @@
/*
* Copyright (c) 2025 Hutool Team and hutool.cn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dromara.hutool.ai; package org.dromara.hutool.ai;
import org.dromara.hutool.ai.core.AIConfigBuilder; import org.dromara.hutool.ai.core.AIConfigBuilder;

View File

@ -1,3 +1,19 @@
/*
* Copyright (c) 2025 Hutool Team and hutool.cn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dromara.hutool.ai.model.deepseek; package org.dromara.hutool.ai.model.deepseek;
import org.dromara.hutool.ai.AIServiceFactory; import org.dromara.hutool.ai.AIServiceFactory;

View File

@ -1,3 +1,19 @@
/*
* Copyright (c) 2025 Hutool Team and hutool.cn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dromara.hutool.ai.model.doubao; package org.dromara.hutool.ai.model.doubao;
import org.dromara.hutool.ai.AIServiceFactory; import org.dromara.hutool.ai.AIServiceFactory;
@ -13,8 +29,6 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
class DoubaoServiceTest { class DoubaoServiceTest {
String key = "your key"; String key = "your key";

View File

@ -1,3 +1,19 @@
/*
* Copyright (c) 2025 Hutool Team and hutool.cn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dromara.hutool.ai.model.grok; package org.dromara.hutool.ai.model.grok;
import org.dromara.hutool.ai.AIServiceFactory; import org.dromara.hutool.ai.AIServiceFactory;

View File

@ -1,3 +1,19 @@
/*
* Copyright (c) 2025 Hutool Team and hutool.cn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dromara.hutool.ai.model.openai; package org.dromara.hutool.ai.model.openai;
import org.dromara.hutool.ai.AIServiceFactory; import org.dromara.hutool.ai.AIServiceFactory;