做一件事,做到极致。LLMKit 专注于为 Java 开发者提供最轻量的 LLM 调用体验。
不依赖 Jackson、Gson、OkHttp 等任何第三方库,仅使用 JDK 标准 API。没有依赖冲突,没有版本地狱。
兼容 JDK 8,而 Spring AI 和 Langchain4j 需要 JDK 17+。无论你的项目跑在什么环境,都能直接使用。
支持多个主流 LLM 提供商,一套 API 切换自如。只需改一行配置,即可在 OpenAI、Anthropic、DeepSeek 等模型间无缝切换。
核心 JAR 不到 200KB,启动即用。没有冗余抽象,没有框架绑定,就是一个纯粹的 LLM 客户端。
添加依赖,初始化客户端,开始对话。就是这么简单。
1. 添加 Maven 依赖
<dependency> <groupId>io.github.intellimill</groupId> <artifactId>llmkit-openai</artifactId> <version>0.1.0</version> </dependency>
2. 编写代码
import io.llmkit.*; LlmClient client = LlmKit.create("sk-xxx"); String answer = client.chat("Hello, LLMKit!"); System.out.println(answer);
3. Switch Provider
LlmClient client = LlmKit .builder(Providers.OPENAI) .apiKey("sk-xxx") .build();
LlmClient client = LlmKit .builder(Providers.DEEPSEEK) .apiKey("sk-xxx") .build();
LlmClient client = LlmKit .builder(Providers.GLM) .apiKey("xxx.xxx") .build();
LlmClient client = LlmKit .builder(Providers.QWEN) .apiKey("sk-xxx") .build();
<!-- 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 层,每一层都可以独立替换和扩展。
统一 API 覆盖主流 LLM 提供商,无缝切换。
直觉式的 API,让你专注于业务逻辑而非基础设施。
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());
client.chatStream(request, new StreamListener() { @Override public void onChunk(ChatChunk chunk) { System.out.print(chunk.text()); } @Override public void onComplete() { System.out.println("\nDone"); } });
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...
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();