Secretary 🚀
Secretary is a Rust library that translates natural language into structured data using large language models (LLMs). It provides a simple, type-safe way to extract structured information from unstructured text.
Features
- 🔍 Schema-Based Extraction: Define your data structure using Rust structs and let LLMs extract matching data
- 🔄 Context-Aware Conversations: Maintain conversation state for multi-turn interactions
- 🧠 Progressive Data Building: Incrementally build complex data structures through conversational interactions
- 📋 Declarative Schema Annotations: Document your schemas with field descriptions that guide the LLM
- 🔌 Extensible LLM Support: Currently supports OpenAI API with more providers planned
Quick Start
Or,
[]
= "0.1.12"
Basic Example
use ;
use ;
// Define your output schema
How It Works
- Define Your Schema: Create a Rust struct that represents the data structure you want to extract
- Create a Task: Initialize a task with your schema and any additional instructions
- Process Text: Send natural language input to an LLM through the Secretary API
- Get Structured Data: Receive a JSON result that matches your defined schema
Advanced Features
Multi-Turn Conversations
Secretary supports contextual, multi-turn conversations that build data progressively:
// See the examples directory for complete multi-turn conversation examples
let mut task = new;
// First user message
task.push;
// Generate response based on context
let response = llm.generate_json_with_context.unwrap;
// Add response to conversation context
task.push.unwrap;
// Continue conversation
task.push.unwrap;
Contextual Tasks
For complex data gathering, use ContextualTask to maintain reasoning, notes, and follow-up questions:
let mut task = new;
// ContextualTask automatically manages reasoning, notes,
// and generates appropriate follow-up questions
Documentation
- Getting Started - Complete setup guide
- Examples - Practical code examples
- Project Structure - Architecture overview
- API Documentation - Detailed API reference
Environment Setup
Secretary requires the following environment variables:
# or other compatible model
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.