springai结合ollama

目录

ollama

介绍

使用

下载:

安装:

点击这个玩意next就行了。

运行

spring ai使用ollama调用本地部署的大模型

加依赖

配置yml

写代码


ollama

介绍

官网:Ollama

Ollama是一个用于部署和运行各种开源大模型的工具;

它能够帮助用户快速在本地运行各种大模型,极大地简化了大模型在本地运行的过程。

用户通过执行几条命令就能在本地运行开源大模型,如Llama2等;

综上,Ollama是一个大模型部署运行工具,在该工具里面可以部署运行各种大模型,方便开发者在本地搭建一套大模型运行环境;

使用

下载:

Download Ollama on macOS

安装:

点击这个玩意next就行了。
运行

ollama run qwen:0.5b-chat(大模型的名字去ollama官网找:library

后面这个qwen:0.5b-chat是模型名字,你需要自己去找对应的想用的模型

注意:默认的ollama api会监听11434端口,可以使用命令进行查看(如下)

netstat-ano | findstr 11434

spring ai使用ollama调用本地部署的大模型

加依赖
<dependency>

   <groupId>org.springframework.ai</groupId>

   <artifactId>spring-ai-ollama-spring-boot-starter</artifactId>

</dependency>
配置yml

因为ollama这个依赖默认用的是minster这个大模型,为了能使用别的大模型,我们可以在配置文件中标明

chat:

option:

model: xxxxx(模型名字)

其他配置默认的,直接抄就行。

写代码
import jakarta.annotation.Resource;
import org.springframework.ai.ollama.OllamaChatClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class olllamacoll {
    @Resource
    private OllamaChatClient ollamaChatClient;
     @RequestMapping(value = "/ai/ollama")
    public Object ollama(@RequestParam(value = "msq") String msq){

    String called=ollamaChatClient.call(msq);
         return called;
     }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值