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

Spring Ai | 从零带你一起走进AI项目(中英)

目录

Thinking

Study question

pox.xml

Maven

Gradle

Configure API Key

Use the AI Client

Question



Thinking

让数据变得更加贴近用户的想法

Study question

  • null

pox.xml

添加依赖

Maven

<dependencies><dependency><groupId>org.springframework.ai</groupId><artifactId>spring-ai-openai-spring-boot-starter</artifactId><version>1.0.0</version></dependency>
</dependencies>

For Gradle:

Gradle

dependencies {implementation 'org.springframework.ai:spring-ai-openai-spring-boot-starter:1.0.0'
}

Configure API Key

Get openAi key on the article:Open Ai | 从零搭建属于你的Ai项目(中英结合)

to the application.yaml or application.properties 

spring:ai:openai:api-key: YOUR_OPENAI_API_KEYmodel: gpt-3.5-turbo
spring.ai.openai.api-key=sk-YourOpenAIKeyHere
spring.ai.openai.model=gpt-3.5-turbo

Use the AI Client

Create a Spring component or service and autowire the AI client:

import org.springframework.ai.openai.OpenAiChatClient;
import org.springframework.stereotype.Service;@Service
public class AiService {private final OpenAiChatClient chatClient;public AiService(OpenAiChatClient chatClient) {this.chatClient = chatClient;}public String ask(String prompt) {return chatClient.call(prompt);}
}

Question

Could not autowire. No beans of 'OpenAiChatClient' type found.


- Thank you -

http://www.xdnf.cn/news/9450.html

相关文章:

  • PXC集群
  • C++数据结构 : 二叉搜索树
  • Java大师成长计划之第32天:使用Kubernetes进行Java应用编排与管理
  • Python页面纸张大小设置
  • 为什么苹果签名会掉签
  • 语音合成之十七 语音合成(TTS)中文自然度:问题、成因、解决方案
  • C++ 初始化大全
  • JavaScript变量宣言三剑客:var、let、const的奇幻冒险
  • 覆盖索引详解:原理、优势与面试要点
  • 循环神经网络(RNN):原理、架构与实战
  • 第1章 计算机系统知识
  • 32. 自动化测试开发之建立mysql和oracle数据库连接池
  • 训练自己的yolo模型,并部署到rk3588上
  • 微元法求解弧长与侧面积
  • 哪些情况索引会失效?
  • ubuntu 24 下使用pip 时碰到Externally Managed Environment Error的解决办法
  • Oracle迁移到瀚高之后,空值问题处理(APP)
  • 数据库相关问题
  • 什么是车间 6S 管理,如何实现人、事、物有序可控
  • [yolov11改进系列]基于yolov11引入全维度动态卷积ODConv的python源码+训练源码
  • QML常用窗口和菜单
  • 深入理解Modbus通信中的延迟机制
  • “相关分析”
  • UE5 蓝图,隐藏一个Actor,同时隐藏它的所有子物体
  • Rust 开发的一些GUI库
  • 如何在 Windows 和 Mac 上擦拭和清洁希捷外置硬盘
  • cf1703G
  • VR 技术与病毒分离鉴定:一场奇妙的邂逅​
  • vue3 getcurrentinstance 用法
  • 聊聊5G RedCap与eRedCap