| 77 | # ── Test 1: Simple extraction ──────────────────────────────────────────── |
| 78 | |
| 79 | def test_extract_person(): |
| 80 | result = session.tool("generate_object", { |
| 81 | "schema": { |
| 82 | "type": "object", |
| 83 | "required": ["name", "age", "city"], |
| 84 | "properties": { |
| 85 | "name": {"type": "string"}, |
| 86 | "age": {"type": "integer"}, |
| 87 | "city": {"type": "string"}, |
| 88 | }, |
| 89 | }, |
| 90 | "prompt": 'Extract: "Bob Zhang is 32 years old and lives in Beijing."', |
| 91 | "schema_name": "person", |
| 92 | "mode": "tool", |
| 93 | }) |
| 94 | assert result.exit_code == 0, f"Tool failed: {result.output}" |
| 95 | parsed = json.loads(result.output) |
| 96 | obj = parsed["object"] |
| 97 | assert obj["name"].lower() == "bob zhang", f"name: {obj['name']}" |
| 98 | assert obj["age"] == 32, f"age: {obj['age']}" |
| 99 | assert "beijing" in obj["city"].lower(), f"city: {obj['city']}" |
| 100 | print(f" Result: {json.dumps(obj)}") |
| 101 | |
| 102 | run_test("generate_object: extract person info", test_extract_person) |
| 103 | |