formal-ai 0.231.0

Formal symbolic AI implementation with OpenAI-compatible APIs
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
//! Capability and recipe tables for composite program blueprints.

use crate::coding::blueprint::{BlueprintExecution, BlueprintRecipe, Capability, RecipeProgram};
use crate::coding::blueprint_programs::{
    JAVASCRIPT_HTTP_JSON_STATS, PYTHON_CRYPTO_PORTFOLIO_TRACKER, PYTHON_HTTP_JSON_STATS,
    PYTHON_PERSONAL_BUDGET_REPORT, PYTHON_SMART_TRAVEL_PLANNER, RUST_HTTP_JSON_STATS,
    RUST_SELF_SOURCE_METRICS,
};

/// The capability catalog. Each entry maps a class of sub-task onto the surface
/// phrases that request it. Latin/Cyrillic keywords match on whitespace token
/// boundaries; CJK keywords match by substring in the selector.
pub const CAPABILITIES: &[Capability] = &[
    Capability {
        slug: "http_request",
        label: "Make an HTTP request",
        keywords: &[
            "http",
            "https",
            "url",
            "get request",
            "http get",
            "fetch",
            "download",
            "запрос",
            "ссылк",
            "загруз",
            "स्थानांतरण",
            "अनुरोध",
            "请求",
            "下载",
            "网址",
        ],
    },
    Capability {
        slug: "json_parse",
        label: "Parse the JSON response",
        keywords: &[
            "json",
            "parse",
            "parses",
            "parsing",
            "deserialize",
            "разбор",
            "разобрать",
            "парсинг",
            "जेसन",
            "पार्स",
            "解析",
        ],
    },
    Capability {
        slug: "statistics",
        label: "Calculate statistics (mean, median)",
        keywords: &[
            "statistics",
            "statistic",
            "mean",
            "average",
            "median",
            "статистик",
            "среднее",
            "медиан",
            "औसत",
            "माध्यिका",
            "सांख्यिकी",
            "统计",
            "平均",
            "中位数",
        ],
    },
    Capability {
        slug: "output_results",
        label: "Output the results",
        keywords: &[
            "output",
            "print",
            "outputs",
            "display",
            "report",
            "вывод",
            "вывести",
            "печат",
            "आउटपुट",
            "छाप",
            "输出",
            "打印",
            "显示",
        ],
    },
    Capability {
        slug: "error_handling",
        label: "Handle errors",
        keywords: &[
            "error handling",
            "error-handling",
            "errors",
            "error",
            "exception",
            "ошибк",
            "обработк",
            "त्रुटि",
            "错误",
            "异常",
        ],
    },
    Capability {
        slug: "comments",
        label: "Document the code with comments",
        keywords: &[
            "comments",
            "comment",
            "commented",
            "documented",
            "комментар",
            "टिप्पणि",
            "注释",
            "评论",
        ],
    },
    Capability {
        slug: "web_research",
        label: "Research current source data",
        keywords: &[
            "search",
            "research",
            "sources",
            "source",
            "look up",
            "current",
            "average",
            "поиск",
            "источник",
            "источники",
            "искать",
            "खोज",
            "स्रोत",
            "वर्तमान",
            "搜索",
            "来源",
        ],
    },
    Capability {
        slug: "city_costs",
        label: "Compare city living costs",
        keywords: &[
            "living costs",
            "cost of living",
            "average rent",
            "rent",
            "moscow",
            "berlin",
            "new york",
            "city",
            "cities",
            "аренда",
            "стоимость жизни",
            "москва",
            "берлин",
            "нью-йорк",
            "जीवन यापन",
            "लागत",
            "किराया",
            "मास्को",
            "बर्लिन",
            "न्यूयॉर्क",
            "租金",
            "生活成本",
        ],
    },
    Capability {
        slug: "visa_requirements",
        label: "Check visa requirements",
        keywords: &["visa", "visa-free", "russian citizens", "requirements"],
    },
    Capability {
        slug: "flight_costs",
        label: "Estimate flight costs",
        keywords: &[
            "flight costs",
            "flight cost",
            "flight",
            "from moscow",
            "next 3 months",
            "destinations",
        ],
    },
    Capability {
        slug: "travel_planner_class",
        label: "Build a travel-planner class",
        keywords: &[
            "travel planner",
            "travelplanner",
            "itinerary",
            "generate_itinerary",
            "add_destination",
            "destination",
            "trip",
            "class",
        ],
    },
    Capability {
        slug: "budget_flags",
        label: "Flag destinations over budget",
        keywords: &[
            "budget < estimated cost",
            "budget warning",
            "estimated cost",
            "prioritize",
            "visa-free access",
            "flag",
            "budget",
        ],
    },
    Capability {
        slug: "sample_itinerary",
        label: "Generate a sample itinerary",
        keywords: &[
            "sample output",
            "sample itinerary",
            "7-day",
            "7 day",
            "$2000",
            "$2,000",
        ],
    },
    Capability {
        slug: "budget_rule",
        label: "Apply the 50/30/20 budget rule",
        keywords: &[
            "50/30/20",
            "budget rule",
            "monthly income",
            "income",
            "needs",
            "wants",
            "savings",
            "бюджет",
            "доход",
            "сбереж",
            "बजट",
            "आय",
            "बचत",
            "预算",
            "收入",
        ],
    },
    Capability {
        slug: "compound_savings",
        label: "Project compound savings",
        keywords: &[
            "annual return",
            "return",
            "8%",
            "10 years",
            "$3000",
            "100,000",
            "100000",
            "years to save",
            "накопить",
            "доходность",
            "वार्षिक रिटर्न",
            "रिटर्न",
            "साल",
            "收益",
            "",
        ],
    },
    Capability {
        slug: "markdown_report",
        label: "Export a Markdown comparison report",
        keywords: &[
            "markdown",
            "formatted markdown",
            "report",
            "comparison table",
            "table",
            "export",
            "отчет",
            "отчёт",
            "таблица",
            "экспорт",
            "मार्कडाउन",
            "रिपोर्ट",
            "तालिका",
            "निर्यात",
            "报告",
            "表格",
            "导出",
        ],
    },
    Capability {
        slug: "source_text",
        label: "Read the program's own source code as text",
        keywords: &["own source", "source code as text", "itself"],
    },
    Capability {
        slug: "source_metrics",
        label: "Count functions, loops, conditionals, and comments",
        keywords: &["functions", "loops", "conditionals", "comments"],
    },
    Capability {
        slug: "complexity_score",
        label: "Calculate a cyclomatic-complexity score",
        keywords: &["complexity score", "cyclomatic", "complexity"],
    },
    Capability {
        slug: "json_report",
        label: "Output the metrics as JSON",
        keywords: &["json report", "json", "metrics"],
    },
    Capability {
        slug: "self_response_analysis",
        label: "Analyze the assistant response with the same metrics",
        keywords: &["your own response", "reasoning text", "same metrics"],
    },
    Capability {
        slug: "complexity_comparison",
        label: "Compare code complexity with reasoning-text complexity",
        keywords: &["compare", "more complex", "which is more complex"],
    },
    Capability {
        slug: "crypto_prices",
        label: "Fetch current crypto prices",
        keywords: &[
            "crypto",
            "btc",
            "eth",
            "ton",
            "usdt",
            "current prices",
            "public api",
        ],
    },
    Capability {
        slug: "portfolio_holdings",
        label: "Model portfolio holdings",
        keywords: &["portfolio", "holdings"],
    },
    Capability {
        slug: "portfolio_calculations",
        label: "Calculate total value, 24h changes, and weights",
        keywords: &[
            "total value",
            "value in usd",
            "24h change",
            "weight distribution",
        ],
    },
    Capability {
        slug: "alert_logic",
        label: "Notify when an asset drops more than 5%",
        keywords: &["alert", "notify", "drops"],
    },
    Capability {
        slug: "mock_api",
        label: "Mock the public API endpoint",
        keywords: &["mock", "mock endpoint"],
    },
];

