-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnl_config.py
More file actions
65 lines (51 loc) · 2.74 KB
/
nl_config.py
File metadata and controls
65 lines (51 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
"""VynFi NL config generation — describe a dataset, get a validated config.
Two sibling endpoints (both Scale+):
- ``client.configs.from_description(text)`` — free-text description →
validated PortalGenerationConfig.
- ``client.configs.from_company(uid=..., name=...)`` — Swiss VynCo
company profile → config tailored to the real entity's profile.
This example exercises both, prints the generated config, and (optionally)
submits it for a tiny dry-run generation so you can see the round-trip.
"""
from __future__ import annotations
import json
import os
import vynfi
client = vynfi.VynFi(api_key=os.environ["VYNFI_API_KEY"])
# ── 1. From free-text description ────────────────────────────────────────────
description = (
"Swiss manufacturing midsize firm, 4 quarterly periods in 2025, "
"IFRS, CHF, 3 legal entities, fraud-light baseline with a "
"vendor-kickback scheme, AML-free. Include audit workpapers."
)
print("=== configs.from_description() ===")
nl = client.configs.from_description(description)
print(f"confidence: {nl.confidence}")
print(f"notes: {nl.notes}")
cfg_preview = {k: v for k, v in (nl.config or {}).items() if not k.startswith("_")}
print("generated config (top-level keys):")
for key in sorted(cfg_preview):
print(f" - {key}: {json.dumps(cfg_preview[key], default=str)[:80]}")
# ── 2. From VynCo company profile (optional) ────────────────────────────────
# Uncomment to try the VynCo path. Requires the portal to have VynCo wired
# up and your tier to include the integration; falls back with 404/503 otherwise.
#
# try:
# print("\n=== configs.from_company(name=...) ===")
# co = client.configs.from_company(name="Nestlé", periods=4, fraud_rate=0.02)
# print(f"company: {co.company.get('name')} "
# f"({co.company.get('uid')})")
# print(f"notes: {co.notes}")
# except vynfi.NotFoundError:
# print("\n(VynCo company not found — integration may be disabled in your portal.)")
# ── 3. (Optional) submit the generated config for a small run ────────────────
if os.environ.get("VYNFI_RUN_NL", "") == "1":
# Bound the dry-run to something small regardless of what the LLM chose.
cfg = dict(nl.config or {})
cfg["rows"] = min(int(cfg.get("rows", 200)), 200)
cfg["periods"] = min(int(cfg.get("periods", 1)), 1)
cfg["companies"] = min(int(cfg.get("companies", 1)), 1)
print(f"\nSubmitting NL-generated config (rows={cfg['rows']})…")
job = client.jobs.generate_config(config=cfg)
done = client.jobs.wait(job.id, timeout=300)
print(f" job {done.id} → {done.status}")