From e291654d8c067d650280c740983f8fe73fc8e93d Mon Sep 17 00:00:00 2001 From: choweli <1030848819@qq.com> Date: Wed, 26 Mar 2025 16:46:12 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E8=A7=84=E8=8C=83=E5=BB=BA?= =?UTF-8?q?=E8=AE=AE=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/dromara/hutool/ai/AIException.java | 16 ++++ .../dromara/hutool/ai/AIServiceFactory.java | 16 ++++ .../java/org/dromara/hutool/ai/AIUtil.java | 16 ++++ .../java/org/dromara/hutool/ai/ModelName.java | 16 ++++ .../java/org/dromara/hutool/ai/Models.java | 16 ++++ .../org/dromara/hutool/ai/core/AIConfig.java | 16 ++++ .../hutool/ai/core/AIConfigBuilder.java | 16 ++++ .../hutool/ai/core/AIConfigRegistry.java | 16 ++++ .../org/dromara/hutool/ai/core/AIService.java | 18 +++- .../hutool/ai/core/AIServiceProvider.java | 20 +++- .../dromara/hutool/ai/core/BaseAIService.java | 33 +++++++ .../dromara/hutool/ai/core/BaseConfig.java | 17 +++- .../org/dromara/hutool/ai/core/Message.java | 16 ++++ .../dromara/hutool/ai/core/package-info.java | 2 + .../ai/model/deepseek/DeepSeekCommon.java | 16 ++++ .../ai/model/deepseek/DeepSeekConfig.java | 16 ++++ .../ai/model/deepseek/DeepSeekProvider.java | 19 +++- .../ai/model/deepseek/DeepSeekService.java | 16 ++++ .../model/deepseek/DeepSeekServiceImpl.java | 28 ++++-- .../ai/model/deepseek/package-info.java | 24 +++++ .../hutool/ai/model/doubao/DoubaoCommon.java | 18 +++- .../hutool/ai/model/doubao/DoubaoConfig.java | 16 ++++ .../ai/model/doubao/DoubaoProvider.java | 18 +++- .../hutool/ai/model/doubao/DoubaoService.java | 32 +++++-- .../ai/model/doubao/DoubaoServiceImpl.java | 93 +++++++++++-------- .../hutool/ai/model/doubao/package-info.java | 24 +++++ .../hutool/ai/model/grok/GrokCommon.java | 16 ++++ .../hutool/ai/model/grok/GrokConfig.java | 16 ++++ .../hutool/ai/model/grok/GrokProvider.java | 18 +++- .../hutool/ai/model/grok/GrokService.java | 20 +++- .../hutool/ai/model/grok/GrokServiceImpl.java | 46 ++++++--- .../hutool/ai/model/grok/package-info.java | 24 +++++ .../hutool/ai/model/openai/OpenaiCommon.java | 16 ++++ .../hutool/ai/model/openai/OpenaiConfig.java | 17 +++- .../ai/model/openai/OpenaiProvider.java | 19 +++- .../hutool/ai/model/openai/OpenaiService.java | 34 +++++-- .../ai/model/openai/OpenaiServiceImpl.java | 92 ++++++++++-------- .../hutool/ai/model/openai/package-info.java | 24 +++++ .../dromara/hutool/ai/model/package-info.java | 24 +++++ .../org/dromara/hutool/ai/package-info.java | 4 +- .../hutool/ai/AIServiceFactoryTest.java | 16 ++++ .../org/dromara/hutool/ai/AIUtilTest.java | 16 ++++ .../model/deepseek/DeepSeekServiceTest.java | 16 ++++ .../ai/model/doubao/DoubaoServiceTest.java | 18 +++- .../hutool/ai/model/grok/GrokServiceTest.java | 16 ++++ .../ai/model/openai/OpenaiServiceTest.java | 16 ++++ 46 files changed, 889 insertions(+), 133 deletions(-) create mode 100644 hutool-ai/src/main/java/org/dromara/hutool/ai/model/deepseek/package-info.java create mode 100644 hutool-ai/src/main/java/org/dromara/hutool/ai/model/doubao/package-info.java create mode 100644 hutool-ai/src/main/java/org/dromara/hutool/ai/model/grok/package-info.java create mode 100644 hutool-ai/src/main/java/org/dromara/hutool/ai/model/openai/package-info.java create mode 100644 hutool-ai/src/main/java/org/dromara/hutool/ai/model/package-info.java diff --git a/hutool-ai/src/main/java/org/dromara/hutool/ai/AIException.java b/hutool-ai/src/main/java/org/dromara/hutool/ai/AIException.java index aec3ec67e..7722443b6 100644 --- a/hutool-ai/src/main/java/org/dromara/hutool/ai/AIException.java +++ b/hutool-ai/src/main/java/org/dromara/hutool/ai/AIException.java @@ -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; import org.dromara.hutool.core.exception.HutoolException; diff --git a/hutool-ai/src/main/java/org/dromara/hutool/ai/AIServiceFactory.java b/hutool-ai/src/main/java/org/dromara/hutool/ai/AIServiceFactory.java index cb0dcbd04..7d900871d 100644 --- a/hutool-ai/src/main/java/org/dromara/hutool/ai/AIServiceFactory.java +++ b/hutool-ai/src/main/java/org/dromara/hutool/ai/AIServiceFactory.java @@ -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; import org.dromara.hutool.ai.core.AIConfig; diff --git a/hutool-ai/src/main/java/org/dromara/hutool/ai/AIUtil.java b/hutool-ai/src/main/java/org/dromara/hutool/ai/AIUtil.java index e48e06ea3..45f22eeaf 100644 --- a/hutool-ai/src/main/java/org/dromara/hutool/ai/AIUtil.java +++ b/hutool-ai/src/main/java/org/dromara/hutool/ai/AIUtil.java @@ -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; import org.dromara.hutool.ai.core.AIConfig; diff --git a/hutool-ai/src/main/java/org/dromara/hutool/ai/ModelName.java b/hutool-ai/src/main/java/org/dromara/hutool/ai/ModelName.java index e74d75439..3ae1718e5 100644 --- a/hutool-ai/src/main/java/org/dromara/hutool/ai/ModelName.java +++ b/hutool-ai/src/main/java/org/dromara/hutool/ai/ModelName.java @@ -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; /** diff --git a/hutool-ai/src/main/java/org/dromara/hutool/ai/Models.java b/hutool-ai/src/main/java/org/dromara/hutool/ai/Models.java index 02db63771..ed2ab92c4 100644 --- a/hutool-ai/src/main/java/org/dromara/hutool/ai/Models.java +++ b/hutool-ai/src/main/java/org/dromara/hutool/ai/Models.java @@ -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; /** diff --git a/hutool-ai/src/main/java/org/dromara/hutool/ai/core/AIConfig.java b/hutool-ai/src/main/java/org/dromara/hutool/ai/core/AIConfig.java index 0a4b2822f..1980b76f6 100644 --- a/hutool-ai/src/main/java/org/dromara/hutool/ai/core/AIConfig.java +++ b/hutool-ai/src/main/java/org/dromara/hutool/ai/core/AIConfig.java @@ -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; import java.util.Map; diff --git a/hutool-ai/src/main/java/org/dromara/hutool/ai/core/AIConfigBuilder.java b/hutool-ai/src/main/java/org/dromara/hutool/ai/core/AIConfigBuilder.java index 6135e5fd8..060fa8a3e 100644 --- a/hutool-ai/src/main/java/org/dromara/hutool/ai/core/AIConfigBuilder.java +++ b/hutool-ai/src/main/java/org/dromara/hutool/ai/core/AIConfigBuilder.java @@ -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; import java.lang.reflect.Constructor; diff --git a/hutool-ai/src/main/java/org/dromara/hutool/ai/core/AIConfigRegistry.java b/hutool-ai/src/main/java/org/dromara/hutool/ai/core/AIConfigRegistry.java index 8bfdc1d80..7d03ed456 100644 --- a/hutool-ai/src/main/java/org/dromara/hutool/ai/core/AIConfigRegistry.java +++ b/hutool-ai/src/main/java/org/dromara/hutool/ai/core/AIConfigRegistry.java @@ -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; import org.dromara.hutool.core.map.concurrent.SafeConcurrentHashMap; diff --git a/hutool-ai/src/main/java/org/dromara/hutool/ai/core/AIService.java b/hutool-ai/src/main/java/org/dromara/hutool/ai/core/AIService.java index 256cefdbf..fd049ed5f 100644 --- a/hutool-ai/src/main/java/org/dromara/hutool/ai/core/AIService.java +++ b/hutool-ai/src/main/java/org/dromara/hutool/ai/core/AIService.java @@ -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; import java.util.List; @@ -26,6 +42,6 @@ public interface AIService { * @return AI回答 * @since 6.0.0 */ - String chat(List messages); + String chat(final List messages); } diff --git a/hutool-ai/src/main/java/org/dromara/hutool/ai/core/AIServiceProvider.java b/hutool-ai/src/main/java/org/dromara/hutool/ai/core/AIServiceProvider.java index 5ff6d2f2e..be435b73d 100644 --- a/hutool-ai/src/main/java/org/dromara/hutool/ai/core/AIServiceProvider.java +++ b/hutool-ai/src/main/java/org/dromara/hutool/ai/core/AIServiceProvider.java @@ -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; /** @@ -20,9 +36,9 @@ public interface AIServiceProvider { * 创建AI服务实例 * * @param config AIConfig配置 - * @param AIService类型 + * @param AIService实现类 * @return AI服务实例 * @since 6.0.0 */ - T create(AIConfig config); + T create(final AIConfig config); } diff --git a/hutool-ai/src/main/java/org/dromara/hutool/ai/core/BaseAIService.java b/hutool-ai/src/main/java/org/dromara/hutool/ai/core/BaseAIService.java index 9e00076e8..5a0a18a9a 100644 --- a/hutool-ai/src/main/java/org/dromara/hutool/ai/core/BaseAIService.java +++ b/hutool-ai/src/main/java/org/dromara/hutool/ai/core/BaseAIService.java @@ -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; import org.dromara.hutool.ai.AIException; @@ -28,6 +44,11 @@ public class BaseAIService { this.config = config; } + /** + * 发送Get请求 + * @param endpoint 请求节点 + * @return 请求响应 + */ protected Response sendGet(final String endpoint) { //链式构建请求 try { @@ -42,6 +63,12 @@ public class BaseAIService { } } + /** + * 发送Post请求 + * @param endpoint 请求节点 + * @param paramJson 请求参数json + * @return 请求响应 + */ protected Response sendPost(final String endpoint, final String paramJson) { //链式构建请求 try { @@ -59,6 +86,12 @@ public class BaseAIService { } + /** + * 发送表单请求 + * @param endpoint 请求节点 + * @param paramMap 请求参数map + * @return 请求响应 + */ protected Response sendFormData(final String endpoint, final Map paramMap) { //链式构建请求 try { diff --git a/hutool-ai/src/main/java/org/dromara/hutool/ai/core/BaseConfig.java b/hutool-ai/src/main/java/org/dromara/hutool/ai/core/BaseConfig.java index 9bfacbcfc..20f195b77 100644 --- a/hutool-ai/src/main/java/org/dromara/hutool/ai/core/BaseConfig.java +++ b/hutool-ai/src/main/java/org/dromara/hutool/ai/core/BaseConfig.java @@ -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; diff --git a/hutool-ai/src/main/java/org/dromara/hutool/ai/core/Message.java b/hutool-ai/src/main/java/org/dromara/hutool/ai/core/Message.java index 726751b3e..6bb85c2a4 100644 --- a/hutool-ai/src/main/java/org/dromara/hutool/ai/core/Message.java +++ b/hutool-ai/src/main/java/org/dromara/hutool/ai/core/Message.java @@ -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; /** diff --git a/hutool-ai/src/main/java/org/dromara/hutool/ai/core/package-info.java b/hutool-ai/src/main/java/org/dromara/hutool/ai/core/package-info.java index 68d692b26..97575b34e 100644 --- a/hutool-ai/src/main/java/org/dromara/hutool/ai/core/package-info.java +++ b/hutool-ai/src/main/java/org/dromara/hutool/ai/core/package-info.java @@ -18,5 +18,7 @@ * AI相关基础类 * * @author elichow + * @since 6.0.0 */ + package org.dromara.hutool.ai.core; diff --git a/hutool-ai/src/main/java/org/dromara/hutool/ai/model/deepseek/DeepSeekCommon.java b/hutool-ai/src/main/java/org/dromara/hutool/ai/model/deepseek/DeepSeekCommon.java index a3aaee27e..440fe54b1 100644 --- a/hutool-ai/src/main/java/org/dromara/hutool/ai/model/deepseek/DeepSeekCommon.java +++ b/hutool-ai/src/main/java/org/dromara/hutool/ai/model/deepseek/DeepSeekCommon.java @@ -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; /** diff --git a/hutool-ai/src/main/java/org/dromara/hutool/ai/model/deepseek/DeepSeekConfig.java b/hutool-ai/src/main/java/org/dromara/hutool/ai/model/deepseek/DeepSeekConfig.java index 66a15aed1..e7ac42db0 100644 --- a/hutool-ai/src/main/java/org/dromara/hutool/ai/model/deepseek/DeepSeekConfig.java +++ b/hutool-ai/src/main/java/org/dromara/hutool/ai/model/deepseek/DeepSeekConfig.java @@ -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; import org.dromara.hutool.ai.Models; diff --git a/hutool-ai/src/main/java/org/dromara/hutool/ai/model/deepseek/DeepSeekProvider.java b/hutool-ai/src/main/java/org/dromara/hutool/ai/model/deepseek/DeepSeekProvider.java index 126790f4e..cb58671b6 100644 --- a/hutool-ai/src/main/java/org/dromara/hutool/ai/model/deepseek/DeepSeekProvider.java +++ b/hutool-ai/src/main/java/org/dromara/hutool/ai/model/deepseek/DeepSeekProvider.java @@ -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.AIServiceProvider; @@ -18,7 +33,7 @@ public class DeepSeekProvider implements AIServiceProvider { } @Override - public DeepSeekService create(AIConfig config) { + public DeepSeekService create(final AIConfig config) { return new DeepSeekServiceImpl(config); } } diff --git a/hutool-ai/src/main/java/org/dromara/hutool/ai/model/deepseek/DeepSeekService.java b/hutool-ai/src/main/java/org/dromara/hutool/ai/model/deepseek/DeepSeekService.java index da893e266..f82b58d1f 100644 --- a/hutool-ai/src/main/java/org/dromara/hutool/ai/model/deepseek/DeepSeekService.java +++ b/hutool-ai/src/main/java/org/dromara/hutool/ai/model/deepseek/DeepSeekService.java @@ -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; import org.dromara.hutool.ai.core.AIService; diff --git a/hutool-ai/src/main/java/org/dromara/hutool/ai/model/deepseek/DeepSeekServiceImpl.java b/hutool-ai/src/main/java/org/dromara/hutool/ai/model/deepseek/DeepSeekServiceImpl.java index d01ee33e3..ae891c088 100644 --- a/hutool-ai/src/main/java/org/dromara/hutool/ai/model/deepseek/DeepSeekServiceImpl.java +++ b/hutool-ai/src/main/java/org/dromara/hutool/ai/model/deepseek/DeepSeekServiceImpl.java @@ -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; 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"; - public DeepSeekServiceImpl(AIConfig config) { + public DeepSeekServiceImpl(final AIConfig config) { //初始化DeepSeek客户端 super(config); } @@ -36,14 +52,14 @@ public class DeepSeekServiceImpl extends BaseAIService implements DeepSeekServic @Override public String chat(String prompt) { // 定义消息结构 - List messages = new ArrayList<>(); + final List messages = new ArrayList<>(); messages.add(new Message("system", "You are a helpful assistant")); messages.add(new Message("user", prompt)); return chat(messages); } @Override - public String chat(List messages) { + public String chat(final List messages) { String paramJson = buildChatRequestBody(messages); Response response = sendPost(CHAT_ENDPOINT, paramJson); return response.bodyStr(); @@ -69,9 +85,9 @@ public class DeepSeekServiceImpl extends BaseAIService implements DeepSeekServic } // 构建chat请求体 - private String buildChatRequestBody(List messages) { + private String buildChatRequestBody(final List messages) { //使用JSON工具 - Map paramMap = new HashMap<>(); + final Map paramMap = new HashMap<>(); paramMap.put("model", config.getModel()); paramMap.put("messages", messages); //合并其他参数 @@ -84,7 +100,7 @@ public class DeepSeekServiceImpl extends BaseAIService implements DeepSeekServic private String buildBetaRequestBody(String prompt) { // 定义消息结构 //使用JSON工具 - Map paramMap = new HashMap<>(); + final Map paramMap = new HashMap<>(); paramMap.put("model", config.getModel()); paramMap.put("prompt", prompt); // //合并其他参数 diff --git a/hutool-ai/src/main/java/org/dromara/hutool/ai/model/deepseek/package-info.java b/hutool-ai/src/main/java/org/dromara/hutool/ai/model/deepseek/package-info.java new file mode 100644 index 000000000..553dfbf37 --- /dev/null +++ b/hutool-ai/src/main/java/org/dromara/hutool/ai/model/deepseek/package-info.java @@ -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; diff --git a/hutool-ai/src/main/java/org/dromara/hutool/ai/model/doubao/DoubaoCommon.java b/hutool-ai/src/main/java/org/dromara/hutool/ai/model/doubao/DoubaoCommon.java index fe471a44f..c8e9ddd9c 100644 --- a/hutool-ai/src/main/java/org/dromara/hutool/ai/model/doubao/DoubaoCommon.java +++ b/hutool-ai/src/main/java/org/dromara/hutool/ai/model/doubao/DoubaoCommon.java @@ -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; /** @@ -25,7 +41,7 @@ public class DoubaoCommon { } } - //豆包视觉参数 + //doubao视觉参数 public enum DoubaoVision { AUTO("auto"), diff --git a/hutool-ai/src/main/java/org/dromara/hutool/ai/model/doubao/DoubaoConfig.java b/hutool-ai/src/main/java/org/dromara/hutool/ai/model/doubao/DoubaoConfig.java index ee3786696..fa8a588e7 100644 --- a/hutool-ai/src/main/java/org/dromara/hutool/ai/model/doubao/DoubaoConfig.java +++ b/hutool-ai/src/main/java/org/dromara/hutool/ai/model/doubao/DoubaoConfig.java @@ -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; import org.dromara.hutool.ai.Models; diff --git a/hutool-ai/src/main/java/org/dromara/hutool/ai/model/doubao/DoubaoProvider.java b/hutool-ai/src/main/java/org/dromara/hutool/ai/model/doubao/DoubaoProvider.java index 050fde6ca..cf6dd5fcc 100644 --- a/hutool-ai/src/main/java/org/dromara/hutool/ai/model/doubao/DoubaoProvider.java +++ b/hutool-ai/src/main/java/org/dromara/hutool/ai/model/doubao/DoubaoProvider.java @@ -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; import org.dromara.hutool.ai.core.AIConfig; @@ -17,7 +33,7 @@ public class DoubaoProvider implements AIServiceProvider { } @Override - public DoubaoService create(AIConfig config) { + public DoubaoService create(final AIConfig config) { return new DoubaoServiceImpl(config); } } diff --git a/hutool-ai/src/main/java/org/dromara/hutool/ai/model/doubao/DoubaoService.java b/hutool-ai/src/main/java/org/dromara/hutool/ai/model/doubao/DoubaoService.java index 8f5b36959..37d86b01e 100644 --- a/hutool-ai/src/main/java/org/dromara/hutool/ai/model/doubao/DoubaoService.java +++ b/hutool-ai/src/main/java/org/dromara/hutool/ai/model/doubao/DoubaoService.java @@ -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; import org.dromara.hutool.ai.core.AIService; @@ -22,7 +38,7 @@ public interface DoubaoService extends AIService { * @return AI回答 * @since 6.0.0 */ - String chatVision(String prompt, List images, String detail); + String chatVision(String prompt, final List images, String detail); /** * 图像理解:模型会依据传入的图片信息以及问题,给出回复。 @@ -32,7 +48,7 @@ public interface DoubaoService extends AIService { * @return AI回答 * @since 6.0.0 */ - default String chatVision(String prompt, List images) { + default String chatVision(String prompt, final List images) { return chatVision(prompt, images, DoubaoCommon.DoubaoVision.AUTO.getDetail()); } @@ -46,7 +62,7 @@ public interface DoubaoService extends AIService { * @return 生成任务id * @since 6.0.0 */ - String videoTasks(String text, String image, List videoParams); + String videoTasks(String text, String image, final List videoParams); /** * 创建视频生成任务 @@ -96,7 +112,7 @@ public interface DoubaoService extends AIService { * @return AI回答 * @since 6.0.0 */ - String botsChat(List messages); + String botsChat(final List messages); /** * 分词:可以将文本转换为模型可理解的 token id,并返回文本的 tokens 数量、token id、 token 在原始文本中的偏移量等信息 @@ -127,7 +143,7 @@ public interface DoubaoService extends AIService { * @return AI回答 * @since 6.0.0 */ - String batchChat(List messages); + String batchChat(final List messages); /** * 创建上下文缓存: 创建上下文缓存,获得缓存 id字段后,在上下文缓存对话 API中使用。 @@ -139,7 +155,7 @@ public interface DoubaoService extends AIService { * @return 返回的缓存id * @since 6.0.0 */ - String createContext(List messages, String mode); + String createContext(final List messages, String mode); /** * 创建上下文缓存: 创建上下文缓存,获得缓存 id字段后,在上下文缓存对话 API中使用。 @@ -150,7 +166,7 @@ public interface DoubaoService extends AIService { * @return 返回的缓存id * @since 6.0.0 */ - default String createContext(List messages) { + default String createContext(final List messages) { return createContext(messages, DoubaoCommon.DoubaoContext.SESSION.getMode()); } @@ -174,6 +190,6 @@ public interface DoubaoService extends AIService { * @return AI的回答 * @since 6.0.0 */ - String chatContext(List messages, String contextId); + String chatContext(final List messages, String contextId); } diff --git a/hutool-ai/src/main/java/org/dromara/hutool/ai/model/doubao/DoubaoServiceImpl.java b/hutool-ai/src/main/java/org/dromara/hutool/ai/model/doubao/DoubaoServiceImpl.java index 5a897becb..60daf124d 100644 --- a/hutool-ai/src/main/java/org/dromara/hutool/ai/model/doubao/DoubaoServiceImpl.java +++ b/hutool-ai/src/main/java/org/dromara/hutool/ai/model/doubao/DoubaoServiceImpl.java @@ -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; 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"; - public DoubaoServiceImpl(AIConfig config) { + public DoubaoServiceImpl(final AIConfig config) { //初始化doubao客户端 super(config); } @@ -47,28 +63,28 @@ public class DoubaoServiceImpl extends BaseAIService implements DoubaoService { @Override public String chat(String prompt) { // 定义消息结构 - List messages = new ArrayList<>(); + final List messages = new ArrayList<>(); messages.add(new Message("system", "You are a helpful assistant")); messages.add(new Message("user", prompt)); return chat(messages); } @Override - public String chat(List messages) { + public String chat(final List messages) { String paramJson = buildChatRequestBody(messages); Response response = sendPost(CHAT_ENDPOINT, paramJson); return response.bodyStr(); } @Override - public String chatVision(String prompt, List images, String detail) { + public String chatVision(String prompt, final List images, String detail) { String paramJson = buildChatVisionRequestBody(prompt, images, detail); Response response = sendPost(CHAT_ENDPOINT, paramJson); return response.bodyStr(); } @Override - public String videoTasks(String text, String image, List videoParams) { + public String videoTasks(String text, String image, final List videoParams) { String paramJson = buildGenerationsTasksRequestBody(text, image, videoParams); Response response = sendPost(CREATE_VIDEO, paramJson); return response.bodyStr(); @@ -96,9 +112,8 @@ public class DoubaoServiceImpl extends BaseAIService implements DoubaoService { } @Override - public String botsChat(List messages) { + public String botsChat(final List messages) { String paramJson = buildBotsChatRequestBody(messages); - System.out.println(paramJson); Response response = sendPost(BOTS_CHAT, paramJson); return response.bodyStr(); } @@ -113,24 +128,22 @@ public class DoubaoServiceImpl extends BaseAIService implements DoubaoService { @Override public String batchChat(String prompt) { // 定义消息结构 - List messages = new ArrayList<>(); + final List messages = new ArrayList<>(); messages.add(new Message("system", "You are a helpful assistant")); messages.add(new Message("user", prompt)); return batchChat(messages); } @Override - public String batchChat(List messages) { + public String batchChat(final List messages) { String paramJson = buildBatchChatRequestBody(messages); - System.out.println(paramJson); Response response = sendPost(BATCH_CHAT, paramJson); return response.bodyStr(); } @Override - public String createContext(List messages, String mode) { + public String createContext(final List messages, String mode) { String paramJson = buildCreateContextRequest(messages, mode); - System.out.println(paramJson); Response response = sendPost(CREATE_CONTEXT, paramJson); return response.bodyStr(); } @@ -138,22 +151,22 @@ public class DoubaoServiceImpl extends BaseAIService implements DoubaoService { @Override public String chatContext(String prompt, String contextId) { // 定义消息结构 - List messages = new ArrayList<>(); + final List messages = new ArrayList<>(); messages.add(new Message("user", prompt)); return chatContext(messages, contextId); } @Override - public String chatContext(List messages, String contextId) { + public String chatContext(final List messages, String contextId) { String paramJson = buildChatContentRequestBody(messages, contextId); Response response = sendPost(CHAT_CONTEXT, paramJson); return response.bodyStr(); } // 构建chat请求体 - private String buildChatRequestBody(List messages) { + private String buildChatRequestBody(final List messages) { //使用JSON工具 - Map paramMap = new HashMap<>(); + final Map paramMap = new HashMap<>(); paramMap.put("model", config.getModel()); paramMap.put("messages", messages); //合并其他参数 @@ -163,12 +176,12 @@ public class DoubaoServiceImpl extends BaseAIService implements DoubaoService { } //构建chatVision请求体 - private String buildChatVisionRequestBody(String prompt, List images, String detail) { + private String buildChatVisionRequestBody(String prompt, final List images, String detail) { // 定义消息结构 - List messages = new ArrayList<>(); - List content = new ArrayList<>(); + final List messages = new ArrayList<>(); + final List content = new ArrayList<>(); - Map contentMap = new HashMap<>(); + final Map contentMap = new HashMap<>(); contentMap.put("type", "text"); contentMap.put("text", prompt); content.add(contentMap); @@ -185,7 +198,7 @@ public class DoubaoServiceImpl extends BaseAIService implements DoubaoService { messages.add(new Message("user", content)); //使用JSON工具 - Map paramMap = new HashMap<>(); + final Map paramMap = new HashMap<>(); paramMap.put("model", config.getModel()); paramMap.put("messages", messages); //合并其他参数 @@ -196,7 +209,7 @@ public class DoubaoServiceImpl extends BaseAIService implements DoubaoService { //构建文本向量化请求体 private String buildEmbeddingTextRequestBody(String[] input) { //使用JSON工具 - Map paramMap = new HashMap<>(); + final Map paramMap = new HashMap<>(); paramMap.put("model", config.getModel()); paramMap.put("input", input); //合并其他参数 @@ -207,22 +220,22 @@ public class DoubaoServiceImpl extends BaseAIService implements DoubaoService { //构建图文向量化请求体 private String buildEmbeddingVisionRequestBody(String text, String image) { //使用JSON工具 - Map paramMap = new HashMap<>(); + final Map paramMap = new HashMap<>(); paramMap.put("model", config.getModel()); - List input = new ArrayList<>(); + final List input = new ArrayList<>(); //添加文本参数 if (!StrUtil.isBlank(text)) { - Map textMap = new HashMap<>(); + final Map textMap = new HashMap<>(); textMap.put("type", "text"); textMap.put("text", text); input.add(textMap); } //添加图片参数 if (!StrUtil.isBlank(image)) { - HashMap imgUrlMap = new HashMap<>(); + final Map imgUrlMap = new HashMap<>(); imgUrlMap.put("type", "image_url"); - HashMap urlMap = new HashMap<>(); + final Map urlMap = new HashMap<>(); urlMap.put("url", image); imgUrlMap.put("image_url", urlMap); input.add(imgUrlMap); @@ -236,26 +249,26 @@ public class DoubaoServiceImpl extends BaseAIService implements DoubaoService { } //构建应用chat请求体 - private String buildBotsChatRequestBody(List messages) { + private String buildBotsChatRequestBody(final List messages) { return buildChatRequestBody(messages); } //构建分词请求体 private String buildTokenizationRequestBody(String[] text) { - Map paramMap = new HashMap<>(); + final Map paramMap = new HashMap<>(); paramMap.put("model", config.getModel()); paramMap.put("text", text); return JSONUtil.toJsonStr(paramMap); } //构建批量推理chat请求体 - private String buildBatchChatRequestBody(List messages) { + private String buildBatchChatRequestBody(final List messages) { return buildChatRequestBody(messages); } //构建创建上下文缓存请求体 - private String buildCreateContextRequest(List messages, String mode) { - Map paramMap = new HashMap<>(); + private String buildCreateContextRequest(final List messages, String mode) { + final Map paramMap = new HashMap<>(); paramMap.put("messages", messages); paramMap.put("model", config.getModel()); paramMap.put("mode", mode); @@ -266,9 +279,9 @@ public class DoubaoServiceImpl extends BaseAIService implements DoubaoService { } //构建上下文缓存对话请求体 - private String buildChatContentRequestBody(List messages, String contextId) { + private String buildChatContentRequestBody(final List messages, String contextId) { //使用JSON工具 - Map paramMap = new HashMap<>(); + final Map paramMap = new HashMap<>(); paramMap.put("model", config.getModel()); paramMap.put("messages", messages); paramMap.put("context_id", contextId); @@ -279,14 +292,14 @@ public class DoubaoServiceImpl extends BaseAIService implements DoubaoService { } //构建创建视频任务请求体 - private String buildGenerationsTasksRequestBody(String text, String image, List videoParams) { + private String buildGenerationsTasksRequestBody(String text, String image, final List videoParams) { //使用JSON工具 - Map paramMap = new HashMap<>(); + final Map paramMap = new HashMap<>(); paramMap.put("model", config.getModel()); - List content = new ArrayList<>(); + final List content = new ArrayList<>(); //添加文本参数 - Map textMap = new HashMap<>(); + final Map textMap = new HashMap<>(); if (!StrUtil.isBlank(text)) { textMap.put("type", "text"); textMap.put("text", text); @@ -294,9 +307,9 @@ public class DoubaoServiceImpl extends BaseAIService implements DoubaoService { } //添加图片参数 if (!StrUtil.isNotBlank(image)) { - Map imgUrlMap = new HashMap<>(); + final Map imgUrlMap = new HashMap<>(); imgUrlMap.put("type", "image_url"); - HashMap urlMap = new HashMap<>(); + final Map urlMap = new HashMap<>(); urlMap.put("url", image); imgUrlMap.put("image_url", urlMap); content.add(imgUrlMap); diff --git a/hutool-ai/src/main/java/org/dromara/hutool/ai/model/doubao/package-info.java b/hutool-ai/src/main/java/org/dromara/hutool/ai/model/doubao/package-info.java new file mode 100644 index 000000000..cd40edd94 --- /dev/null +++ b/hutool-ai/src/main/java/org/dromara/hutool/ai/model/doubao/package-info.java @@ -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; diff --git a/hutool-ai/src/main/java/org/dromara/hutool/ai/model/grok/GrokCommon.java b/hutool-ai/src/main/java/org/dromara/hutool/ai/model/grok/GrokCommon.java index c7eb2d569..98a156bf4 100644 --- a/hutool-ai/src/main/java/org/dromara/hutool/ai/model/grok/GrokCommon.java +++ b/hutool-ai/src/main/java/org/dromara/hutool/ai/model/grok/GrokCommon.java @@ -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; /** diff --git a/hutool-ai/src/main/java/org/dromara/hutool/ai/model/grok/GrokConfig.java b/hutool-ai/src/main/java/org/dromara/hutool/ai/model/grok/GrokConfig.java index e0347b111..461a21437 100644 --- a/hutool-ai/src/main/java/org/dromara/hutool/ai/model/grok/GrokConfig.java +++ b/hutool-ai/src/main/java/org/dromara/hutool/ai/model/grok/GrokConfig.java @@ -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; import org.dromara.hutool.ai.Models; diff --git a/hutool-ai/src/main/java/org/dromara/hutool/ai/model/grok/GrokProvider.java b/hutool-ai/src/main/java/org/dromara/hutool/ai/model/grok/GrokProvider.java index fb2162360..78cbc517e 100644 --- a/hutool-ai/src/main/java/org/dromara/hutool/ai/model/grok/GrokProvider.java +++ b/hutool-ai/src/main/java/org/dromara/hutool/ai/model/grok/GrokProvider.java @@ -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; import org.dromara.hutool.ai.core.AIConfig; @@ -17,7 +33,7 @@ public class GrokProvider implements AIServiceProvider { } @Override - public GrokService create(AIConfig config) { + public GrokService create(final AIConfig config) { return new GrokServiceImpl(config); } } diff --git a/hutool-ai/src/main/java/org/dromara/hutool/ai/model/grok/GrokService.java b/hutool-ai/src/main/java/org/dromara/hutool/ai/model/grok/GrokService.java index 275ae71f0..b4bcbc0e9 100644 --- a/hutool-ai/src/main/java/org/dromara/hutool/ai/model/grok/GrokService.java +++ b/hutool-ai/src/main/java/org/dromara/hutool/ai/model/grok/GrokService.java @@ -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; import org.dromara.hutool.ai.core.AIService; @@ -31,7 +47,7 @@ public interface GrokService extends AIService { * @return AI回答 * @since 6.0.0 */ - String chatVision(String prompt, List images, String detail); + String chatVision(String prompt, final List images, String detail); /** * 图像理解:模型会依据传入的图片信息以及问题,给出回复。 @@ -41,7 +57,7 @@ public interface GrokService extends AIService { * @return AI回答 * @since 6.0.0 */ - default String chatVision(String prompt, List images) { + default String chatVision(String prompt, final List images) { return chatVision(prompt, images, GrokCommon.GrokVision.AUTO.getDetail()); } diff --git a/hutool-ai/src/main/java/org/dromara/hutool/ai/model/grok/GrokServiceImpl.java b/hutool-ai/src/main/java/org/dromara/hutool/ai/model/grok/GrokServiceImpl.java index ae86f2005..9353628f6 100644 --- a/hutool-ai/src/main/java/org/dromara/hutool/ai/model/grok/GrokServiceImpl.java +++ b/hutool-ai/src/main/java/org/dromara/hutool/ai/model/grok/GrokServiceImpl.java @@ -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; 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"; - public GrokServiceImpl(AIConfig config) { + public GrokServiceImpl(final AIConfig config) { //初始化grok客户端 super(config); } @@ -40,14 +56,14 @@ public class GrokServiceImpl extends BaseAIService implements GrokService { @Override public String chat(String prompt) { // 定义消息结构 - List messages = new ArrayList<>(); + final List messages = new ArrayList<>(); messages.add(new Message("system", "You are a helpful assistant")); messages.add(new Message("user", prompt)); return chat(messages); } @Override - public String chat(List messages) { + public String chat(final List messages) { String paramJson = buildChatRequestBody(messages); Response response = sendPost(CHAT_ENDPOINT, paramJson); return response.bodyStr(); @@ -56,7 +72,7 @@ public class GrokServiceImpl extends BaseAIService implements GrokService { @Override public String message(String prompt, int maxToken) { // 定义消息结构 - List messages = new ArrayList<>(); + final List messages = new ArrayList<>(); messages.add(new Message("system", "You are a helpful assistant")); messages.add(new Message("user", prompt)); String paramJson = buildMessageRequestBody(messages, maxToken); @@ -65,7 +81,7 @@ public class GrokServiceImpl extends BaseAIService implements GrokService { } @Override - public String chatVision(String prompt, List images, String detail) { + public String chatVision(String prompt, final List images, String detail) { String paramJson = buildChatVisionRequestBody(prompt, images, detail); Response response = sendPost(CHAT_ENDPOINT, paramJson); return response.bodyStr(); @@ -109,9 +125,9 @@ public class GrokServiceImpl extends BaseAIService implements GrokService { } // 构建chat请求体 - private String buildChatRequestBody(List messages) { + private String buildChatRequestBody(final List messages) { //使用JSON工具 - Map paramMap = new HashMap<>(); + final Map paramMap = new HashMap<>(); paramMap.put("model", config.getModel()); paramMap.put("messages", messages); //合并其他参数 @@ -121,12 +137,12 @@ public class GrokServiceImpl extends BaseAIService implements GrokService { } //构建chatVision请求体 - private String buildChatVisionRequestBody(String prompt, List images, String detail) { + private String buildChatVisionRequestBody(String prompt, final List images, String detail) { // 定义消息结构 - List messages = new ArrayList<>(); - List content = new ArrayList<>(); + final List messages = new ArrayList<>(); + final List content = new ArrayList<>(); - Map contentMap = new HashMap<>(); + final Map contentMap = new HashMap<>(); contentMap.put("type", "text"); contentMap.put("text", prompt); content.add(contentMap); @@ -143,7 +159,7 @@ public class GrokServiceImpl extends BaseAIService implements GrokService { messages.add(new Message("user", content)); //使用JSON工具 - Map paramMap = new HashMap<>(); + final Map paramMap = new HashMap<>(); paramMap.put("model", config.getModel()); paramMap.put("messages", messages); //合并其他参数 @@ -152,8 +168,8 @@ public class GrokServiceImpl extends BaseAIService implements GrokService { } //构建消息回复请求体 - private String buildMessageRequestBody(List messages, int maxToken) { - Map paramMap = new HashMap<>(); + private String buildMessageRequestBody(final List messages, int maxToken) { + final Map paramMap = new HashMap<>(); paramMap.put("model", config.getModel()); paramMap.put("messages", messages); paramMap.put("max_tokens", maxToken); @@ -166,7 +182,7 @@ public class GrokServiceImpl extends BaseAIService implements GrokService { //构建分词请求体 private String buildTokenizeRequestBody(String text) { //使用JSON工具 - Map paramMap = new HashMap<>(); + final Map paramMap = new HashMap<>(); paramMap.put("model", config.getModel()); paramMap.put("text", text); //合并其他参数 diff --git a/hutool-ai/src/main/java/org/dromara/hutool/ai/model/grok/package-info.java b/hutool-ai/src/main/java/org/dromara/hutool/ai/model/grok/package-info.java new file mode 100644 index 000000000..9cca48bd9 --- /dev/null +++ b/hutool-ai/src/main/java/org/dromara/hutool/ai/model/grok/package-info.java @@ -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; diff --git a/hutool-ai/src/main/java/org/dromara/hutool/ai/model/openai/OpenaiCommon.java b/hutool-ai/src/main/java/org/dromara/hutool/ai/model/openai/OpenaiCommon.java index 104316b34..c9bae04ac 100644 --- a/hutool-ai/src/main/java/org/dromara/hutool/ai/model/openai/OpenaiCommon.java +++ b/hutool-ai/src/main/java/org/dromara/hutool/ai/model/openai/OpenaiCommon.java @@ -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; /** diff --git a/hutool-ai/src/main/java/org/dromara/hutool/ai/model/openai/OpenaiConfig.java b/hutool-ai/src/main/java/org/dromara/hutool/ai/model/openai/OpenaiConfig.java index 245e36e2e..3de62ea06 100644 --- a/hutool-ai/src/main/java/org/dromara/hutool/ai/model/openai/OpenaiConfig.java +++ b/hutool-ai/src/main/java/org/dromara/hutool/ai/model/openai/OpenaiConfig.java @@ -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.core.BaseConfig; diff --git a/hutool-ai/src/main/java/org/dromara/hutool/ai/model/openai/OpenaiProvider.java b/hutool-ai/src/main/java/org/dromara/hutool/ai/model/openai/OpenaiProvider.java index 4b59a0e0a..114f60449 100644 --- a/hutool-ai/src/main/java/org/dromara/hutool/ai/model/openai/OpenaiProvider.java +++ b/hutool-ai/src/main/java/org/dromara/hutool/ai/model/openai/OpenaiProvider.java @@ -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.AIServiceProvider; @@ -18,7 +33,7 @@ public class OpenaiProvider implements AIServiceProvider { } @Override - public OpenaiService create(AIConfig config) { + public OpenaiService create(final AIConfig config) { return new OpenaiServiceImpl(config); } } diff --git a/hutool-ai/src/main/java/org/dromara/hutool/ai/model/openai/OpenaiService.java b/hutool-ai/src/main/java/org/dromara/hutool/ai/model/openai/OpenaiService.java index 6ff590a68..1c8dbddd2 100644 --- a/hutool-ai/src/main/java/org/dromara/hutool/ai/model/openai/OpenaiService.java +++ b/hutool-ai/src/main/java/org/dromara/hutool/ai/model/openai/OpenaiService.java @@ -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; import org.dromara.hutool.ai.core.AIService; @@ -24,7 +40,7 @@ public interface OpenaiService extends AIService { * @return AI回答 * @since 6.0.0 */ - String chatVision(String prompt, List images, String detail); + String chatVision(String prompt, final List images, String detail); /** * 图像理解:模型会依据传入的图片信息以及问题,给出回复。 @@ -34,7 +50,7 @@ public interface OpenaiService extends AIService { * @return AI回答 * @since 6.0.0 */ - default String chatVision(String prompt, List images) { + default String chatVision(String prompt, final List images) { return chatVision(prompt, images, OpenaiCommon.OpenaiVision.AUTO.getDetail()); } @@ -56,7 +72,7 @@ public interface OpenaiService extends AIService { * @return 包含生成图片的url * @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 @@ -66,7 +82,7 @@ public interface OpenaiService extends AIService { * @return 包含生成图片的url * @since 6.0.0 */ - default String imagesEdits(String prompt, File image) { + default String imagesEdits(String prompt, final File image) { return imagesEdits(prompt, image, null); } @@ -77,7 +93,7 @@ public interface OpenaiService extends AIService { * @return 包含生成图片的url * @since 6.0.0 */ - String imagesVariations(File image); + String imagesVariations(final File image); /** * TTS文本转语音 请设置config中model为支持TTS功能的模型 TTS系列 @@ -87,7 +103,7 @@ public interface OpenaiService extends AIService { * @return 返回的音频mp3文件流 * @since 6.0.0 */ - InputStream textToSpeech(String input, OpenaiCommon.OpenaiSpeech voice); + InputStream textToSpeech(String input, final OpenaiCommon.OpenaiSpeech voice); /** * TTS文本转语音 请设置config中model为支持TTS功能的模型 TTS系列 @@ -107,7 +123,7 @@ public interface OpenaiService extends AIService { * @return 返回的文本内容 * @since 6.0.0 */ - String speechToText(File file); + String speechToText(final File file); /** * 文本向量化 请设置config中model为支持文本向量化功能的模型 text-embedding系列 @@ -173,7 +189,7 @@ public interface OpenaiService extends AIService { * @return AI回答 * @since 6.0.0 */ - String chatReasoning(List messages, String reasoningEffort); + String chatReasoning(final List messages, String reasoningEffort); /** * 推理chat @@ -183,7 +199,7 @@ public interface OpenaiService extends AIService { * @return AI回答 * @since 6.0.0 */ - default String chatReasoning(List messages) { + default String chatReasoning(final List messages) { return chatReasoning(messages, OpenaiCommon.OpenaiReasoning.MEDIUM.getEffort()); } diff --git a/hutool-ai/src/main/java/org/dromara/hutool/ai/model/openai/OpenaiServiceImpl.java b/hutool-ai/src/main/java/org/dromara/hutool/ai/model/openai/OpenaiServiceImpl.java index 7d41be8c7..e337a0017 100644 --- a/hutool-ai/src/main/java/org/dromara/hutool/ai/model/openai/OpenaiServiceImpl.java +++ b/hutool-ai/src/main/java/org/dromara/hutool/ai/model/openai/OpenaiServiceImpl.java @@ -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; import org.dromara.hutool.ai.core.AIConfig; @@ -39,7 +55,7 @@ public class OpenaiServiceImpl extends BaseAIService implements OpenaiService { //检查文本或图片 private final String MODERATIONS = "/moderations"; - public OpenaiServiceImpl(AIConfig config) { + public OpenaiServiceImpl(final AIConfig config) { //初始化Openai客户端 super(config); } @@ -47,21 +63,21 @@ public class OpenaiServiceImpl extends BaseAIService implements OpenaiService { @Override public String chat(String prompt) { // 定义消息结构 - List messages = new ArrayList<>(); + final List messages = new ArrayList<>(); messages.add(new Message("system", "You are a helpful assistant")); messages.add(new Message("user", prompt)); return chat(messages); } @Override - public String chat(List messages) { + public String chat(final List messages) { String paramJson = buildChatRequestBody(messages); Response response = sendPost(CHAT_ENDPOINT, paramJson); return response.bodyStr(); } @Override - public String chatVision(String prompt, List images, String detail) { + public String chatVision(String prompt, final List images, String detail) { String paramJson = buildChatVisionRequestBody(prompt, images, detail); Response response = sendPost(CHAT_ENDPOINT, paramJson); return response.bodyStr(); @@ -75,29 +91,29 @@ public class OpenaiServiceImpl extends BaseAIService implements OpenaiService { } @Override - public String imagesEdits(String prompt, File image, File mask) { - Map paramMap = buildImagesEditsRequestBody(prompt, image, mask); + public String imagesEdits(String prompt, final File image, final File mask) { + final Map paramMap = buildImagesEditsRequestBody(prompt, image, mask); Response response = sendFormData(IMAGES_EDITS, paramMap); return response.bodyStr(); } @Override - public String imagesVariations(File image) { - Map paramMap = buildImagesVariationsRequestBody(image); + public String imagesVariations(final File image) { + final Map paramMap = buildImagesVariationsRequestBody(image); Response response = sendFormData(IMAGES_VARIATIONS, paramMap); return response.bodyStr(); } @Override - public InputStream textToSpeech(String input, OpenaiCommon.OpenaiSpeech voice) { + public InputStream textToSpeech(String input, final OpenaiCommon.OpenaiSpeech voice) { String paramJson = buildTTSRequestBody(input, voice.getVoice()); Response response = sendPost(TTS, paramJson); return response.bodyStream(); } @Override - public String speechToText(File file) { - Map paramMap = buildSTTRequestBody(file); + public String speechToText(final File file) { + final Map paramMap = buildSTTRequestBody(file); Response response = sendFormData(STT, paramMap); return response.bodyStr(); } @@ -119,23 +135,23 @@ public class OpenaiServiceImpl extends BaseAIService implements OpenaiService { @Override public String chatReasoning(String prompt, String reasoningEffort) { // 定义消息结构 - List messages = new ArrayList<>(); + final List messages = new ArrayList<>(); messages.add(new Message("system", "You are a helpful assistant")); messages.add(new Message("user", prompt)); return chat(messages); } @Override - public String chatReasoning(List messages, String reasoningEffort) { + public String chatReasoning(final List messages, String reasoningEffort) { String paramJson = buildChatReasoningRequestBody(messages, reasoningEffort); Response response = sendPost(CHAT_ENDPOINT, paramJson); return response.bodyStr(); } // 构建chat请求体 - private String buildChatRequestBody(List messages) { + private String buildChatRequestBody(final List messages) { //使用JSON工具 - Map paramMap = new HashMap<>(); + final Map paramMap = new HashMap<>(); paramMap.put("model", config.getModel()); paramMap.put("messages", messages); //合并其他参数 @@ -145,19 +161,19 @@ public class OpenaiServiceImpl extends BaseAIService implements OpenaiService { } //构建chatVision请求体 - private String buildChatVisionRequestBody(String prompt, List images, String detail) { + private String buildChatVisionRequestBody(String prompt, final List images, String detail) { // 定义消息结构 - List messages = new ArrayList<>(); - List content = new ArrayList<>(); + final List messages = new ArrayList<>(); + final List content = new ArrayList<>(); - Map contentMap = new HashMap<>(); + final Map contentMap = new HashMap<>(); contentMap.put("type", "text"); contentMap.put("text", prompt); content.add(contentMap); for (String img : images) { - HashMap imgUrlMap = new HashMap<>(); + final Map imgUrlMap = new HashMap<>(); imgUrlMap.put("type", "image_url"); - HashMap urlMap = new HashMap<>(); + final Map urlMap = new HashMap<>(); urlMap.put("url", img); urlMap.put("detail", detail); imgUrlMap.put("image_url", urlMap); @@ -167,7 +183,7 @@ public class OpenaiServiceImpl extends BaseAIService implements OpenaiService { messages.add(new Message("user", content)); //使用JSON工具 - Map paramMap = new HashMap<>(); + final Map paramMap = new HashMap<>(); paramMap.put("model", config.getModel()); paramMap.put("messages", messages); //合并其他参数 @@ -177,7 +193,7 @@ public class OpenaiServiceImpl extends BaseAIService implements OpenaiService { //构建文生图请求体 private String buildImagesGenerationsRequestBody(String prompt) { - Map paramMap = new HashMap<>(); + final Map paramMap = new HashMap<>(); paramMap.put("model", config.getModel()); paramMap.put("prompt", prompt); //合并其他参数 @@ -187,8 +203,8 @@ public class OpenaiServiceImpl extends BaseAIService implements OpenaiService { } //构建图片编辑请求体 - private Map buildImagesEditsRequestBody(String prompt, File image, File mask) { - Map paramMap = new HashMap<>(); + private Map buildImagesEditsRequestBody(String prompt, final File image, final File mask) { + final Map paramMap = new HashMap<>(); paramMap.put("model", config.getModel()); paramMap.put("prompt", prompt); paramMap.put("image", image); @@ -202,8 +218,8 @@ public class OpenaiServiceImpl extends BaseAIService implements OpenaiService { } //构建图片变形请求体 - private Map buildImagesVariationsRequestBody(File image) { - Map paramMap = new HashMap<>(); + private Map buildImagesVariationsRequestBody(final File image) { + final Map paramMap = new HashMap<>(); paramMap.put("model", config.getModel()); paramMap.put("image", image); //合并其他参数 @@ -214,7 +230,7 @@ public class OpenaiServiceImpl extends BaseAIService implements OpenaiService { //构建TTS请求体 private String buildTTSRequestBody(String input, String voice) { - Map paramMap = new HashMap<>(); + final Map paramMap = new HashMap<>(); paramMap.put("model", config.getModel()); paramMap.put("input", input); paramMap.put("voice", voice); @@ -225,8 +241,8 @@ public class OpenaiServiceImpl extends BaseAIService implements OpenaiService { } //构建STT请求体 - private Map buildSTTRequestBody(File file) { - Map paramMap = new HashMap<>(); + private Map buildSTTRequestBody(final File file) { + final Map paramMap = new HashMap<>(); paramMap.put("model", config.getModel()); paramMap.put("file", file); //合并其他参数 @@ -238,7 +254,7 @@ public class OpenaiServiceImpl extends BaseAIService implements OpenaiService { //构建文本向量化请求体 private String buildEmbeddingTextRequestBody(String input) { //使用JSON工具 - Map paramMap = new HashMap<>(); + final Map paramMap = new HashMap<>(); paramMap.put("model", config.getModel()); paramMap.put("input", input); //合并其他参数 @@ -249,22 +265,22 @@ public class OpenaiServiceImpl extends BaseAIService implements OpenaiService { //构建检查图片或文字请求体 private String buileModerationsRequestBody(String text, String imgUrl) { //使用JSON工具 - Map paramMap = new HashMap<>(); + final Map paramMap = new HashMap<>(); paramMap.put("model", config.getModel()); - List input = new ArrayList<>(); + final List input = new ArrayList<>(); //添加文本参数 if (!StrUtil.isBlank(text)) { - Map textMap = new HashMap<>(); + final Map textMap = new HashMap<>(); textMap.put("type", "text"); textMap.put("text", text); input.add(textMap); } //添加图片参数 if (!StrUtil.isBlank(imgUrl)) { - HashMap imgUrlMap = new HashMap<>(); + final Map imgUrlMap = new HashMap<>(); imgUrlMap.put("type", "image_url"); - HashMap urlMap = new HashMap<>(); + final Map urlMap = new HashMap<>(); urlMap.put("url", imgUrl); imgUrlMap.put("image_url", urlMap); input.add(imgUrlMap); @@ -278,8 +294,8 @@ public class OpenaiServiceImpl extends BaseAIService implements OpenaiService { } //构建推理请求体 - private String buildChatReasoningRequestBody(List messages, String reasoningEffort) { - Map paramMap = new HashMap<>(); + private String buildChatReasoningRequestBody(final List messages, String reasoningEffort) { + final Map paramMap = new HashMap<>(); paramMap.put("model", config.getModel()); paramMap.put("messages", messages); paramMap.put("reasoning_effort", reasoningEffort); diff --git a/hutool-ai/src/main/java/org/dromara/hutool/ai/model/openai/package-info.java b/hutool-ai/src/main/java/org/dromara/hutool/ai/model/openai/package-info.java new file mode 100644 index 000000000..e16e22946 --- /dev/null +++ b/hutool-ai/src/main/java/org/dromara/hutool/ai/model/openai/package-info.java @@ -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; diff --git a/hutool-ai/src/main/java/org/dromara/hutool/ai/model/package-info.java b/hutool-ai/src/main/java/org/dromara/hutool/ai/model/package-info.java new file mode 100644 index 000000000..7a264876c --- /dev/null +++ b/hutool-ai/src/main/java/org/dromara/hutool/ai/model/package-info.java @@ -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; diff --git a/hutool-ai/src/main/java/org/dromara/hutool/ai/package-info.java b/hutool-ai/src/main/java/org/dromara/hutool/ai/package-info.java index 2bce16f8b..35cd681c4 100644 --- a/hutool-ai/src/main/java/org/dromara/hutool/ai/package-info.java +++ b/hutool-ai/src/main/java/org/dromara/hutool/ai/package-info.java @@ -15,8 +15,10 @@ */ /** - * AI模块 + * Hutool-ai主要用于AI大模型的封装,只需要对AI模型最基本的设置,即可调用AI大模型。 * * @author elichow + * @since 6.0.0 */ + package org.dromara.hutool.ai; diff --git a/hutool-ai/src/test/java/org/dromara/hutool/ai/AIServiceFactoryTest.java b/hutool-ai/src/test/java/org/dromara/hutool/ai/AIServiceFactoryTest.java index 84ff276ac..912cae25e 100644 --- a/hutool-ai/src/test/java/org/dromara/hutool/ai/AIServiceFactoryTest.java +++ b/hutool-ai/src/test/java/org/dromara/hutool/ai/AIServiceFactoryTest.java @@ -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; import org.dromara.hutool.ai.core.AIConfigBuilder; diff --git a/hutool-ai/src/test/java/org/dromara/hutool/ai/AIUtilTest.java b/hutool-ai/src/test/java/org/dromara/hutool/ai/AIUtilTest.java index f283a1856..3e986d879 100644 --- a/hutool-ai/src/test/java/org/dromara/hutool/ai/AIUtilTest.java +++ b/hutool-ai/src/test/java/org/dromara/hutool/ai/AIUtilTest.java @@ -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; import org.dromara.hutool.ai.core.AIConfigBuilder; diff --git a/hutool-ai/src/test/java/org/dromara/hutool/ai/model/deepseek/DeepSeekServiceTest.java b/hutool-ai/src/test/java/org/dromara/hutool/ai/model/deepseek/DeepSeekServiceTest.java index c5fbe0257..2c1878704 100644 --- a/hutool-ai/src/test/java/org/dromara/hutool/ai/model/deepseek/DeepSeekServiceTest.java +++ b/hutool-ai/src/test/java/org/dromara/hutool/ai/model/deepseek/DeepSeekServiceTest.java @@ -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; import org.dromara.hutool.ai.AIServiceFactory; diff --git a/hutool-ai/src/test/java/org/dromara/hutool/ai/model/doubao/DoubaoServiceTest.java b/hutool-ai/src/test/java/org/dromara/hutool/ai/model/doubao/DoubaoServiceTest.java index 9f69a2e37..c053eb1a5 100644 --- a/hutool-ai/src/test/java/org/dromara/hutool/ai/model/doubao/DoubaoServiceTest.java +++ b/hutool-ai/src/test/java/org/dromara/hutool/ai/model/doubao/DoubaoServiceTest.java @@ -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; import org.dromara.hutool.ai.AIServiceFactory; @@ -13,8 +29,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import static org.junit.jupiter.api.Assertions.*; - class DoubaoServiceTest { String key = "your key"; diff --git a/hutool-ai/src/test/java/org/dromara/hutool/ai/model/grok/GrokServiceTest.java b/hutool-ai/src/test/java/org/dromara/hutool/ai/model/grok/GrokServiceTest.java index 1f8ff2f88..4a3b63c13 100644 --- a/hutool-ai/src/test/java/org/dromara/hutool/ai/model/grok/GrokServiceTest.java +++ b/hutool-ai/src/test/java/org/dromara/hutool/ai/model/grok/GrokServiceTest.java @@ -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; import org.dromara.hutool.ai.AIServiceFactory; diff --git a/hutool-ai/src/test/java/org/dromara/hutool/ai/model/openai/OpenaiServiceTest.java b/hutool-ai/src/test/java/org/dromara/hutool/ai/model/openai/OpenaiServiceTest.java index a9210003e..e5536299d 100644 --- a/hutool-ai/src/test/java/org/dromara/hutool/ai/model/openai/OpenaiServiceTest.java +++ b/hutool-ai/src/test/java/org/dromara/hutool/ai/model/openai/OpenaiServiceTest.java @@ -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; import org.dromara.hutool.ai.AIServiceFactory;