Basic Object Generation
Generate simple structured objects with defined schemas. This is the most common use case for ObjectWeaver.
Simple Object Example
This example generates a technological landscape description for a fantasy world:
- cURL
- Python
- JavaScript/Node.js
- Go
curl -X POST http://localhost:2008/api/objectGen \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"prompt": "Generate a schema that defines the technological landscape of the world",
"definition": {
"type": "object",
"instruction": "Defines the technological landscape of the world, including its level of advancement and notable innovations.",
"properties": {
"Level": {
"type": "string",
"instruction": "Categorize the overall technological sophistication of the world, such as medieval, industrial, or advanced futuristic."
},
"Inventions": {
"type": "string",
"instruction": "Describe the most significant technological discoveries and their transformative impact on the society, economy, and daily life."
}
}
}
}'
import requests
url = "http://localhost:2008/api/objectGen"
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_API_KEY"
}
data = {
"prompt": "Generate a schema that defines the technological landscape of the world",
"definition": {
"type": "object",
"instruction": "Defines the technological landscape of the world, including its level of advancement and notable innovations.",
"properties": {
"Level": {
"type": "string",
"instruction": "Categorize the overall technological sophistication of the world, such as medieval, industrial, or advanced futuristic."
},
"Inventions": {
"type": "string",
"instruction": "Describe the most significant technological discoveries and their transformative impact on the society, economy, and daily life."
}
}
}
}
response = requests.post(url, headers=headers, json=data)
print(response.json())
const fetch = require('node-fetch');
const url = 'http://localhost:2008/api/objectGen';
const headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_API_KEY'
};
const data = {
prompt: 'Generate a schema that defines the technological landscape of the world',
definition: {
type: 'object',
instruction: 'Defines the technological landscape of the world, including its level of advancement and notable innovations.',
properties: {
Level: {
type: 'string',
instruction: 'Categorize the overall technological sophistication of the world, such as medieval, industrial, or advanced futuristic.'
},
Inventions: {
type: 'string',
instruction: 'Describe the most significant technological discoveries and their transformative impact on the society, economy, and daily life.'
}
}
}
};
fetch(url, {
method: 'POST',
headers: headers,
body: JSON.stringify(data)
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
type Property struct {
Type string `json:"type"`
Instruction string `json:"instruction"`
}
type Definition struct {
Type string `json:"type"`
Instruction string `json:"instruction"`
Properties map[string]Property `json:"properties"`
}
type RequestBody struct {
Prompt string `json:"prompt"`
Definition *Definition `json:"definition"`
}
func main() {
url := "http://localhost:2008/objectGen"
requestBody := RequestBody{
Prompt: "Generate a schema that defines the technological landscape of the world",
Definition: &Definition{
Type: "object",
Instruction: "Defines the technological landscape of the world, including its level of advancement and notable innovations.",
Properties: map[string]Property{
"Level": {
Type: "string",
Instruction: "Categorize the overall technological sophistication of the world, such as medieval, industrial, or advanced futuristic.",
},
"Inventions": {
Type: "string",
Instruction: "Describe the most significant technological discoveries and their transformative impact on the society, economy, and daily life.",
},
},
},
}
jsonData, err := json.Marshal(requestBody)
if err != nil {
fmt.Printf("Error marshalling request: %v\n", err)
return
}
req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
if err != nil {
fmt.Printf("Error creating request: %v\n", err)
return
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer YOUR_API_KEY")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Printf("Error sending request: %v\n", err)
return
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Printf("Error reading response: %v\n", err)
return
}
fmt.Println(string(body))
}
Expected Response
{
"Level": "Advanced Industrial with Magical Integration",
"Inventions": "The world's most transformative innovation is Aether-Steam Engines, which combine magical essence extraction with mechanical steam power. This hybrid technology has revolutionized transportation through sky-ships and rail networks, reshaped manufacturing by enabling enchantment assembly lines, and democratized access to both magical and mechanical tools, fundamentally altering the economic landscape and social mobility patterns."
}
Key Components
- Endpoint:
http://localhost:2008/objectGen - Method: POST
- Headers:
Content-Type: application/jsonAuthorization: Bearer YOUR_API_KEY
- Body: JSON definition with
promptanddefinition
Definition Structure
| Field | Type | Description |
|---|---|---|
type | string | Always "object" for object generation |
instruction | string | High-level context for the entire object |
properties | object | Map of field names to their definitions |
Property Structure
| Field | Type | Description |
|---|---|---|
type | string | Data type: "string", "number", "boolean", "object", "array" |
instruction | string | Specific guidance for generating this field |
model | string (optional) | Override model for this field (e.g., "gpt-4") |
temp | number (optional) | Temperature setting (0.0 - 2.0) |
Best Practices
- Clear Instructions: Be specific about what you want each field to contain
- Appropriate Types: Use the right data type for each field
- Context in Prompt: Provide high-level context in the main prompt
- Field Instructions: Give detailed guidance in each property's instruction
tip
For simple fields, you can omit the instruction and let the field name guide generation. For complex outputs, detailed instructions are essential.
Next Steps
- Learn about Decision Trees for conditional logic
- Explore Recursive Generation for nested structures
- See Epistemic Uncertainty for confidence scoring