Fix entity types configuration to support JSON list parsing
- Add JSON parsing for list env vars - Update entity types example format - Add list type support to get_env_value
This commit is contained in:
parent
1a015a7015
commit
c8c59c38b0
3 changed files with 23 additions and 2 deletions
|
|
@ -125,7 +125,7 @@ ENABLE_LLM_CACHE_FOR_EXTRACT=true
|
||||||
SUMMARY_LANGUAGE=English
|
SUMMARY_LANGUAGE=English
|
||||||
|
|
||||||
### Entity types that the LLM will attempt to recognize
|
### Entity types that the LLM will attempt to recognize
|
||||||
# ENTITY_TYPES=["organization", "person", "equiment", "product", "technology", "location", "event", "category"]
|
# ENTITY_TYPES='["Organization", "Person", "Equiment", "Product", "Technology", "Location", "Event", "Category"]'
|
||||||
|
|
||||||
### Chunk size for document splitting, 500~1500 is recommended
|
### Chunk size for document splitting, 500~1500 is recommended
|
||||||
# CHUNK_SIZE=1200
|
# CHUNK_SIZE=1200
|
||||||
|
|
|
||||||
|
|
@ -352,7 +352,7 @@ def parse_args() -> argparse.Namespace:
|
||||||
# Add environment variables that were previously read directly
|
# Add environment variables that were previously read directly
|
||||||
args.cors_origins = get_env_value("CORS_ORIGINS", "*")
|
args.cors_origins = get_env_value("CORS_ORIGINS", "*")
|
||||||
args.summary_language = get_env_value("SUMMARY_LANGUAGE", DEFAULT_SUMMARY_LANGUAGE)
|
args.summary_language = get_env_value("SUMMARY_LANGUAGE", DEFAULT_SUMMARY_LANGUAGE)
|
||||||
args.entity_types = get_env_value("ENTITY_TYPES", DEFAULT_ENTITY_TYPES)
|
args.entity_types = get_env_value("ENTITY_TYPES", DEFAULT_ENTITY_TYPES, list)
|
||||||
args.whitelist_paths = get_env_value("WHITELIST_PATHS", "/health,/api/*")
|
args.whitelist_paths = get_env_value("WHITELIST_PATHS", "/health,/api/*")
|
||||||
|
|
||||||
# For JWT Auth
|
# For JWT Auth
|
||||||
|
|
|
||||||
|
|
@ -82,6 +82,27 @@ def get_env_value(
|
||||||
|
|
||||||
if value_type is bool:
|
if value_type is bool:
|
||||||
return value.lower() in ("true", "1", "yes", "t", "on")
|
return value.lower() in ("true", "1", "yes", "t", "on")
|
||||||
|
|
||||||
|
# Handle list type with JSON parsing
|
||||||
|
if value_type is list:
|
||||||
|
try:
|
||||||
|
import json
|
||||||
|
|
||||||
|
parsed_value = json.loads(value)
|
||||||
|
# Ensure the parsed value is actually a list
|
||||||
|
if isinstance(parsed_value, list):
|
||||||
|
return parsed_value
|
||||||
|
else:
|
||||||
|
logger.warning(
|
||||||
|
f"Environment variable {env_key} is not a valid JSON list, using default"
|
||||||
|
)
|
||||||
|
return default
|
||||||
|
except (json.JSONDecodeError, ValueError) as e:
|
||||||
|
logger.warning(
|
||||||
|
f"Failed to parse {env_key} as JSON list: {e}, using default"
|
||||||
|
)
|
||||||
|
return default
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return value_type(value)
|
return value_type(value)
|
||||||
except (ValueError, TypeError):
|
except (ValueError, TypeError):
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue