### Project Setup and Environment Initialization Source: https://github.com/petercat-ai/whiskerrag_toolkit/blob/main/README.md Guides through cloning the project, setting up a Python virtual environment using Poetry, and installing project dependencies. ```bash git clone https://github.com/petercat-ai/whiskerrag_toolkit.git cd whiskerrag_toolkit # Configure Poetry for virtual environment poetry config virtualenvs.create true poetry config virtualenvs.in-project true # Use a specific Python version poetry env use python3.10 # Activate the virtual environment source .venv/bin/activate # Install project dependencies poetry install # Install pre-commit hooks pre-commit install ``` -------------------------------- ### Run Example Script Source: https://github.com/petercat-ai/whiskerrag_toolkit/blob/main/docs/json_parser_enhancement.md Command to run the example script that demonstrates the new JSON parser functionality. ```bash python examples/json_parser_example.py ``` -------------------------------- ### Install WhiskerRAG Source: https://github.com/petercat-ai/whiskerrag_toolkit/blob/main/README.md Installs the whiskerrag package using pip. This is the primary method for adding the toolkit to your Python environment. ```bash pip install whiskerrag ``` -------------------------------- ### JSON Parsing Error Handling Examples Source: https://github.com/petercat-ai/whiskerrag_toolkit/blob/main/docs/json_parser_enhancement.md Shows examples of how the enhanced JSON parser handles errors, including invalid JSON syntax and attempts to parse primitive JSON types. ```python # Invalid JSON try: await parser.parse(knowledge, Text(content='{"invalid": json}', metadata={})) except ValueError as e: print(f"Error: {e}") # "Invalid JSON content provided for splitting: ..." # Primitive JSON (not supported) try: await parser.parse(knowledge, Text(content="42", metadata={})) except ValueError as e: print(f"Error: {e}") # "JSON content must be a dictionary or array." ``` -------------------------------- ### Dictionary Format JSON Parsing Example Source: https://github.com/petercat-ai/whiskerrag_toolkit/blob/main/docs/json_parser_enhancement.md Demonstrates parsing of a dictionary-formatted JSON string using the enhanced parser. This functionality is backward compatible with previous versions. ```python json_content = """ { "user": { "name": "John Doe", "age": 30, "email": "john.doe@example.com" } } """ # This works as before result = await parser.parse(knowledge, Text(content=json_content, metadata={})) ``` -------------------------------- ### Array Format JSON Parsing Example Source: https://github.com/petercat-ai/whiskerrag_toolkit/blob/main/docs/json_parser_enhancement.md Illustrates parsing of an array-formatted JSON string with the enhanced parser. The array format is now supported and converted for processing. ```python json_content = """ [ {"id": 1, "name": "Product A"}, {"id": 2, "name": "Product B"}, {"id": 3, "name": "Product C"} ] """ # This now works with the enhanced parser result = await parser.parse(knowledge, Text(content=json_content, metadata={})) ``` -------------------------------- ### Running Tests with Poetry Source: https://github.com/petercat-ai/whiskerrag_toolkit/blob/main/README.md Details how to execute tests using Poetry, including running all tests or specific test files. ```bash # Run all tests poetry run pytest # Run tests for a specific file poetry run pytest tests/test_loader.py ``` -------------------------------- ### Contribution Workflow Source: https://github.com/petercat-ai/whiskerrag_toolkit/blob/main/README.md Outlines the recommended workflow for contributing to the project, including branching, committing, pull requests, and code reviews. ```bash # Create a new branch make branch name=feature/amazing-feature # Commit changes git commit -m 'Add some amazing feature' # Push to the branch git push origin feature/amazing-feature # Open a Pull Request ``` -------------------------------- ### Poetry Common Commands Source: https://github.com/petercat-ai/whiskerrag_toolkit/blob/main/README.md Provides a reference for frequently used Poetry commands for managing project dependencies and environments. ```bash # Install dependencies poetry install # Add a new dependency poetry add package_name # Add a new dev dependency poetry add --dev package_name # Update dependencies poetry update # View environment information poetry env info # List installed packages poetry show ``` -------------------------------- ### WhiskerRAG Client API Usage Source: https://github.com/petercat-ai/whiskerrag_toolkit/blob/main/README.md Demonstrates how to use the APIClient from whiskerrag_client to interact with RAG system services. It covers retrieving knowledge chunks, space content, chunk lists, and task details. ```python from whiskerrag_client import APIClient from whiskerrag_client.schema import RetrievalByKnowledgeRequest, RetrievalBySpaceRequest api_client = APIClient( base_url="https://api.example.com", token="your_token_here" ) # Retrieve knowledge chunks knowledge_chunks = await api_client.retrieval.retrieve_knowledge_content( RetrievalByKnowledgeRequest(knowledge_id="your knowledge uuid here") ) # Retrieve space content space_chunks = await api_client.retrieval.retrieve_space_content( RetrievalBySpaceRequest(space_id="your space id here ") ) # Get a list of chunks chunk_list = await api_client.chunk.get_chunk_list( page=1, size=10, filters={"status": "active"} ) # Get a list of tasks task_list = await api_client.task.get_task_list( page=1, size=10 ) # Get task details task_detail = await api_client.task.get_task_detail("task_id_here") ``` -------------------------------- ### Run Unit Tests Source: https://github.com/petercat-ai/whiskerrag_toolkit/blob/main/docs/json_parser_enhancement.md Command to execute the comprehensive unit tests for the JSON parser enhancement, covering various formats and error conditions. ```bash python -m pytest tests/whiskerrag_utils/parser/test_json_splitter.py -v ``` -------------------------------- ### WhiskerRAG Types Usage Source: https://github.com/petercat-ai/whiskerrag_toolkit/blob/main/README.md Shows how to import and use type hints and interfaces from the whiskerrag_types module for developing RAG systems. ```python from whiskerrag_types.interface import DBPluginInterface, TaskEngineInterface from whiskerrag_types.model import Knowledge, Task, Tenant, PageParams, PageResponse ``` -------------------------------- ### Enhanced JSON Content Parsing Function Source: https://github.com/petercat-ai/whiskerrag_toolkit/blob/main/docs/json_parser_enhancement.md A new helper function `parse_json_content` is introduced to parse JSON content with improved error handling and support for both dictionary and array formats. It returns a dictionary or list, raising a ValueError for invalid JSON or unsupported types. ```python def parse_json_content(content: str) -> Union[Dict[str, Any], List[Any]]: """ Parse JSON content with better compatibility. Args: content: JSON string content Returns: Parsed JSON object (dict or list) Raises: ValueError: If content is not valid JSON or is not a dict/list """ # Implementation details would follow here ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.