基于 Spring Boot 3.x 、Spring AI、Ollama 的
自定义模型
功能示例。
您首先需要在本地计算机上运行 Ollama。请参阅官方 Ollama 项目自述文件,开始在本地计算机上运行模型。
其次,你还需要基于Ollama实现一个自定义模型。
Spring AI 工件发布在 Spring Milestone
和 Snapshot
存储库中。请参阅存储库部分将这些存储库添加到您的构建系统中。
为了帮助进行依赖管理,Spring AI 提供了 BOM(物料清单),以确保在整个项目中使用一致的 Spring AI 版本。请参阅依赖管理部分将 Spring AI BOM 添加到您的构建系统。
Spring AI 为 Ollama 聊天客户端提供 Spring Boot 自动配置。要启用它,请将以下依赖项添加到项目的 Maven pom.xml
文件中:
<dependency>
<groupId>dev.langchain4j</groupId>
<artifactId>langchain4j-ollama-spring-boot-starter</artifactId>
</dependency>
或者,在你的 Gradle 构建文件 build.gradle
中添加:
dependencies {
implementation 'dev.langchain4j:langchain4j-ollama-spring-boot-starter'
}
llama3-13b-chinese:12b
Qwen2 是阿里巴巴集团推出的全新系列大型语言模型。
Qwen2基于29 种语言的数据进行训练,包括英语和中文。
注意: 安装 ollama run qwen2
将下载一个 4.4GB 的 docker 镜像。
它有 4 种参数大小:0.5B、1.5B、7B、72B。 在 7B 和 72B 模型中,上下文长度已扩展至128k 个 token。
Models | Qwen2-0.5B | Qwen2-1.5B | Qwen2-7B | Qwen2-72B |
---|---|---|---|---|
Params | 0.49B | 1.54B | 7.07B | 72.71B |
Non-Emb Params | 0.35B | 1.31B | 5.98B | 70.21B |
GQA | True | True | True | True |
Tie Embedding | True | True | False | False |
Context Length | 32K | 32K | 128K | 128K |
通过文档,我们可以可知 qwen2:0.5b
和 qwen2:1.5b
模型支持 Embedding 。