Skip to content

Type Conversion

Control how the response is parsed before returning.

Chaining methods

javascript
IA.asNumber();
await IA.create("cuanto es 5 * 10"); // returns number

IA.asObject();
await IA.create("dame un objeto con nombre y edad"); // returns object

Available Types

TypeDescriptionExample Output
stringReturns as string (default)"texto plano"
numberParses to number42
booleanParses to booleantrue
arrayParses to array["a", "b", "c"]
objectParses to object{ name: "Juan" }
jsonParses any valid JSONObject or array

Schema Validation

Define exact structures with .schema() — the response is validated and automatically retried on failure.

javascript
const user = await IA
  .schema({
    name: "string",
    age: "number",
    tags: ["string"],
  })
  .create("Dame un usuario");

console.log(user);
// → { name: "Ana", age: 28, tags: ["admin", "user"] }

See Methods → .schema() for full reference.

Automatic Detection

Without specifying a type, the parser automatically detects:

  • JSON objects {...} → object
  • JSON arrays [...] → array
  • Numeric values → number
  • true / false → boolean
  • Everything else → string
javascript
const result = await IA.create(
  'Responde con JSON: { "nombre": "Ana", "edad": 30 }'
);
console.log(result); // { nombre: "Ana", edad: 30 } (object)

const num = await IA.execute("5 + 3");
console.log(num); // 8 (number)

Response Length

Control response verbosity:

javascript
IA.short();   // Very brief — one word or short phrase
IA.medium();  // Concise (default)
IA.long();    // Detailed and complete

// Combined with type
const res = await IA.asArray().short().create("dame 3 números");

See Chaining → Length Setters for details.

Released under the MIT License.