当前位置: 首页 > article >正文

使用spring-ai-ollama访问本地化部署DeepSeek

创建SpringBoot工程,引入依赖
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.3.8</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <groupId>org.example</groupId>
    <artifactId>springai-deepseek</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
        <spring-ai.version>1.0.0-M5</spring-ai.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.ai</groupId>
            <artifactId>spring-ai-ollama-spring-boot-starter</artifactId>
            <version>1.0.0-SNAPSHOT</version>
        </dependency>
    </dependencies>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.ai</groupId>
                <artifactId>spring-ai-bom</artifactId>
                <version>${spring-ai.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <!--下载spring-ai相关包需要用到的仓库地址-->
    <repositories>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <releases>
                <enabled>false</enabled>
            </releases>
        </repository>
    </repositories>

</project>
创建配置文件

application.properties

server.port=8899
spring.application.name=spring-ai-deepseek-demo

spring.ai.ollama.base-url=http://localhost:11434
spring.ai.ollama.chat.options.model=deepseek-r1:1.5b
spring.ai.ollama.chat.options.temperature=0.7
创建启动类
@SpringBootApplication
public class SpringAiDemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringAiDemoApplication.class, args);
    }

}
创建Controller
@RestController
public class ChatDeepSeekController {

    @Autowired
    private OllamaChatModel ollamaChatModel;

    @GetMapping("/ai/test")
    public String generate(@RequestParam(value = "message", defaultValue = "hello")
                           String message) {
        String response = this.ollamaChatModel.call(message);
        System.out.println("response : "+response);
        return response;
    }
}


http://www.kler.cn/a/595756.html

相关文章:

  • 企业信息化的“双螺旋”——IT治理和数据治理
  • MySQL0基础学习记录-下载与安装
  • 光影香江聚四海,蓝陵科技扬帆数字内容新蓝海
  • 充分了解深度学习
  • Jsonpath使用
  • 游戏MOD伴随盗号风险,仿冒网站借“风灵月影”窃密【火绒企业版V2.0】
  • 【linux】防止SSD掉盘导致无法 reboot 软重启
  • Mysql表的简单操作
  • 嵌入式开发之STM32学习笔记day07
  • 基于RAGFlow本地部署DeepSeek-R1大模型与知识库:从配置到应用的全流程解析
  • UR5e机器人位姿
  • fpga系列 HDL:tips 状态机状态转换时BitOut会存在未知状态的输出的解决
  • JAVA泛型擦除原理
  • Three.js中的加载器与资源管理:构建丰富3D场景的关键
  • 清晰易懂的Maven安装教程(含自定义依赖包位置)
  • 星越L_陡坡缓降使用讲解
  • 卷积神经网络梯度消失与梯度爆炸的通俗解释
  • 亚信科技:寒风中,用AI驱动增长
  • WEB API 设计规范
  • 基于 kubekey -实现懒人一键部署K8S集群