/// Curated composite recipes. They are returned with an honest execution status
/// because the answer renderer does not compile these multi-step blueprints in
/// place; some also need network access or external libraries.
pub const RECIPES: &[BlueprintRecipe] = &[
    BlueprintRecipe {
        slug: "http_json_stats",
        label: "fetch JSON over HTTP and report the mean and median of its numbers",
        required_capabilities: &["http_request", "json_parse", "statistics"],
        programs: &[
            RecipeProgram {
                language_slug: "rust",
                libraries: &["reqwest (blocking, json)", "serde_json"],
                run_command: "cargo run -- <url-returning-json>",
                execution: BlueprintExecution::ExternalLibrariesAndNetwork,
                code: RUST_HTTP_JSON_STATS,
            },
            RecipeProgram {
                language_slug: "python",
                libraries: &["requests"],
                run_command: "python stats.py <url-returning-json>",
                execution: BlueprintExecution::ExternalLibrariesAndNetwork,
                code: PYTHON_HTTP_JSON_STATS,
            },
            RecipeProgram {
                language_slug: "javascript",
                libraries: &["Node.js 18+ (built-in global fetch; no extra packages)"],
                run_command: "node stats.js <url-returning-json>",
                execution: BlueprintExecution::ExternalLibrariesAndNetwork,
                code: JAVASCRIPT_HTTP_JSON_STATS,
            },
        ],
    },
    BlueprintRecipe {
        slug: "personal_budget_report",
        label: "build a sourced 50/30/20 city budget calculator and Markdown report",
        required_capabilities: &[
            "web_research",
            "city_costs",
            "budget_rule",
            "compound_savings",
            "markdown_report",
        ],
        programs: &[RecipeProgram {
            language_slug: "python",
            libraries: &["Python 3 standard library only"],
            run_command: "python budget_report.py",
            execution: BlueprintExecution::ReviewDataAssumptions,
            code: PYTHON_PERSONAL_BUDGET_REPORT,
        }],
    },
    BlueprintRecipe {
        slug: "smart_travel_planner",
        label: "build a sourced travel planner class with visa, flight-cost, budget, and itinerary logic",
        required_capabilities: &[
            "web_research",
            "visa_requirements",
            "flight_costs",
            "travel_planner_class",
            "budget_flags",
            "sample_itinerary",
        ],
        programs: &[RecipeProgram {
            language_slug: "python",
            libraries: &["Python 3 standard library only"],
            run_command: "python travel_planner.py",
            execution: BlueprintExecution::ReviewDataAssumptions,
            code: PYTHON_SMART_TRAVEL_PLANNER,
        }],
    },
    BlueprintRecipe {
        slug: "self_source_metrics_report",
        label:
            "inspect its own Rust source, emit JSON metrics, and compare code with response prose",
        required_capabilities: &[
            "source_text",
            "source_metrics",
            "complexity_score",
            "json_report",
            "self_response_analysis",
            "complexity_comparison",
        ],
        programs: &[RecipeProgram {
            language_slug: "rust",
            libraries: &["Rust standard library only"],
            run_command: "cargo run",
            execution: BlueprintExecution::LocalSourceAnalysis,
            code: RUST_SELF_SOURCE_METRICS,
        }],
    },
    BlueprintRecipe {
        slug: "crypto_portfolio_tracker",
        label: "simulate a crypto portfolio tracker with alerts and a Markdown dashboard",
        required_capabilities: &[
            "crypto_prices",
            "portfolio_holdings",
            "portfolio_calculations",
            "alert_logic",
            "mock_api",
            "markdown_report",
        ],
        programs: &[RecipeProgram {
            language_slug: "python",
            libraries: &["Python 3 standard library only"],
            run_command: "python crypto_portfolio.py",
            execution: BlueprintExecution::ReviewDataAssumptions,
            code: PYTHON_CRYPTO_PORTFOLIO_TRACKER,
        }],
    },
];