Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ public ChatClient buildOrUpdateDynamicChatClient(DynamicModelEntity model) {
chatOptionsBuilder.topP(model.getTopP());
}

chatOptionsBuilder.internalToolExecutionEnabled(false);

OpenAiChatOptions chatOptions = chatOptionsBuilder.build();
if (headers != null) {
chatOptions.setHttpHeaders(headers);
Expand All @@ -235,7 +237,6 @@ public ChatClient buildOrUpdateDynamicChatClient(DynamicModelEntity model) {
ChatClient client = ChatClient.builder(openAiChatModel)
// .defaultAdvisors(MessageChatMemoryAdvisor.builder(agentMemory).build())
.defaultAdvisors(new SimpleLoggerAdvisor())
.defaultOptions(OpenAiChatOptions.builder().internalToolExecutionEnabled(false).build())
.build();
clients.put(modelId, client);
log.info("Build or update dynamic chat client for model: {}", modelName);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright 2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.cloud.ai.example.manus.llm;

import com.alibaba.cloud.ai.example.manus.config.ManusProperties;
import com.alibaba.cloud.ai.example.manus.dynamic.model.entity.DynamicModelEntity;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.ai.chat.client.ChatClient;

import java.util.HashMap;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.assertNotNull;

@ExtendWith(MockitoExtension.class)
public class DynamicHeaderPreservationTest {

@Mock
private ManusProperties manusProperties;

private LlmService llmService;

@BeforeEach
void setUp() {
llmService = new LlmService();
}

@Test
void testDynamicChatClientCreationWithHeaders() {
DynamicModelEntity model = new DynamicModelEntity();
model.setId(1L);
model.setBaseUrl("https://test.example.com");
model.setApiKey("test-api-key");
model.setModelName("test-model");

Map<String, String> headers = new HashMap<>();
headers.put("Custom-Header", "test-value");
headers.put("Authorization", "Bearer test-token");
model.setHeaders(headers);

ChatClient chatClient = llmService.buildOrUpdateDynamicChatClient(model);

assertNotNull(chatClient, "ChatClient should be created successfully");

}

@Test
void testDynamicChatClientCreationWithoutHeaders() {
DynamicModelEntity model = new DynamicModelEntity();
model.setId(2L);
model.setBaseUrl("https://test.example.com");
model.setApiKey("test-api-key");
model.setModelName("test-model");

ChatClient chatClient = llmService.buildOrUpdateDynamicChatClient(model);
assertNotNull(chatClient, "ChatClient should be created successfully even without headers");
}

}
Loading