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