-
Notifications
You must be signed in to change notification settings - Fork 280
fix(767): 支持设置生成选项传递给模型以便跟踪 #775
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hangweizhang
wants to merge
1
commit into
agentscope-ai:main
Choose a base branch
from
hangweizhang:fix-767
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+58
−6
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -36,6 +36,7 @@ | |||||||||
| import io.agentscope.core.message.ToolUseBlock; | ||||||||||
| import io.agentscope.core.model.ChatResponse; | ||||||||||
| import io.agentscope.core.model.ChatUsage; | ||||||||||
| import io.agentscope.core.model.GenerateOptions; | ||||||||||
| import io.agentscope.core.tool.Toolkit; | ||||||||||
| import io.agentscope.core.util.JsonUtils; | ||||||||||
| import java.time.Duration; | ||||||||||
|
|
@@ -101,6 +102,34 @@ void testInitialization() { | |||||||||
| assertTrue(agent.getMemory().getMessages().isEmpty(), "Memory should be empty initially"); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| @Test | ||||||||||
| @DisplayName("Should pass generateOptions (temperature, topP, maxTokens) to model for tracing") | ||||||||||
| void testGenerateOptionsPassedToModel() { | ||||||||||
| GenerateOptions options = | ||||||||||
| GenerateOptions.builder().temperature(0.7).topP(0.9).maxTokens(1000).build(); | ||||||||||
|
|
||||||||||
| ReActAgent agentWithOptions = | ||||||||||
| ReActAgent.builder() | ||||||||||
| .name(TestConstants.TEST_REACT_AGENT_NAME) | ||||||||||
| .sysPrompt(TestConstants.DEFAULT_SYS_PROMPT) | ||||||||||
| .model(mockModel) | ||||||||||
| .toolkit(mockToolkit) | ||||||||||
| .memory(memory) | ||||||||||
| .generateOptions(options) | ||||||||||
| .build(); | ||||||||||
|
|
||||||||||
| Msg userMsg = TestUtils.createUserMessage("User", TestConstants.TEST_USER_INPUT); | ||||||||||
| agentWithOptions | ||||||||||
| .call(userMsg) | ||||||||||
| .block(Duration.ofMillis(TestConstants.DEFAULT_TEST_TIMEOUT_MS)); | ||||||||||
|
|
||||||||||
| GenerateOptions lastOptions = mockModel.getLastOptions(); | ||||||||||
| assertNotNull(lastOptions, "Model should receive GenerateOptions"); | ||||||||||
| assertEquals(0.7, lastOptions.getTemperature(), "Temperature should be passed to model"); | ||||||||||
| assertEquals(0.9, lastOptions.getTopP(), "TopP should be passed to model"); | ||||||||||
|
Comment on lines
+128
to
+129
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 在比较浮点数时,使用一个容差(delta)是最佳实践,可以避免因精度问题导致的测试失败。虽然在这里使用字面量比较可能不会出问题,但使用带 delta 的
Suggested change
|
||||||||||
| assertEquals(1000, lastOptions.getMaxTokens(), "MaxTokens should be passed to model"); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| @Test | ||||||||||
| @DisplayName("Should generate simple text response") | ||||||||||
| void testSimpleReply() { | ||||||||||
|
|
||||||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
当前的实现虽然功能正确,但使用三元运算符使代码略显紧凑,可读性稍差。通过提前处理
modelExecutionConfig == null的情况,可以使逻辑更清晰:如果没有特定于 agent 的执行配置,就直接使用generateOptions;否则,将 agent 的配置合并到基础选项之上。