Skip to content

feat(ai): 基于 LangChain4j 的简单对话接口 - #6

Draft
cng1985 wants to merge 1 commit into
modulesfrom
cursor/langchain4j-ai-0c3f
Draft

cng1985 wants to merge 1 commit into
modulesfrom
cursor/langchain4j-ai-0c3f

Conversation

@cng1985

@cng1985 cng1985 commented Apr 20, 2026

Copy link
Copy Markdown
Owner

摘要

本变更新增独立 Maven 子模块 modules/ai(Java 17),使用 LangChain4j 1.0 与 OpenAiChatModel 接入 OpenAI 兼容的聊天 API,并在 Spring MVC 中暴露 JSON 接口。

主要改动

  • 新模块 aiChatModel Bean(未配置 OPENAI_API_KEY 时返回友好提示)、AiChatServiceAiChatRestController/rest/ai/chat)。
  • 依赖结构调整:将原先挂在 modules 父 POM 上的 discover-website、MyBatis、Jodd、servlet-api 等依赖下沉到 businessanalysis,使 ai 模块可单独编译,不强制拉取 discover 全量传递依赖。
  • pom.xml:将阿里云仓库 URL 从 HTTP 改为 HTTPS,避免在较新 Maven 上触发 HTTP 拦截。

配置与调用

  • 环境变量:OPENAI_API_KEY(必填方可真实调用);可选 OPENAI_MODEL(默认 gpt-4o-mini)。
  • 示例:GET {contextPath}/rest/ai/chat.json?message=你好(与现有 *.json 映射一致)。

构建说明

在本环境中 discover-common-freemarker 等私有构件无法从公共仓库解析,完整 web 模块编译需使用团队内部 Maven 仓库或本地已安装的对应 JAR。mvn -pl modules/ai -am compile 已通过验证。

Open in Web Open in Cursor 

Introduce a Java 17 `ai` module with Spring wiring, OpenAI ChatModel via
LangChain4j, and a JSON REST endpoint. Move discover/MyBatis/servlet
dependencies from the modules aggregator into `business` and `analysis` so
`ai` can compile without the full discover stack. Use HTTPS for the Aliyun
Maven repository in the root POM.

Co-authored-by: ada.young <735529126@qq.com>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new ai module utilizing langchain4j for OpenAI integration, including configuration, service, and REST controller layers. It also refactors dependency management by moving common dependencies from the parent modules/pom.xml to specific sub-modules (analysis and business) and updates the Aliyun repository to use HTTPS. Key feedback includes a critical Java version mismatch between the new module (Java 17) and the rest of the project (Java 8), which will lead to runtime errors, and a recommendation to centralize the mybatis-spring version property to avoid hardcoding.

Comment thread modules/ai/pom.xml
Comment on lines +19 to +20
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

模块 ai 配置为 Java 17,但根项目和 web 模块(依赖于 ai)仍配置为 Java 1.8。在 Java 8 环境下运行 Java 17 编译的类会触发 UnsupportedClassVersionError。此外,代码中使用了 String.isBlank() 等 Java 11+ 的 API。建议将全线项目统一升级至 Java 17,或将 ai 模块降级为 Java 8 并修正相关代码。

Comment thread modules/analysis/pom.xml
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>2.0.4</version>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

mybatis-spring 的版本号 2.0.4analysisbusiness 模块中重复硬编码。建议在根 pom.xml<properties> 中定义一个变量(如 <mybatis-spring.version>2.0.4</mybatis-spring.version>)并在此处引用,以确保版本一致性并简化后续维护。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants