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

模型部署与调用

目录

部署

ollama下载

模型版本选择 

​编辑 对照表

控制台执行

调用


部署

大模型部署我使用的是Ollama,点击跳转

接下来我将在本地使用ollama就行模型部署的演示

ollama下载

模型版本选择 

 对照表

大家可以根据自己的显卡配置选择对应的模型版本

控制台执行

执行部署 DeepSeek-R1 模型的命令后开始下载对应的模型

        到这里本地大模型就部署成功了,大家可以看到已经能够实现deepseek对话,但我们的目的是调用api对大模型进行使用

调用

import okhttp3.*;
import org.json.JSONObject;
import java.io.IOException;

public class DeepSeekR1ApiClient {
    private static final String API_URL = "https://api.deepseek.com/v1/chat/completions";
    private static final String API_KEY = "your_api_key_here";
    private static final MediaType JSON = MediaType.get("application/json; charset=utf-8");

    public static void main(String[] args) {
        OkHttpClient client = new OkHttpClient();
        
        // 构建请求体
        JSONObject requestBody = new JSONObject();
        requestBody.put("model", "deepseek-r1");  // 指定R1模型
        
        JSONObject message = new JSONObject();
        message.put("role", "user");
        message.put("content", "你好,DeepSeek R1!");
        
        requestBody.put("messages", new JSONObject[] {message});
        
        // 可选参数
        requestBody.put("temperature", 0.7);      // 控制随机性
        requestBody.put("max_tokens", 1024);      // 最大输出token数
        
        Request request = new Request.Builder()
                .url(API_URL)
                .addHeader("Authorization", "Bearer " + API_KEY)
                .post(RequestBody.create(requestBody.toString(), JSON))
                .build();
        
        try (Response response = client.newCall(request).execute()) {
            if (!response.isSuccessful()) {
                throw new IOException("请求失败: " + response.code() + " - " + response.message());
            }
            
            String responseBody = response.body().string();
            System.out.println("API响应: " + responseBody);
            
            // 解析响应
            JSONObject jsonResponse = new JSONObject(responseBody);
            String assistantReply = jsonResponse.getJSONArray("choices")
                    .getJSONObject(0)
                    .getJSONObject("message")
                    .getString("content");
            
            System.out.println("\nAI回复: " + assistantReply);
        } catch (IOException e) {
            System.err.println("请求发生错误: " + e.getMessage());
            e.printStackTrace();
        }
    }
}

当然除了上面的调用方式,还要多种不同的其他方式: 

相关文章:

  • OrbStack 作为 Mac 用户的 Docker 替代方案
  • 数据结构每日一题day9(顺序表)★★★★★
  • Thrust库中,host_vector和device_vector数据之间如何高效传输,有异步传输方式吗?
  • Linux 企业项目服务器组建(附脚本)
  • C++学习笔记(三十二)——priority_queue
  • Java基础 4.1
  • OpenLayers:海量图形渲染之矢量切片
  • 07-01-自考数据结构(20331)- 排序-内部排序知识点
  • 【14】Selenium的基本使用
  • 一道积分_4
  • DJI上云API使用与配置
  • spring打包,打包错误
  • 供应链管理-经济指数:GDP、GNP、NNP、NDP、PPI、CPI、DPI...
  • WordPress汉主题
  • 二、基本应用工具
  • 云原生周刊:Kubernetes v1.33 要来了
  • 针对单台浪潮服务器运行Windows Server 2019和SQL Server的MES系统场景、高效能监控策略(兼顾软硬件健康)
  • golang 的channel
  • 函数类型声明
  • 大模型-提示词(Prompt)技巧
  • 长春网长春网站建设站建设/上海关键词优化报价
  • 北京江苏省住房和城乡建设厅网站/企业文化标语经典
  • 网上商城网站设计/帮平台做推广怎么赚钱
  • 狗爹域名网站/全能搜
  • 制作网站深圳/河北seo基础教程
  • 郑州大学动态网站开发考试答案/公司做网页要多少钱