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

LangChain4J入门:接入大模型

承接上文LangChain4J入门:创建SpringBoot应用程序-CSDN博客

(一)添加依赖

在pom.xml中加入方法一:

<properties><langchain4j.version>1.0.0-beta3</langchain4j.version> <!-- 稳定版 --></properties><dependencies><!-- LangChain4j OpenAI 集成 --><dependency><groupId>dev.langchain4j</groupId><artifactId>langchain4j-open-ai</artifactId><version>${langchain4j.version}</version></dependency></dependencies>

方法二(推荐):

<properties><langchain4j.version>1.0.0-beta3</langchain4j.version> <!-- 稳定版 --></properties><dependencies><!-- LangChain4j OpenAI 集成 --><dependency><groupId>dev.langchain4j</groupId><artifactId>langchain4j-open-ai</artifactId></dependency></dependencies>
<dependencyManagement><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-dependencies</artifactId><version>${spring-boot.version}</version><type>pom</type><scope>import</scope></dependency>
<!--物料清单 (BOM)--><dependency><groupId>dev.langchain4j</groupId><artifactId>langchain4j-bom</artifactId><version>1.0.0-beta3</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement>

(二)LLMTest类

在test的java包下新建一个包com.aiguigu.java.ai.langchain4j下新建一个类

package com.aiguigu.java.ai.langchain4j;import dev.langchain4j.model.openai.OpenAiChatModel;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;@SpringBootTest
public class LLMTest {@Testpublic void testGPTDemo() {OpenAiChatModel model = OpenAiChatModel.builder().baseUrl("http://langchain4j.dev/demo/openai/v1").apiKey("demo").modelName("gpt-4o-mini").build();String answer=model.chat("你是谁呀");System.out.println(answer);}
}

运行输出

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

相关文章:

  • 系统学习算法:专题十六 字符串
  • 第三章-提示词-高级:开启智能交互新境界(13/36)
  • 日常--详细介绍qt Designer常用快捷键(详细图文)
  • 【QT】概述
  • 高质量数据集|建设三大难点
  • 01.MySQL 安装
  • 服务器中切换盘的操作指南
  • Android 之 MVVM架构
  • 使用 Docker 部署 Golang 程序
  • 第四章:OSPF 协议
  • Dify中自定义工具类的类型
  • WebMvc自动配置流程讲解
  • MySQL 索引失效的场景与原因
  • 嵌入式开发学习———Linux环境下IO进程线程学习(二)
  • 04.Redis 的多实例
  • 笔试——Day27
  • 前端面试手撕题目全解析
  • 【数据迁移】Windows11 下将 Ubuntu 从 C 盘迁移到 D 盘
  • Redis——常用指令汇总指南(三)(哈希类型)
  • Odoo OWL前端框架全面学习指南 (后端开发者视角)
  • 三角洲行动ACE反作弊VT-d报错?CPU虚拟化如何开启!
  • GitOps:云原生时代的革命性基础设施管理范式
  • Ubuntu20.04 Carla安装与和Ros联合仿真
  • Ubuntu22.4部署大模型前置安装
  • AI + 云原生:正在引爆下一代应用的技术革命
  • LabVIEW小波变换检测信号断点
  • HCIP笔记(第四章)
  • 悬挂的绳子,它的函数方程是什么样子的?
  • Python Dash 全面讲解
  • 大屏项目展示