fix: implement dynamic top_p parameter adjustment for LLM API calls#104
Merged
kevin-mindverse merged 1 commit intomindverse:masterfrom Apr 7, 2025
Merged
Conversation
- Add _top_p_adjusted flag to track parameter adjustments
- Implement _fix_top_p_param to adjust invalid top_p values
- Enhance _call_llm_with_retry with parameter adjustment retry mechanism
- Apply consistent implementation across all generator classes
- Improve error logging for API error debugging
Contributor
|
@yingapple plz take a look at this. |
kevin-mindverse
approved these changes
Apr 7, 2025
Collaborator
|
Love the work! |
Collaborator
|
Hi @Airmomo 👋, Thank you so much for your contribution to this PR! Your work is really appreciated. If you haven’t already, feel free to join our Discord community here: Discord Invite Link — it's a great place to connect with our team and other contributors, share ideas, and stay up to date with the project! Also, feel free to add me directly on WeChat (id: Neon_MoonS) if you’d like to chat more or have any questions! Looking forward to connecting! 😊 |
Heterohabilis
pushed a commit
to Heterohabilis/Second-Me
that referenced
this pull request
May 29, 2025
…indverse#104) - Add _top_p_adjusted flag to track parameter adjustments - Implement _fix_top_p_param to adjust invalid top_p values - Enhance _call_llm_with_retry with parameter adjustment retry mechanism - Apply consistent implementation across all generator classes - Improve error logging for API error debugging
EOMZON
pushed a commit
to EOMZON/Second-Me
that referenced
this pull request
Feb 1, 2026
…indverse#104) - Add _top_p_adjusted flag to track parameter adjustments - Implement _fix_top_p_param to adjust invalid top_p values - Enhance _call_llm_with_retry with parameter adjustment retry mechanism - Apply consistent implementation across all generator classes - Improve error logging for API error debugging
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Issue
When I request LLM API with
top_p=0, some model providers (such as DeepSeek)reject the request with a 400 error, indicating that the valid range fortop_pis (0, 1.0]. This causes API calls to fail in various generators(L1), includingL1Generator,TopicsGenerator,ShadeGenerator, andStatusBioGenerator.Cause analysis
Fix
Currently, only the
top_pparameter for error handling and dynamic adjustment. I think: If other parameter error issues arise in the future, error handling can be added on this basis.L1GeneratorTopicsGeneratorShadeGeneratorShadeMergerStatusBioGeneratorEach generator has implemented the same logic, which may be a bit redundant, but in order not to compromise the independence of each generator, I think I should do it this way.
Improvements
Increased Compatibility:
Robust Error Handling:
Automatic Recovery:
Consistent Implementation:
Share my thinking
At first, I wanted to simply add a configuration item in
.envto uniformly settop_pandtemperature, but after reviewing the code of the generator, I realized that there may be different parameter sets for each individual generator in the future development of the project. Therefore, it is not necessary to unify the parameter configuration here.In addition, considering the concept of the project, I believe that the generated results should be as close to the data itself as possible. Therefore, it is not necessary to treat it as a customized configuration item here. I only need to dynamically update
top_pto a value as close to 0 as possible, which will achieve a very close approximation; andtemperatureis a value that almost all mainstream models support setting to0, so I will not make dynamic adjustments to it for now.