fix: 解决ChatModel多Bean冲突和JVM内存不足问题
- AppConfig中用@Qualifier指定anthropicChatModel - spring-boot-maven-plugin配置-Xmx512m限制堆内存 - application.yml关闭web-application-type为none Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -89,6 +89,9 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<jvmArguments>-Xmx512m -Xms256m</jvmArguments>
|
||||||
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import com.claudecode.tool.ToolContext;
|
|||||||
import com.claudecode.tool.ToolRegistry;
|
import com.claudecode.tool.ToolRegistry;
|
||||||
import com.claudecode.tool.impl.*;
|
import com.claudecode.tool.impl.*;
|
||||||
import org.springframework.ai.chat.model.ChatModel;
|
import org.springframework.ai.chat.model.ChatModel;
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
@@ -67,7 +68,7 @@ public class AppConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public AgentLoop agentLoop(ChatModel chatModel, ToolRegistry toolRegistry,
|
public AgentLoop agentLoop(@Qualifier("anthropicChatModel") ChatModel chatModel, ToolRegistry toolRegistry,
|
||||||
ToolContext toolContext, String systemPrompt) {
|
ToolContext toolContext, String systemPrompt) {
|
||||||
return new AgentLoop(chatModel, toolRegistry, toolContext, systemPrompt);
|
return new AgentLoop(chatModel, toolRegistry, toolContext, systemPrompt);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,9 +3,10 @@ spring:
|
|||||||
ai:
|
ai:
|
||||||
anthropic:
|
anthropic:
|
||||||
api-key: ${ANTHROPIC_API_KEY:}
|
api-key: ${ANTHROPIC_API_KEY:}
|
||||||
|
base-url: ${ANTHROPIC_BASE_URL:https://open.bigmodel.cn/api/anthropic}
|
||||||
chat:
|
chat:
|
||||||
options:
|
options:
|
||||||
model: ${AI_MODEL:claude-sonnet-4-20250514}
|
model: ${AI_MODEL:claude-sonnet-4}
|
||||||
max-tokens: ${AI_MAX_TOKENS:8096}
|
max-tokens: ${AI_MAX_TOKENS:8096}
|
||||||
temperature: 0.7
|
temperature: 0.7
|
||||||
# 备选:兼容 OpenAI 格式的 API(如自建代理)
|
# 备选:兼容 OpenAI 格式的 API(如自建代理)
|
||||||
|
|||||||
Reference in New Issue
Block a user