最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

deepseek本地部署及java、python調(diào)用步驟詳解

 更新時(shí)間:2025年02月15日 10:19:46   作者:Most666  
這篇文章主要介紹了如何下載和使用Ollama模型,包括安裝JDK?17及以上版本和Spring?Boot?3.3.6,配置pom文件和application.yml,創(chuàng)建Controller,以及使用Python調(diào)用模型,需要的朋友可以參考下

1.下載Ollama

(需要科學(xué)上網(wǎng))

https://ollama.com/

2.拉取模型

輸入命令

ollama pull deepseek-v3

由于v3太大,改為r1,命令為:

ollama run deepseek-r1:1.5b

查看安裝的模型

ollama ls

查看啟動(dòng)的模型

ollama ps

對話框輸入/bye退出

3.Java調(diào)用

目前僅支持jdk17以上版本使用,本文使用的是jdk21,springboot版本為3.3.6版本過高、過低時(shí)都無法正常啟動(dòng)

3.1引入pom

<?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 https://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.6</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>demo21</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demo21</name>
    <description>demo21</description>

    <properties>
        <java.version>21</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>io.springboot.ai</groupId>
            <artifactId>spring-ai-ollama-spring-boot-starter</artifactId>
            <version>1.0.3</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <annotationProcessorPaths>
                        <path>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </path>
                    </annotationProcessorPaths>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

3.2配置application.yml

server:
  port: 8088
spring:
  application:
    name: demo21
  ai:
    ollama:
      base-url: http://localhost:11434
      chat:
        options:
          model: deepseek-r1:1.5b

3.2創(chuàng)建Controller

import org.springframework.ai.chat.ChatResponse;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.ai.ollama.OllamaChatClient;
import org.springframework.ai.ollama.api.OllamaOptions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class OllamaClientController {

    @Autowired
    @Qualifier("ollamaChatClient")
    private OllamaChatClient ollamaChatClient;

    /**
     * http://localhost:8088/ollama/chat/v1?msg=java就業(yè)前景
     */
    @GetMapping("/ollama/chat/v1")
    public String ollamaChat(@RequestParam String msg) {
        return this.ollamaChatClient.call(msg);
    }

    /**
     * http://localhost:8088/ollama/chat/v2?msg=java就業(yè)前景
     */
    @GetMapping("/ollama/chat/v2")
    public Object ollamaChatV2(@RequestParam String msg) {
        Prompt prompt = new Prompt(msg);
        ChatResponse chatResponse = ollamaChatClient.call(prompt);
        return chatResponse.getResult().getOutput().getContent();
    }

    /**
     * http://localhost:8088/ollama/chat/v3?msg=java就業(yè)前景
     */
    @GetMapping("/ollama/chat/v3")
    public Object ollamaChatV3(@RequestParam String msg) {
        Prompt prompt = new Prompt(
                msg,
                OllamaOptions.create()
                        .withModel("deepseek-r1:1.5b")
                        .withTemperature(0.4F));
        ChatResponse chatResponse = ollamaChatClient.call(prompt);
        return chatResponse.getResult().getOutput().getContent();
    }
}

4.python調(diào)用

pip引入

pip install ollama

創(chuàng)建.py文件

import ollama

# 流式輸出
def api_generate(text: str):
    print(f'提問:{text}')

    stream = ollama.generate(
        stream=True,
        model='deepseek-r1:1.5b',
        prompt=text,
    )

    print('-----------------------------------------')
    for chunk in stream:
        if not chunk['done']:
            print(chunk['response'], end='', flush=True)
        else:
            print('\n')
            print('-----------------------------------------')
            print(f'總耗時(shí):{chunk['total_duration']}')
            print('-----------------------------------------')

def api_chat(text: str):
    print(f'提問:{text}')

    stream = ollama.chat(
        stream=True,
        model='deepseek-r1:1.5b',
        messages=[{"role":"user","content":text}]
    )

    print('-----------------------------------------')
    for chunk in stream:
        if not chunk['done']:
            print(chunk['message'].content, end='', flush=True)
        else:
            print('\n')
            print('-----------------------------------------')
            print(f'總耗時(shí):{chunk['total_duration']}')
            print('-----------------------------------------')

if __name__ == '__main__':
    # 流式輸出
    api_generate(text='python就業(yè)前景')
    
    api_chat(text='python就業(yè)前景')

    # 非流式輸出
    content = ollama.generate(model='deepseek-r1:1.5b', prompt='python就業(yè)前景')
    print(content)

    content = ollama.chat(model='deepseek-r1:1.5b', messages=[{"role":"user","content":'python就業(yè)前景'}])
    print(content)

總結(jié) 

到此這篇關(guān)于deepseek本地部署及java、python調(diào)用的文章就介紹到這了,更多相關(guān)deepseek本地部署java、python調(diào)用內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • javax.validation.constraints如何校驗(yàn)參數(shù)合法性

    javax.validation.constraints如何校驗(yàn)參數(shù)合法性

    本文將深入探討javax.validation.constraints的基本用法和高級應(yīng)用,幫助讀者更好地理解和運(yùn)用這個(gè)強(qiáng)大的校驗(yàn)框架,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-07-07
  • 在Java與Kotlin之間如何進(jìn)行互操作詳解

    在Java與Kotlin之間如何進(jìn)行互操作詳解

    這篇文章主要給大家介紹了關(guān)于在Java和Kotlin之間如何進(jìn)行互操作的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-12-12
  • MyBatis分頁插件PageHelper深度解析與實(shí)踐指南

    MyBatis分頁插件PageHelper深度解析與實(shí)踐指南

    在數(shù)據(jù)庫操作中,分頁查詢是最常見的需求之一,傳統(tǒng)的分頁方式通常有兩種內(nèi)存分頁和SQL分頁,MyBatis作為優(yōu)秀的ORM框架,本身并未提供統(tǒng)一的分頁解決方案,這正是PageHelper誕生的背景,下面小編給大家詳細(xì)說說MyBatis分頁插件PageHelper,需要的朋友可以參考下
    2025-05-05
  • 帶你入門Java的方法

    帶你入門Java的方法

    這篇文章主要介紹了java基礎(chǔ)之方法詳解,文中有非常詳細(xì)的代碼示例,對正在學(xué)習(xí)java基礎(chǔ)的小伙伴們有非常好的幫助,需要的朋友可以參考下
    2021-07-07
  • Java布隆過濾器的原理和實(shí)現(xiàn)分析

    Java布隆過濾器的原理和實(shí)現(xiàn)分析

    數(shù)組、鏈表、樹等數(shù)據(jù)結(jié)構(gòu)會(huì)存儲(chǔ)元素的內(nèi)容,一旦數(shù)據(jù)量過大,消耗的內(nèi)存也會(huì)呈現(xiàn)線性增長所以布隆過濾器是為了解決數(shù)據(jù)量大的一種數(shù)據(jù)結(jié)構(gòu)。本文就來和大家詳細(xì)說說布隆過濾器的原理和實(shí)現(xiàn),感興趣的可以了解一下
    2022-10-10
  • Java JDK動(dòng)態(tài)代理的基本原理詳細(xì)介紹

    Java JDK動(dòng)態(tài)代理的基本原理詳細(xì)介紹

    這篇文章主要介紹了Java JDK動(dòng)態(tài)代理的基本原理詳細(xì)介紹的相關(guān)資料,這里對動(dòng)態(tài)代理進(jìn)行了詳解并附簡單實(shí)例代碼,需要的朋友可以參考下
    2017-01-01
  • SpringBoot事件機(jī)制相關(guān)知識(shí)點(diǎn)匯總

    SpringBoot事件機(jī)制相關(guān)知識(shí)點(diǎn)匯總

    這篇文章主要介紹了SpringBoot事件機(jī)制相關(guān)知識(shí)點(diǎn)匯總,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-09-09
  • java實(shí)現(xiàn)馬踏棋盤的完整版

    java實(shí)現(xiàn)馬踏棋盤的完整版

    這篇文章主要為大家詳細(xì)介紹了java實(shí)現(xiàn)馬踏棋盤的完整版,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-02-02
  • mybatis-plus內(nèi)置雪花算法主鍵重復(fù)問題解決

    mybatis-plus內(nèi)置雪花算法主鍵重復(fù)問題解決

    本文主要介紹了mybatis-plus內(nèi)置雪花算法主鍵重復(fù)問題解決,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-09-09
  • Java利用Spire.XLS?for?Java實(shí)現(xiàn)查找并替換Excel中的數(shù)據(jù)

    Java利用Spire.XLS?for?Java實(shí)現(xiàn)查找并替換Excel中的數(shù)據(jù)

    在日常的數(shù)據(jù)處理工作中,Excel?文件無疑是最常見的載體之一,本文將深入探討如何借助?Java?語言和強(qiáng)大的?Spire.XLS?for?Java?自動(dòng)化處理?Excel?文件的查找替換任務(wù),感興趣的小伙伴可以了解下
    2025-09-09

最新評論

平昌县| 青田县| 临邑县| 伊川县| 平果县| 洛浦县| 马尔康县| 潮安县| 嘉鱼县| 即墨市| 上虞市| 图片| 安宁市| 长葛市| 敦煌市| 鹿邑县| 革吉县| 虞城县| 那曲县| 滁州市| 新兴县| 黄平县| 青铜峡市| 额尔古纳市| 孝感市| 天全县| 南开区| 藁城市| 偃师市| 贵溪市| 青河县| 忻州市| 蒙城县| 阳朔县| 周口市| 淮北市| 阳山县| 丰都县| 南岸区| 宝鸡市| 当雄县|