Skip to content

fix(config): enhance config path handling and add project root validation#262

Merged
imbajin merged 36 commits intoapache:mainfrom
weijinglin:main
Jun 4, 2025
Merged

fix(config): enhance config path handling and add project root validation#262
imbajin merged 36 commits intoapache:mainfrom
weijinglin:main

Conversation

@weijinglin
Copy link
Collaborator

@weijinglin weijinglin commented May 28, 2025

Add Path Checking Logic for Configuration Files

Description

This PR introduces path validation logic to ensure the application is running from the correct project root directory. It adds a new utility function to determine the project root and implements checks to prevent configuration loading from incorrect working directories.

Changes

  • Added new utility function get_project_root() in hugegraph_llm/utils/anchor.py to reliably determine the project root directory
  • Updated configuration file path in base_prompt_config.py to use the correct path structure
  • Implemented working directory validation in BasePromptConfig.ensure_yaml_file_exists()
  • Added graceful error handling with informative messages when running from incorrect directory

Technical Details

  • The path checking logic verifies if the current working directory matches the project root
  • If running from incorrect directory, the application will exit with a clear error message
  • Configuration file path has been updated to use the correct structure under src/hugegraph_llm/resources/demo

Testing

  • Verify application runs correctly from project root
  • Confirm appropriate error message when running from incorrect directory
  • Test configuration file loading with the new path structure

Impact

This change improves the reliability of the application by ensuring configuration files are loaded from the correct location and provides better error handling for incorrect usage.

@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label May 28, 2025
@github-actions github-actions bot added the llm label May 28, 2025
@dosubot dosubot bot added the enhancement New feature or request label May 28, 2025
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels May 31, 2025
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels May 31, 2025
@imbajin imbajin requested a review from Copilot June 3, 2025 12:33
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces project-root detection and enforces correct working directory for loading configuration files, updates associated paths, and enhances deployment documentation along with Dockerfile adjustments.

  • Added get_project_root() utility to identify the repo root
  • Enforced working-directory validation in BasePromptConfig.ensure_yaml_file_exists()
  • Updated README and Dockerfiles for Docker-based deployment and build changes

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
utils/anchor.py Added get_project_root() for locating project root directories
config/models/base_prompt_config.py Implemented CWD check and exit on invalid directory
README.md Added Docker deployment instructions
docker/Dockerfile.nk Included jieba package in Nuitka build
docker/Dockerfile.llm Swapped Poetry for uv-based venv setup and adjusted WORKDIR paths
Comments suppressed due to low confidence (1)

hugegraph-llm/src/hugegraph_llm/config/models/base_prompt_config.py:53

  • The variable yaml_file_path is not defined within ensure_yaml_file_exists(). Introduce a definition (e.g., using get_project_root() along with F_NAME) before checking its existence.
if os.path.exists(yaml_file_path):

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Jun 3, 2025
Copy link
Member

@imbajin imbajin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merge it first, should test the docker image soon

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jun 4, 2025
@imbajin imbajin merged commit cd6fd33 into apache:main Jun 4, 2025
10 checks passed
@try-agaaain
Copy link

I followed the instructions from https://hugegraph.apache.org/cn/docs/quickstart/hugegraph-ai/ and ran the following command:

cd ./hugegraph-llm/src
python3 -m hugegraph_llm.demo.rag_demo.app

However, an error was reported stating that the program should not be run from the src directory:

(hugegraph) try-agaaain@XiaoXin16Pro21:/workspace/LLM-Agent/incubator-hugegraph-ai/hugegraph-llm/src$ python -m hugegraph_llm.demo.rag_demo.app
[06/08/25 08:41:17] ERROR    llm: Current working directory is not the project root.   base_prompt_config.py:54
                             Please run this script from the project root directory:                           
                             /workspace/LLM-Agent/incubator-hugegraph-ai/hugegraph-llm                         
                             Current directory:                                                                
                             /workspace/LLM-Agent/incubator-hugegraph-ai/hugegraph-llm                         
                             /src                                                                              

How should I run the program correctly?

@imbajin
Copy link
Member

imbajin commented Jun 9, 2025

I followed the instructions from hugegraph.apache.org/cn/docs/quickstart/hugegraph-ai and ran the following command:

cd ./hugegraph-llm/src
python3 -m hugegraph_llm.demo.rag_demo.app

However, an error was reported stating that the program should not be run from the src directory:

(hugegraph) try-agaaain@XiaoXin16Pro21:/workspace/LLM-Agent/incubator-hugegraph-ai/hugegraph-llm/src$ python -m hugegraph_llm.demo.rag_demo.app
[06/08/25 08:41:17] ERROR    llm: Current working directory is not the project root.   base_prompt_config.py:54
                             Please run this script from the project root directory:                           
                             /workspace/LLM-Agent/incubator-hugegraph-ai/hugegraph-llm                         
                             Current directory:                                                                
                             /workspace/LLM-Agent/incubator-hugegraph-ai/hugegraph-llm                         
                             /src                                                                              

How should I run the program correctly?

@try-agaaain Apologize, the website is outdated & we'll update/sync it soon

Please refer here to get the latest instruction & could also try docker images for it

https://github.com/apache/incubator-hugegraph-ai/blob/main/hugegraph-llm/README.md

@try-agaaain
Copy link

I followed the instructions from hugegraph.apache.org/cn/docs/quickstart/hugegraph-ai and ran the following command:

cd ./hugegraph-llm/src
python3 -m hugegraph_llm.demo.rag_demo.app

However, an error was reported stating that the program should not be run from the src directory:

(hugegraph) try-agaaain@XiaoXin16Pro21:/workspace/LLM-Agent/incubator-hugegraph-ai/hugegraph-llm/src$ python -m hugegraph_llm.demo.rag_demo.app
[06/08/25 08:41:17] ERROR    llm: Current working directory is not the project root.   base_prompt_config.py:54
                             Please run this script from the project root directory:                           
                             /workspace/LLM-Agent/incubator-hugegraph-ai/hugegraph-llm                         
                             Current directory:                                                                
                             /workspace/LLM-Agent/incubator-hugegraph-ai/hugegraph-llm                         
                             /src                                                                              

How should I run the program correctly?

@try-agaaain Apologize, the website is outdated & we'll update/sync it soon

Please refer here to get the latest instruction & could also try docker images for it

https://github.com/apache/incubator-hugegraph-ai/blob/main/hugegraph-llm/README.md

Thanks a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request lgtm This PR has been approved by a maintainer llm size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants