spring-ai 下载不了依赖spring-ai-openai-spring-boot-starter

第1坑:配置第三方仓库不生效, 提示在阿里云仓库没有找到 spring-ai-openai-spring-boot-starter

第2坑:升级jdk17后,springboot项目启动报错

Internal error (java.lang.reflect.InaccessibleObjectException): Unable to make protected void java.util.ResourceBundle.setParent(java.util.ResourceBundle) accessible: module java.base does not "opens java.util" to unnamed module @bef2d72

java.lang.reflect.InaccessibleObjectException: Unable to make protected void java.util.ResourceBundle.setParent(java.util...

也可以尝试多次运行,一般第二次就会成功运行,原因不详!!! 本人尝试配置vm参数好像不会再出现这个情况,尝试的少,所以不好定论

3. 中间商

https://api.xty.app/token

4.application.properties配置

附上完整的pom文件:

复制代码
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.2.5</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <groupId>com.ldj.ai</groupId>
    <artifactId>open-ai</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>open-ai</name>
    <description>openAI project for Spring Boot</description>

    <properties>
        <java.version>17</java.version>
        <spring-ai.version>1.0.0-M1</spring-ai.version>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.ai</groupId>
                <artifactId>spring-ai-bom</artifactId>
                <version>${spring-ai.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <artifactId>junit-jupiter</artifactId>
                    <groupId>org.junit.jupiter</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        
        <!--单测有点小bug,说找不到依赖,降低junit版本-->
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>5.5.0</version>
            <scope>test</scope>
        </dependency>

        <!--版本继承spring-ai-bom-->
        <dependency>
            <groupId>org.springframework.ai</groupId>
            <artifactId>spring-ai-openai-spring-boot-starter</artifactId>
        </dependency>
    </dependencies>

    <!--第三方依赖库,注意配置了有可能不生效,需要修改maven setting配置文件,见截图-->
    <repositories>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

参考官方示例:Chat Client API :: Spring AI Reference

后续补充:

复制代码
package com.ldj.ai.openai.controller;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.web.bind.annotation.*;

/**
 * User: ldj
 * Date: 2024/7/7
 * Time: 15:03
 * Description: AI 聊天controller
 */
@RestController
@RequestMapping("/openai")
public class ChatController {

    private final ChatClient chatClient;

    public ChatController(ChatClient.Builder chatClientBuilder) {
        this.chatClient = chatClientBuilder.build();
    }

    @GetMapping("/chat")
    public String generation(@RequestParam(value = "question", defaultValue = "使用中文简短介绍自己") String question) {
        return this.chatClient.prompt()
                .user(question)
                .call()
                .content();
    }

}
相关推荐
进度猫4 分钟前
5个甘特图高阶用法,不止简单排工期
大数据·人工智能·产品经理·甘特图·项目管理软件
码视野5 分钟前
基于 Vue3 + Element Plus 的【基于大模型与知识图谱的 AI 智能法律咨询与案件辅助研判系统】设计与实现(附完整源码与PRD)
人工智能·知识图谱
跨境旺仔小拳头16 分钟前
如何使用Crawl4AI进行网页爬虫?从0搭建教程与代理配置指南
网络·人工智能·爬虫·chatgpt·aigc
mqiqe20 分钟前
AgentScope Java 2.0 协议集成全景解析:A2A、AG-UI、Agent Protocol 三大开放协议实战指南
java·开发语言·ui
脉动数据行情25 分钟前
Java 实现台股 TWSE/TPEx 行情采集(个股 + K 线)
java·开发语言·twse·tpex·台股
财迅通Ai1 小时前
AI布局全面深化,赤子城科技上半年创新业务收入大幅增长41.2%
人工智能·科技·赤子城科技
冬奇Lab1 小时前
Code Agent 解剖(11):Harness 设计之一——控制流
人工智能·开源
码视野1 小时前
基于 Vue3 + Element Plus 的【智慧新能源汽车充电桩运维调度与分时共享租赁系统】设计与实现(附完整源码与PRD)
运维·人工智能·汽车·vue3
冬奇Lab1 小时前
开源项目第198期:Omarchy — DHH 打造的「意见鲜明」Linux 桌面系统
人工智能·开源·操作系统