Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor api server by split it to smaller files #880

Merged
merged 16 commits into from
Feb 21, 2025

Conversation

danielaskdd
Copy link
Contributor

@danielaskdd danielaskdd commented Feb 19, 2025

Description

Refactor api server by split it to smaller files.

Changes Made

Refactor lightrag_server.py by by split it to smaller files, an put it in ./routes

  • Separate each api categorial to individual file
  • Put all the config handle functions to utils_api.py

Improve document status retrieval with content fallback for legacy storage file compatibility.

  • Added content fallback to content_summary
  • Handled missing fields gracefully

Change progress_lock for document scan from threading.Lock() to asyncio.Lock

  • threading.Lock() is not for async, and does not work with FASTAPI

Respect user-specified log level in set_logger

  • Previously, the set_logger function would always set the log level to DEBUG, overriding any user-specified log level.

Checklist

  • Changes tested locally
  • Code reviewed
  • Documentation updated (if necessary)
  • Unit tests added (if applicable)

Additional Notes

none

- Added 'future' package
- Removed 'networkx' package
- Cleaned up commented sections
- Maintained core dependencies
- Simplified requirements structure
- Added FileResponse for webui root endpoint
- Enabled directory check in StaticFiles mount
- Improved webui static file handling
- Ensured webui directory existence
- Simplified webui access with root endpoint
- Added content fallback to content_summary
- Handled missing fields gracefully
- Made data copy to avoid modification
- Added error logging for missing fields
- Improved code readability and robustness
- Move parse_args and display_splash_screen functions from lightrag_server.py to utils_api.py
- Move OllamaServerInfos class and instance from ollama_api.py to utils_api.py
- Fix refactoring error on pipeline_index_file
- Delete unsed func: scan_directory
- Add type hints of rag for better maintainability
- Refine comments for better understanding
• Add rag param to function call
• Fix argument mismatch error
• Ensure proper pipeline execution
@YanSte
Copy link
Contributor

YanSte commented Feb 20, 2025

Hello, in this refactor. Could you extract Ollama please?
To make it more generic without dependency on Ollama.

Thanks 🙏🏻

@danielaskdd
Copy link
Contributor Author

without dependency on Ollama? I can't get the points. API server just emulates an Ollama model for LightRAG, so chat frontend supporting Ollama API can use LightRAG directly.

@YanSte
Copy link
Contributor

YanSte commented Feb 20, 2025

I mean it is not possible to use the default defined LLM, otherwise if it is not defined use ollama?

@danielaskdd danielaskdd marked this pull request as ready for review February 21, 2025 04:15
Previously, the set_logger function would always set the log level to DEBUG, overriding any user-specified log level.
Copy link
Contributor

@ParisNeo ParisNeo left a comment

Choose a reason for hiding this comment

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

Nice step forward

return default


def display_splash_screen(args: argparse.Namespace) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi.
Where did you move this part?

Copy link
Contributor

Choose a reason for hiding this comment

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

OK found it


# database packages
networkx
future
Copy link
Contributor

Choose a reason for hiding this comment

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

Approove

@@ -57,11 +57,17 @@ async def __aexit__(self, exc_type, exc, tb):
logging.getLogger("httpx").setLevel(logging.WARNING)


def set_logger(log_file: str):
logger.setLevel(logging.DEBUG)
def set_logger(log_file: str, level: int = logging.DEBUG):
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice

for k, v in self._data.items()
if v["status"] == status.value
}
result = {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Cool

@@ -0,0 +1,554 @@
"""
Utility functions for the LightRAG API.
Copy link
Contributor

Choose a reason for hiding this comment

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

OK found it!
Nice

@danielaskdd
Copy link
Contributor Author

danielaskdd commented Feb 21, 2025

Sync modifications of lightrag_server.py from main branch @ParisNeo @LarFii

@LarFii LarFii merged commit b1a9a55 into HKUDS:main Feb 21, 2025
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants