环境准备
JDK17 环境 java17
本地OLLAMA服务 参考:【大模型】OLLAMA 本地部署使用 - Windows篇
工程搭建
接口调用
配置 application.yml
server:
port: 8088
spring:
application:
name: ollama
ai:
ollama:
base-url: http://localhost:11434 #服务地址
chat:
options:
model: qwen2:0.5b #模型名称
接口定义
package com.ap.ai.controller;
import jakarta.annotation.Resource;
import org.springframework.ai.ollama.OllamaChatModel;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* @Author : AP
* @Date: 2024/9/4 下午8:42
* @Description:
*/
@RestController
public class OllamaChatController {
@Resource
private OllamaChatModel ollamaChatClient;
@GetMapping("/ollama/chat")
public String chat(@RequestParam String msg){
return ollamaChatClient.call(msg);
}
}
使用
后续更新更加丰富类型调用使用