textured 0.1.0 copy "textured: ^0.1.0" to clipboard
textured: ^0.1.0 copied to clipboard

A Dart package to use LLMs to parse text into pre-defined data structures.

example/README.md

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 #

  1. 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
    
  2. 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:

  1. Enter your text to parse
  2. Press Ctrl+D (Linux/Mac) or Ctrl+Z (Windows) when finished
  3. 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 #

  1. Use appropriate models: Larger models (e.g., mistral) may be more accurate but slower
  2. Optimize temperature: Lower values (0.1-0.3) for more consistent extraction
  3. Schema design: Well-defined schemas with examples improve accuracy
  4. 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
0
likes
140
points
153
downloads

Publisher

verified publisherbandgap.ai

Weekly Downloads

A Dart package to use LLMs to parse text into pre-defined data structures.

Homepage
Repository (GitLab)
View/report issues

Topics

#llm #text-parsing #json-schema

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

dotenv, googleapis_auth, http

More

Packages that depend on textured