Expand description
This module provides high-level abstractions for extracting structured data from text using LLMs.
Note: The target structure must implement the serde::Deserialize
, serde::Serialize
,
and schemars::JsonSchema
traits. Those can be easily derived using the derive
macro.
§Example
use rig::providers::openai;
// Initialize the OpenAI client
let openai = openai::Client::new("your-open-ai-api-key");
// Define the structure of the data you want to extract
#[derive(serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
struct Person {
name: Option<String>,
age: Option<u8>,
profession: Option<String>,
}
// Create the extractor
let extractor = openai.extractor::<Person>(openai::GPT_4O)
.build();
// Extract structured data from text
let person = extractor.extract("John Doe is a 30 year old doctor.")
.await
.expect("Failed to extract data from text");
Structs§
- Extractor for structured data from text
- Builder for the Extractor