fix: support both 'llm' and 'chat_llm' config keys; handle dict core_entities#746
Open
octo-patch wants to merge 1 commit intoOpenSPG:masterfrom
Open
Conversation
…re_entities (fixes OpenSPG#731) - In project.py (create_project and update_project), fall back from 'llm' to 'chat_llm' when reading LLM config so that configs using either key (e.g. 2wiki kag_config_knowledge_unit.yaml uses 'llm') work correctly. - In knowledge_unit_extractor.py, handle core_entities as either a dict (returned by the English-language LLM prompt) or a comma-separated string (returned by the Chinese-language LLM prompt and for triple-derived units), preserving the entity type when available. Co-Authored-By: Octopus <liyuan851277048@icloud.com>
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.
Fixes #731
Problem
When creating a project using the 2wiki benchmark configs (e.g.
kag_config_knowledge_unit.yaml), which define the LLM config under thellmtop-level key,project.pywas readingchat_llm— a different key used by other configs such as the medicine example. This caused the LLM config lookup to silently return an empty dict, leading to downstream errors (includingAttributeError: 'TaggedScalar' object has no attribute 'openapi_types').Additionally, the English-language knowledge unit prompt returns
Core Entitiesas a dict ({"entity": "type", ...}), butknowledge_unit_extractor.pywas always treatingcore_entitiesas a comma-separated string, causing aTypeErrorwhen the English prompt was used.Solution
knext/command/sub_command/project.py— In bothcreate_projectandupdate_project, read the LLM config by checkingllmfirst and falling back tochat_llm. This matches the existing logic inkag/common/config.py::get_default_chat_llm_config()and is backward-compatible with configs that use either key.kag/builder/component/extractor/knowledge_unit_extractor.py— Handlecore_entitiesas either adict(English-language LLM output, where entity types are provided) or a comma-separatedstr(Chinese-language LLM output and triple-derived units). When it is a dict, the entity type value from the LLM is preserved instead of defaulting everything to"Others".Testing
Verified the diff matches the fix described by the maintainer in the issue thread. The changes are backward-compatible: configs using
chat_llmcontinue to work, and both Chinese and English prompt outputs forcore_entitiesare correctly handled.