textured 0.1.0
textured: ^0.1.0 copied to clipboard
A Dart package to use LLMs to parse text into pre-defined data structures.
Textured CLI #
A simple command-line interface for the textured package that demonstrates LLM-powered text parsing with JSON schema validation.
Features #
- 📋 Schema Loading: Loads JSON Schema files to define output structure
- 🤖 LLM Integration: Uses Ollama for natural language processing
- ✅ Schema Validation: Validates LLM output against the provided schema
- 📊 Rich Output: Displays extracted data, validation results, and performance metrics
- 🎯 Error Handling: Comprehensive error messages and debugging support
Prerequisites #
-
Ollama: Install and run Ollama locally
# Install Ollama (visit https://ollama.ai for instructions) # Start Ollama server ollama serve # Pull a model (e.g., llama2) ollama pull llama2 -
Dart SDK: Make sure you have Dart installed (>=3.0.0)
Usage #
Basic Usage #
dart run example/textured_cli.dart <schema_file> [model]
Arguments #
schema_file: Path to a JSON Schema file (required)model: Ollama model name (optional, default: llama2)
Examples #
Using the included tree schema:
dart run example/textured_cli.dart test/data/tree_metadata_schema.json
Using a different model:
dart run example/textured_cli.dart test/data/tree_metadata_schema.json mistral
With piped input:
echo "A beautiful cherry blossom tree in Tokyo, Japan" | dart run example/textured_cli.dart test/data/tree_metadata_schema.json
Interactive Mode #
When run without piped input, the CLI enters interactive mode:
- Enter your text to parse
- Press Ctrl+D (Linux/Mac) or Ctrl+Z (Windows) when finished
- The tool will process your input and display results
Output Format #
The CLI displays:
- ✅ Success/Failure Status: Whether the LLM call succeeded
- 🔍 Validation Results: Schema validation status and any errors
- 📋 Extracted Data: The structured JSON output
- 📈 Performance Metrics: Response time, token counts, model info
Example Session #
🌟 Textured CLI - LLM Text Parser
═══════════════════════════════════
Schema: test/data/tree_metadata_schema.json
Model: llama2
📋 Loading schema...
✓ Loaded: Tree Metadata Schema
✓ Properties: 32
✓ Required fields: 32
🤖 Configuring LLM...
⚡ Testing Ollama connection...
✓ Connection successful
📝 Enter your text to parse:
(Type your text and press Ctrl+D when finished)
> This is a large oak tree in Central Park, New York.
📤 Processing text (47 characters)...
🎯 Generating LLM prompt...
✓ Prompt generated (5344 characters)
🚀 Calling LLM...
✓ Response received (8181ms)
📊 RESULTS
═══════════════════════════════════
✅ Success!
✅ Schema Validation: PASSED
📋 Extracted Data:
━━━━━━━━━━━━━━━━━━━
{
"tree_id": null,
"name": "Large Oak Tree",
"city": "New York",
"state": "NY",
"is_alive": true,
...
}
📈 Metadata:
━━━━━━━━━━━━━━━━━━━
• Model: llama2
• Response time: 8175ms
• Content length: 775 characters
🎉 Processing complete!
Error Handling #
The CLI provides helpful error messages for common issues:
- Missing Ollama: Instructions to start Ollama server
- Invalid Schema: JSON format validation errors
- Missing Files: File not found errors
- Model Issues: Model availability problems
Debugging #
Add --debug flag for detailed error information:
dart run example/textured_cli.dart test/data/tree_metadata_schema.json --debug
Creating Custom Schemas #
You can use any JSON Schema Draft 7 file. The schema should define:
- Required properties
- Property types and constraints
- Examples (optional but helpful for LLM accuracy)
See test/data/tree_metadata_schema.json for a comprehensive example.
Performance Tips #
- Use appropriate models: Larger models (e.g., mistral) may be more accurate but slower
- Optimize temperature: Lower values (0.1-0.3) for more consistent extraction
- Schema design: Well-defined schemas with examples improve accuracy
- Hardware: Ensure sufficient RAM for your chosen model
Troubleshooting #
"Connection failed" #
- Check if Ollama is running:
ollama serve - Verify the model is available:
ollama list
"Model not found" #
- Pull the model:
ollama pull <model_name> - Check available models:
ollama list
"Schema validation failed" #
- Review the schema file for JSON syntax errors
- Ensure the schema follows JSON Schema Draft 7 format
Poor extraction accuracy #
- Try a larger model (e.g., mistral, codellama)
- Add examples to your schema
- Lower the temperature parameter
- Provide clearer, more structured input text