Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

857 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

ai4j banner

Maven Central Docs License JDK 8+ Agentic Enabled MCP Supported A2A Supported RAG Built-in CLI TUI ACP Built-in

ai4j

一款面向 JDK 8+ 的 Java AI Agentic 开发套件:统一的大模型接入、Tool Calling、MCP、A2A、RAG、Agent Runtime,以及内置的 Coding Agent CLI / TUI / ACP。

English README

安装

  • Gradle:implementation 'io.github.lnyo-cly:ai4j:2.4.2'
  • Maven:<dependency><groupId>io.github.lnyo-cly</groupId><artifactId>ai4j</artifactId><version>2.4.2</version></dependency>

30 秒跑通

设置 OPENAI_API_KEY 后,下面代码即可发出第一条请求:

import io.github.lnyocly.ai4j.config.OpenAiConfig;
import io.github.lnyocly.ai4j.platform.openai.chat.entity.ChatCompletion;
import io.github.lnyocly.ai4j.platform.openai.chat.entity.ChatCompletionResponse;
import io.github.lnyocly.ai4j.platform.openai.chat.entity.ChatMessage;
import io.github.lnyocly.ai4j.service.Configuration;
import io.github.lnyocly.ai4j.service.IChatService;
import io.github.lnyocly.ai4j.service.PlatformType;
import io.github.lnyocly.ai4j.service.factory.AiService;
public class Ai4jFirstChat {
    public static void main(String[] args) {
        OpenAiConfig openAiConfig = new OpenAiConfig();
        openAiConfig.setApiKey(System.getenv("OPENAI_API_KEY"));
        Configuration configuration = new Configuration();
        configuration.setOpenAiConfig(openAiConfig);
        AiService aiService = new AiService(configuration);
        IChatService chatService = aiService.getChatService(PlatformType.OPENAI);
        ChatCompletion request = ChatCompletion.builder()
                .model("gpt-4o-mini")
                .message(ChatMessage.withUser("用一句话介绍 ai4j"))
                .build();
        ChatCompletionResponse response = chatService.chatCompletion(request);
        System.out.println(response.getChoices().get(0).getMessage().getContent().getText());
    }
}

输出示例:

ai4j 是一款面向 JDK 8+ 的 Java AI Agentic 开发套件,覆盖统一模型接入、Tool Calling、MCP 与 RAG。

换成 DashScope / DeepSeek / Ollama 等其他平台?只需替换 PlatformType 与对应 Config,其余代码不变。

链接

支持的平台

OpenAI / OpenAI-compatible, Anthropic, DashScope(通义/百炼), Doubao(火山方舟/豆包), DeepSeek, Moonshot, Zhipu(智谱), Hunyuan(腾讯混元), Lingyi(零一万物), Ollama, MiniMax, Baichuan, Suno;Rerank(Jina / Ollama / Doubao);AgentFlow(Dify / Coze / n8n);VectorStore(Pinecone / Qdrant / pgvector / Milvus / Redis)。完整能力列表见 feature-map

License

Apache License 2.0

About

Java 8+ agentic SDK: unified LLM access (OpenAI/Anthropic/DashScope/Doubao/DeepSeek...), Tool Calling, MCP, RAG, Agent Runtime, and a built-in Coding Agent CLI/TUI/ACP.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages