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

ollama list模型列表获取 接口代码

ollama list模型列表获取 接口代码

curl http://localhost:11434/v1/models

在这里插入图片描述

coding

package hcx.ollama;/*** @ClassName DockerOllamaList* @Description TODO* @Author dell* @Date 2025/5/26 11:31* @Version 1.0**/import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;public class DockerOllamaListApi {public static List<String> getOllamaModelNames(String host, int port) {List<String> modelNames = new ArrayList<>();try {URL url = new URL(String.format("http://%s:%d/v1/models", host, port));HttpURLConnection conn = (HttpURLConnection) url.openConnection();conn.setRequestMethod("GET");BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));StringBuilder response = new StringBuilder();String line;while ((line = reader.readLine()) != null) {response.append(line);}reader.close();// 使用正则表达式提取模型IDPattern pattern = Pattern.compile("\"id\":\"([^\"]+)\".*?\"object\":\"model\"");Matcher matcher = pattern.matcher(response.toString());while (matcher.find()) {modelNames.add(matcher.group(1));}} catch (Exception e) {throw new RuntimeException("获取Ollama模型列表失败", e);}return modelNames;}public static void main(String[] args) {try {// 使用Ollama API获取模型列表List<String> modelNames = getOllamaModelNames("127.0.0.1", 11434);System.out.println("模型列表:");for (String modelName : modelNames) {System.out.println(modelName);}} catch (Exception e) {e.printStackTrace();}}
}

相关文章:

  • Python打卡第37天
  • Redis与Lua脚本深度解析:原理、应用与最佳实践
  • 【DCCN】多模态情感分析解耦交叉属性关联网络
  • 【Redis】第1节|Redis服务搭建
  • 在Windows上,将 Ubuntu WSL 安装并迁移到 D 盘完整教程(含 Appx 安装与迁移导入)
  • FFmpeg 4.3 H265 二十二.4,使用计算机摄像头,通过VCL软件, 模拟 监控摄像头 的 RTSP 流
  • SDL2常用函数:SDL_BlitSurfaceSDL_UpdateWindowSurface 数据结构及使用介绍
  • Elasticsearch Synthetic _source
  • openpi π₀ 项目部署运行逻辑(三)——策略推理服务器 serve_policy.py
  • OpenCV (C/C++) 中使用 Sobel 算子进行边缘检测
  • Leetcode 3557. Find Maximum Number of Non Intersecting Substrings
  • 如何通过PHPMyadmin对MYSQL数据库进行管理?
  • MQTT-Vue整合
  • 精益数据分析(87/126):市场-产品契合度重构——现有产品寻找新市场的实战指南
  • R 语言科研绘图 --- 热力图-汇总
  • 《软件工程》第 2 章 -UML 与 RUP 统一过程
  • 第11章1 扩展 MySQL
  • Linux连接服务器全攻略:从基础到进阶
  • Hadoop架构与核心模块解析
  • hadoop纠删码基本原理
  • 微站网建站系统/免费推广网站视频
  • 明星做代言的购物网站0/鸿星尔克网络营销
  • 代网站建设/网络销售推广是做什么的具体
  • wordpress图片集插件/石家庄网站seo外包
  • 光谷做网站推广/百度搜索链接入口
  • 关于电商平台/seo百度关键词排名