mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-06-10 03:07:32 +08:00
feat(agent-openai): add OpenAI factory and compatible presets
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
46
liteflow-react-agent/liteflow-react-agent-openai/pom.xml
Normal file
46
liteflow-react-agent/liteflow-react-agent-openai/pom.xml
Normal file
@@ -0,0 +1,46 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.yomahub</groupId>
|
||||
<artifactId>liteflow-react-agent</artifactId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>liteflow-react-agent-openai</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>21</maven.compiler.source>
|
||||
<maven.compiler.target>21</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.yomahub</groupId>
|
||||
<artifactId>liteflow-react-agent-core</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<version>${junit.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<skipTests>false</skipTests>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.yomahub.liteflow.agent.openai;
|
||||
|
||||
import io.agentscope.core.model.OpenAIChatModel;
|
||||
|
||||
public final class OpenAICompatiblePresets {
|
||||
private OpenAICompatiblePresets() {}
|
||||
|
||||
public static OpenAIChatModel deepseek(String apiKey, String modelName) {
|
||||
return OpenAIModelFactory.custom(apiKey, "https://api.deepseek.com/v1", modelName);
|
||||
}
|
||||
public static OpenAIChatModel kimi(String apiKey, String modelName) {
|
||||
return OpenAIModelFactory.custom(apiKey, "https://api.moonshot.cn/v1", modelName);
|
||||
}
|
||||
public static OpenAIChatModel glm(String apiKey, String modelName) {
|
||||
return OpenAIModelFactory.custom(apiKey, "https://open.bigmodel.cn/api/paas/v4", modelName);
|
||||
}
|
||||
public static OpenAIChatModel minimax(String apiKey, String modelName) {
|
||||
return OpenAIModelFactory.custom(apiKey, "https://api.minimax.chat/v1", modelName);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.yomahub.liteflow.agent.openai;
|
||||
|
||||
import io.agentscope.core.model.OpenAIChatModel;
|
||||
|
||||
public final class OpenAIModelFactory {
|
||||
private OpenAIModelFactory() {}
|
||||
|
||||
public static OpenAIChatModel openai(String apiKey, String modelName) {
|
||||
return OpenAIChatModel.builder()
|
||||
.apiKey(apiKey)
|
||||
.modelName(modelName)
|
||||
.build();
|
||||
}
|
||||
|
||||
public static OpenAIChatModel custom(String apiKey, String baseUrl, String modelName) {
|
||||
return OpenAIChatModel.builder()
|
||||
.apiKey(apiKey)
|
||||
.baseUrl(baseUrl)
|
||||
.modelName(modelName)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.yomahub.liteflow.agent.openai;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class OpenAICompatiblePresetsTest {
|
||||
@Test void deepseek_ok() { assertNotNull(OpenAICompatiblePresets.deepseek("k", "deepseek-chat")); }
|
||||
@Test void kimi_ok() { assertNotNull(OpenAICompatiblePresets.kimi("k", "moonshot-v1-8k")); }
|
||||
@Test void glm_ok() { assertNotNull(OpenAICompatiblePresets.glm("k", "glm-4")); }
|
||||
@Test void minimax_ok() { assertNotNull(OpenAICompatiblePresets.minimax("k", "abab6.5s-chat")); }
|
||||
}
|
||||
@@ -17,8 +17,7 @@
|
||||
|
||||
<modules>
|
||||
<module>liteflow-react-agent-core</module>
|
||||
<!-- <module>liteflow-react-agent-openai</module> -->
|
||||
<!-- <module>liteflow-react-agent-anthropic</module> -->
|
||||
<module>liteflow-react-agent-openai</module>
|
||||
<!-- <module>liteflow-react-agent-gemini</module> -->
|
||||
<!-- <module>liteflow-react-agent-dashscope</module> -->
|
||||
</modules>
|
||||
|
||||
Reference in New Issue
Block a user