# ai4j
**Repository Path**: LnYo-Cly/ai4j
## Basic Information
- **Project Name**: ai4j
- **Description**: 一款JavaSDK用于快速接入AI大模型应用,整合多平台大模型,如OpenAi、智谱Zhipu(ChatGLM)、深度求索DeepSeek、月之暗面Moonshot(Kimi)、腾讯混元Hunyuan、零一万物(01)等等,提供统一的输入输出(对齐OpenAi)消除差异化,优化函数调用(Tool Call),优化RAG调用、支持向量数据库(Pinecone),并且支持JDK1.8,为用户提供快速整合AI的能力。
- **Primary Language**: Java
- **License**: Apache-2.0
- **Default Branch**: main
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 21
- **Forks**: 17
- **Created**: 2024-11-22
- **Last Updated**: 2026-08-07
## Categories & Tags
**Categories**: Uncategorized
**Tags**: Java, chatGPT, openAI, chatglm, ollama
## README


# ai4j
一款面向 **JDK 8+** 的 Java AI Agentic 开发套件:统一的大模型接入、Tool Calling、MCP、A2A、RAG、Agent Runtime,以及内置的 Coding Agent CLI / TUI / ACP。
[English README](README-EN.md)
## 安装
- Gradle:`implementation 'io.github.lnyo-cly:ai4j:2.4.2'`
- Maven:`io.github.lnyo-clyai4j2.4.2`
## 30 秒跑通
设置 `OPENAI_API_KEY` 后,下面代码即可发出第一条请求:
```java
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,其余代码不变。
## 链接
- 文档站:https://lnyo-cly.github.io/ai4j/
- [5 分钟跑通](docs-site/docs/start-here/five-minute-first-chat.md) / [能力地图](docs-site/docs/start-here/feature-map.md)
- [Coding Agent CLI / TUI / ACP](docs/readme/zh/coding-agent-cli.md) / [A2A Protocol](docs-site/docs/agent/a2a.md)
- [CHANGELOG](CHANGELOG.md) / [CONTRIBUTING](CONTRIBUTING.md)
## 支持的平台
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](docs-site/docs/start-here/feature-map.md)。
## License
[Apache License 2.0](LICENSE)