feat: add JSON mode and reasoning_effort support#197
Closed
kolmogorov-quyet wants to merge 2 commits intoNevaMind-AI:mainfrom
Closed
feat: add JSON mode and reasoning_effort support#197kolmogorov-quyet wants to merge 2 commits intoNevaMind-AI:mainfrom
kolmogorov-quyet wants to merge 2 commits intoNevaMind-AI:mainfrom
Conversation
Add two new features to improve LLM output quality and control:
1. JSON Mode (response_format="json_object"):
- Add response_format parameter to summarize() method
- Enable JSON mode for LLM rankers in retrieve.py:
- _llm_rank_categories
- _llm_rank_items
- _llm_rank_resources
- Enable JSON mode for _preprocess_conversation in memorize.py
- Support in openai_sdk.py, wrapper.py, and http_client.py
2. Reasoning Effort (reasoning_effort="low"|"medium"|"high"):
- Add reasoning_effort field to LLMConfig in settings.py
- Default value is "high" for better reasoning quality
- Pass through openai_sdk.py to chat.completions.create()
- Wire up in service.py when creating LLM clients
These features help ensure consistent JSON output from LLMs and
enable control over reasoning depth for compatible models.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Contributor
|
Hi kolmogorov-quyet, thanks for the contribution! One small suggestion: it might be better to make these arguments optional, since not all models support them. As it stands, passing them unconditionally can cause errors for some models, for example: |
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.
Summary
Add two new features to improve LLM output quality and control:
1. JSON Mode (
response_format="json_object")response_formatparameter tosummarize()methodretrieve.py:_llm_rank_categories_llm_rank_items_llm_rank_resources_preprocess_conversationinmemorize.pyopenai_sdk.py,wrapper.py, andhttp_client.py2. Reasoning Effort (
reasoning_effort)reasoning_effortfield toLLMConfiginsettings.py"low","medium","high", orNone"high"for better reasoning qualityopenai_sdk.pytochat.completions.create()service.pywhen creating LLM clientsWhy these changes?
JSON Mode: Ensures consistent JSON output from LLMs, reducing parsing errors like "No JSON object found"
Reasoning Effort: Enables control over reasoning depth for compatible models (OpenAI o-series, Cerebras, etc.)