LLMKit

Java LLM 客户端的终极选择

轻量 · 零依赖 · 多模型


    

为什么选择 LLMKit

做一件事,做到极致。LLMKit 专注于为 Java 开发者提供最轻量的 LLM 调用体验。

零外部依赖

不依赖 Jackson、Gson、OkHttp 等任何第三方库,仅使用 JDK 标准 API。没有依赖冲突,没有版本地狱。

JDK 8+

兼容 JDK 8,而 Spring AI 和 Langchain4j 需要 JDK 17+。无论你的项目跑在什么环境,都能直接使用。

多模型统一 API

支持多个主流 LLM 提供商,一套 API 切换自如。只需改一行配置,即可在 OpenAI、Anthropic、DeepSeek 等模型间无缝切换。

极致轻量

核心 JAR 不到 200KB,启动即用。没有冗余抽象,没有框架绑定,就是一个纯粹的 LLM 客户端。

三行代码,即刻开始

添加依赖,初始化客户端,开始对话。就是这么简单。

1. 添加 Maven 依赖

XML
<dependency>
    <groupId>io.github.intellimill</groupId>
    <artifactId>llmkit-openai</artifactId>
    <version>0.1.0</version>
</dependency>

2. 编写代码

Java
import io.llmkit.*;

LlmClient client = LlmKit.create("sk-xxx");
String answer = client.chat("Hello, LLMKit!");
System.out.println(answer);

3. Switch Provider

Java · OpenAI
LlmClient client = LlmKit
    .builder(Providers.OPENAI)
    .apiKey("sk-xxx")
    .build();
Java · DeepSeek
LlmClient client = LlmKit
    .builder(Providers.DEEPSEEK)
    .apiKey("sk-xxx")
    .build();
Java · GLM
LlmClient client = LlmKit
    .builder(Providers.GLM)
    .apiKey("xxx.xxx")
    .build();
Java · Qwen
LlmClient client = LlmKit
    .builder(Providers.QWEN)
    .apiKey("sk-xxx")
    .build();
Maven · More Providers
<!-- DeepSeek -->
<artifactId>llmkit-deepseek</artifactId>
<!-- GLM · Zhipu AI -->
<artifactId>llmkit-glm</artifactId>
<!-- Qwen · DashScope -->
<artifactId>llmkit-qwen</artifactId>
<!-- Anthropic -->
<artifactId>llmkit-anthropic</artifactId>

清晰的分层架构

模块化设计,职责分明。从 API 层到 Provider 层,每一层都可以独立替换和扩展。

llmkit-api
接口 + 模型,零依赖 · 包名: io.llmkit
LlmClient LlmClientBuilder LlmProvider LlmKit ChatRequest ChatResponse
llmkit-core
HTTP 客户端 · SSE 解析 · JSON 读写 · 重试策略
JdkHttpClient SseParser JsonReader JsonWriter RetryPolicy
llmkit-protocols
协议编解码 · 请求/响应序列化
OpenAiCodec AnthropicCodec
llmkit-providers
服务提供者 · 通过 ServiceLoader 自动发现
OpenAI Anthropic DeepSeek GLM Qwen MiniMax Kimi

多模型,一站接入

统一 API 覆盖主流 LLM 提供商,无缝切换。

O
OpenAI
OpenAI Protocol
A
Anthropic
Anthropic Protocol
D
DeepSeek
OpenAI Compatible
G
GLM · Zhipu AI
OpenAI Compatible
Q
Qwen · DashScope
OpenAI Compatible
M
MiniMax
OpenAI Compatible
K
Kimi · Moonshot AI
OpenAI Compatible

简洁优雅的 API 设计

直觉式的 API,让你专注于业务逻辑而非基础设施。

1
同步对话
Java
ChatRequest request = ChatRequest.builder()
    .messages(
        ChatMessage.system("You are a helpful assistant"),
        ChatMessage.user("What is quantum computing?")
    )
    .temperature(0.7)
    .build();

ChatResponse response = client.chat(request);
System.out.println(response.content());
2
流式输出
Java
client.chatStream(request, new StreamListener() {
    @Override
    public void onChunk(ChatChunk chunk) {
        System.out.print(chunk.text());
    }

    @Override
    public void onComplete() {
        System.out.println("\nDone");
    }
});
3
函数调用 (Tool Calling)
Java
ToolDefinition tool = ToolDefinition.builder()
    .name("get_weather")
    .description("Get weather for a given city")
    .parameters("{\"type\":\"object\",\"properties\":{...}}")
    .build();

ChatRequest request = ChatRequest.builder()
    .messages(ChatMessage.user("What is the weather in Beijing?"))
    .tools(tool)
    .build();

ChatResponse response = client.chat(request);
// Handle tool_calls...
4
重试策略与高级配置
Java
LlmClient client = LlmKit
    .builder(Providers.DEEPSEEK)
    .apiKey("sk-xxx")
    .model("deepseek-chat")
    .timeout(Duration.ofSeconds(30))
    .retry(RetryPolicy.builder()
        .maxRetries(3)
        .initialDelay(Duration.ofSeconds(1))
        .maxDelay(Duration.ofSeconds(30))
        .build())
    .build();

开始构建你的 AI 应用

三行代码接入 LLM,零依赖、轻量级,开箱即用。

JDK 8+ < 200KB 多协议 · 多模型 MIT License