Skip to content

[BUG] java.lang.IllegalArgumentException: chatModel cannot be null #291

@QingQiuGeek

Description

@QingQiuGeek

I only want to use streamingChatModel, not chatModel, so I only configured streamingChatModel(), but the error is as follows:
If I configure streamingChatModel and chatModel at the same time, then chatModel will take effect.

my code:

Image

the error:
java.lang.IllegalArgumentException: chatModel cannot be null

at dev.langchain4j.internal.Exceptions.illegalArgument(Exceptions.java:23)
at dev.langchain4j.internal.ValidationUtils.ensureNotNull(ValidationUtils.java:54)
at dev.langchain4j.internal.ValidationUtils.ensureNotNull(ValidationUtils.java:41)
at dev.langchain4j.guardrail.ChatExecutor$SynchronousBuilder.<init>(ChatExecutor.java:100)
at dev.langchain4j.guardrail.ChatExecutor.builder(ChatExecutor.java:39)
at dev.langchain4j.service.DefaultAiServices$1.invoke(DefaultAiServices.java:252)
at jdk.proxy2/jdk.proxy2.$Proxy153.chat(Unknown Source)
at com.qingqiu.aigeek.ChatTest.easyRag(ChatTest.java:186)

It is worth mentioning that chatModel should also be specified in the @aiservice annotation, otherwise it is the same error. How to solve it

jdk is 21 ,springboot 3.4.4, the environment dependences:
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- searXNG 联网搜索 --> <dependency> <groupId>dev.langchain4j</groupId> <artifactId>langchain4j-community-web-search-engine-searxng</artifactId> <version>1.1.0-beta7</version> </dependency> <!-- ip属地查询--> <dependency> <groupId>org.lionsoul</groupId> <artifactId>ip2region</artifactId> <version>2.6.5</version> </dependency> <!-- Sa-Token 权限认证,在线文档:https://sa-token.cc --> <dependency> <groupId>cn.dev33</groupId> <artifactId>sa-token-spring-boot3-starter</artifactId> <version>1.44.0</version> </dependency> <!-- Sa-Token 整合 RedisTemplate --> <dependency> <groupId>cn.dev33</groupId> <artifactId>sa-token-redis-template</artifactId> <version>1.44.0</version> </dependency> <!--引入邮件任务启动器--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-mail</artifactId> </dependency> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-spring-boot3-starter</artifactId> <version>3.5.11</version> </dependency> <!-- LangChain4J DashScope 仅能同时配置一个chatModel和一个stramChatModel,不能同时配置多个,不方便 --> <dependency> <groupId>dev.langchain4j</groupId> <artifactId>langchain4j-community-dashscope-spring-boot-starter</artifactId> <version>1.1.0-beta7</version> </dependency> <dependency> <groupId>dev.langchain4j</groupId> <artifactId>langchain4j</artifactId> <version>1.1.0</version> </dependency> <dependency> <groupId>dev.langchain4j</groupId> <artifactId>langchain4j-mcp</artifactId> <version>1.1.0-beta7</version> </dependency> <!-- flux流式输出 --> <dependency> <groupId>dev.langchain4j</groupId> <artifactId>langchain4j-reactor</artifactId> <version>1.1.0-beta7</version> </dependency> <!-- @AiService注解--> <dependency> <groupId>dev.langchain4j</groupId> <artifactId>langchain4j-spring-boot-starter</artifactId> <version>1.1.0-beta7</version> </dependency> <!-- 支持结构化输出 --> <dependency> <groupId>com.github.victools</groupId> <artifactId>jsonschema-generator</artifactId> <version>4.38.0</version> </dependency> <!-- 支持文件会话记忆持久化的序列化 --> <dependency> <groupId>com.esotericsoftware</groupId> <artifactId>kryo</artifactId> <version>5.6.2</version> </dependency> <!-- pg vector存储 --> <dependency> <groupId>dev.langchain4j</groupId> <artifactId>langchain4j-pgvector</artifactId> <version>1.1.0-beta7</version> </dependency> <!-- jsoup HTML 解析库 --> <dependency> <groupId>org.jsoup</groupId> <artifactId>jsoup</artifactId> <version>1.19.1</version> </dependency> <!-- PDF 生成库 --> <!-- https://mvnrepository.com/artifact/com.itextpdf/itext-core --> <dependency> <groupId>com.itextpdf</groupId> <artifactId>itext-core</artifactId> <version>9.1.0</version> <type>pom</type> </dependency> <!-- https://mvnrepository.com/artifact/com.itextpdf/font-asian --> <dependency> <groupId>com.itextpdf</groupId> <artifactId>font-asian</artifactId> <version>9.1.0</version> <scope>test</scope> </dependency> <dependency> <groupId>cn.hutool</groupId> <artifactId>hutool-all</artifactId> <version>5.8.37</version> </dependency> <dependency> <groupId>com.github.xiaoymin</groupId> <artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId> <version>4.4.0</version> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.36</version> <optional>true</optional> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency> </dependencies>

if i dont't use langchain4j-community-dashscope-spring-boot-starter instead of using langchain4j-community-dashscope,Manually configure the model,Just use AiServices.builder() ,then will "chatModel not be null"

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions