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

Spring AI 第二讲 之 Chat Model API 第五节HuggingFace Chat

HuggingFace Inference Endpoints 允许您在云中部署和提供机器学习模型,并通过 API 对其进行访问。

开始使用

有关 HuggingFace Inference Endpoints 的更多详细信息,请访问此处。

前提条件

添加 spring-ai-huggingface 依赖关系:

<dependency><groupId>org.springframework.ai</groupId><artifactId>spring-ai-huggingface</artifactId>
</dependency>

获取 HuggingFace API 密钥并将其设置为环境变量

export HUGGINGFACE_API_KEY=your_api_key_here

请参阅 "依赖关系管理 "部分,将 Spring AI BOM 添加到构建文件中。

请注意,该聊天实现还没有 Spring Boot Starter。

获取推理的端点 URL

调用模型

HuggingfaceChatModel chatModel = new HuggingfaceChatModel(apiKey, basePath);
Prompt prompt = new Prompt("Your text here...");
ChatResponse response = chatModel.call(prompt);
System.out.println(response.getGeneration().getText());

示例

使用此处的示例

String mistral7bInstruct = """[INST] You are a helpful code assistant. Your task is to generate a valid JSON object based on the given information:name: Johnlastname: Smithaddress: #1 Samuel St.Just generate the JSON object without explanations:[/INST]""";
Prompt prompt = new Prompt(mistral7bInstruct);
ChatResponse aiResponse = huggingfaceChatModel.call(prompt);
System.out.println(response.getGeneration().getText());

将产生以下输出

{"name": "John","lastname": "Smith","address": "#1 Samuel St."
}

下节:Spring AI 第二讲 之 Chat Model API 第五节Google VertexAI API

代码后期添加

http://www.lryc.cn/news/364008.html

相关文章:

  • 【笔记】Sturctured Streaming笔记总结(Python版)
  • Python函数进阶
  • [知识点]c++ delete与delete[ ]
  • iCloud如何被高效利用?
  • 月入30000的软件测试人员,简历是什么样子的?
  • nginx官网源代码方式安装nginx并编译
  • iOS ActivityViewController使用
  • 新手快速上手IDEA【常用快捷键】
  • MySQL里如果有字段是function怎么查询呢?
  • 从高海拔到严寒季的测量作业更要「快准稳」,怎么实现?
  • WowTab:简洁界面,效率神器,重塑新标签页浏览体验
  • PostgreSQL 17 Beta1 发布,酷克数据再次贡献核心力量
  • CDH服务红,查看日志发现host有问题
  • 数据分析------统计学知识点(三)
  • MySQL 导出一条数据的插入语句
  • 隐藏 IP 地址的重要性是什么?
  • Oracle 19c linux安装
  • AI音乐生成流程
  • android room数据库升级脚本常见问题
  • 在 iCloud.com 上导入、导出或打印联系人
  • JavaScript中this方法;var,let,constd区别;JSON是什么
  • Mybatis不明白?就这一篇带你轻松入门
  • pymupdf提取pdf表格及表格数据合并
  • 门外汉一次过软考中级(系统集成项目管理工程师)秘笈,请收藏!
  • [leetcode hot 150]第一百零八题,将有序数组转换为二叉搜索树
  • 科普丨什么是数字孪生灌区(平台)?如何建设?有何好处?
  • Python爬虫如何入门:一步步走向精通的指南
  • Linux用户和用户组的操作
  • git命令行分支(增删改查)
  • 地理加权回归GWR简介