me/SpringAI/0_Java语言接入AGI基础篇.md

38 lines
2.7 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

## 引言
自从 Open AI 发布 ChatGPT 后获得了全球大量的关注。生成式AI的强大能力无缝集成到了人们生活中的方方面面编程语言的生态中也在紧锣密鼓地建设生成式AI的能力在Java语言中Spring社区早已参与其中。截止行文时已发布了Spring AI 1.0.0-SNAPSHAT版本下文将介绍如何安装并部署AI模型重点探讨Spring AI如何调用模型的能力。
## 什么是Hugging Face
Hugging Face是一个公开的AI模型社区托管着来自世界各地AI领域的开发者、企业、组织上传的模型、数据集等内容。方便那些对AI感兴趣的爱好者分享并下载。它就像一个AI模型的超市一样AI模型的生产制造商会把生产出来的模型上架到这个“超市”消费者在这里可以挑选自己感兴趣的模型下载、试用。官网地址需要魔法www.huggingface.co
## 什么是Ollama
前面已经提到了从哪里获取AI模型但是这个模型和应用软件是不一样的windows、linux、macos等操作系统无法直接运行。Ollama就是一个AI模型的安装和管理工具Ollama可能不是最好的AI模型管理工具但它的兼容性很强这是它的优势。我们可以在windows、linux、macos系统里安装Ollama再通过Ollama获取并安装Hugging Face里的AI模型。
可以在https://ollama.com/download网站下载并安装Ollama。安装好以后可以通过命令行拉取模型了以deepseek-r1举例
```
ollama run hf.co/deepseek-ai/deepseek-r1:7b
```
命令的格式:`ollama run hf.co/用户名/模型名:参数量级`上面的7b就是指R1的70亿参数模型。没有魔法的话`hf.co`可能访问不了,可以换成镜像站`hf-mirror.com`
```
ollama run hf-mirror.com/deepseek-ai/deepseek-r1:7b
```
关于Ollama更多的能力这里不再继续展开感兴趣的话可以在网上找视频继续学习。
## 什么是SpringAI
我这里直接贴上官方的springai的定位官方文档地址https://spring.io/projects/spring-ai
> Spring AI is an application framework for AI engineering. Its goal is to apply to the AI domain Spring ecosystem design principles such as portability and modular design and promote using POJOs as the building blocks of an application to the AI domain.
翻译:
> Spring AI 是一个用于 AI 工程的应用程序框架。 其目标是将 Spring 生态系统设计原则(如可移植性和模块化设计)应用于 AI 领域,并将使用 POJO 构建应用程序推广到 AI 领域。
<img src='https://images.ctfassets.net/mnrwi97vnhts/4mda205vy509Dx3vGkMwFr/af520e66dc79fb80cd1bc129a11d6d23/spring-ai-integration-diagram-3.svg'>