Instruct-it
Structured information extraction adhering to custom templates and schemas using the Knowledgator Python SDK.
Example Usage
Structured Output with JSON Template
from knowledgator import Knowledgator
import json
kg = Knowledgator(api_key="YOUR_API_KEY")
template = {
"summary": "",
"key_points": [],
"risk_level": ""
}
result = kg.instruct.it(
text="Analyze this security policy and provide structured feedback.",
template=json.dumps(template),
output_type="json",
adapter_id="your-lora-adapter-id" # Optional LoRA adapter
)
print(result.outputs["summary"])
print(result.outputs["key_points"])
LoRA Adapters vs. Open Models
adapter_id is for fine-tuned LoRA adapters attached to base services. If you trained a standalone Open Model, query it via kg.model(model_id).predict(...) instead.
With File Attachment
from knowledgator import Knowledgator
kg = Knowledgator(api_key="YOUR_API_KEY")
with open("document.pdf", "rb") as f:
file_bytes = f.read()
result = kg.instruct.it(
text="Summarize this document.",
files=[
{
"name": "document.pdf",
"content": file_bytes
}
],
output_type="json"
)
print(result.outputs)
Expected Output
{
"summary": "This document outlines cybersecurity protocols for enterprise data access.",
"key_points": [
"Zero-trust network architecture required for all remote staff",
"Encryption enforced for data at rest and in transit",
"Quarterly access audits mandated"
],
"risk_level": "medium"
}
Result Object Structure
result.outputs contains the structured response parsed according to your output_type and template:
# Accessing fields directly
summary = result.outputs["summary"]
key_points = result.outputs["key_points"]
risk = result.outputs.get("risk_level", "unknown")