@misterscan/sesi 1.2.3 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agents/rules/sesi-must-read.md +116 -0
- package/.agents/workflows/create-sesi-script.md +44 -0
- package/.agents/workflows/fix-sesi-script.md +14 -0
- package/.github/prompts/MakeInSesi.prompt.md +79 -0
- package/README.md +163 -51
- package/bin/sesi.js +196 -38
- package/chatbot/chatbot.html +488 -0
- package/{main → chatbot}/chatbot.sesi +1 -2
- package/chatbot/chatbot_server.py +105 -0
- package/chatbot/sesi_db_chatbot.sesi +278 -0
- package/dist/ai-runtime.js +2 -2
- package/dist/builtins.d.ts.map +1 -1
- package/dist/builtins.js +199 -5
- package/dist/builtins.js.map +1 -1
- package/dist/index.d.ts +12 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +90 -6
- package/dist/index.js.map +1 -1
- package/dist/interpreter.d.ts +21 -2
- package/dist/interpreter.d.ts.map +1 -1
- package/dist/interpreter.js +201 -92
- package/dist/interpreter.js.map +1 -1
- package/dist/lexer.d.ts.map +1 -1
- package/dist/lexer.js +8 -4
- package/dist/lexer.js.map +1 -1
- package/dist/parser.d.ts +1 -0
- package/dist/parser.d.ts.map +1 -1
- package/dist/parser.js +21 -12
- package/dist/parser.js.map +1 -1
- package/dist/sesi.bundled.js +2526 -1487
- package/dist/types.d.ts +14 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +33 -1
- package/dist/types.js.map +1 -1
- package/docs/ARCHITECTURE.md +21 -13
- package/docs/BUILTINS.md +136 -19
- package/docs/CLI.md +200 -0
- package/docs/COMPARISON.md +16 -13
- package/docs/IMAGE_GENERATION.md +13 -14
- package/docs/IMPLEMENTATION_SUMMARY.md +174 -110
- package/docs/QUICKSTART.md +173 -39
- package/docs/README.md +202 -54
- package/docs/{SYSTEMS_REASONING.md → REASONING.md} +115 -120
- package/docs/ROADMAP.md +51 -47
- package/docs/SKILLS.md +73 -98
- package/docs/SPECIFICATION.md +59 -40
- package/examples/03_functions.sesi +30 -1
- package/examples/07_prompts.sesi +27 -3
- package/examples/08_model_call.sesi +6 -4
- package/examples/09_structured_output.sesi +19 -3
- package/examples/10_code_generation.sesi +6 -4
- package/examples/11_memory_conversation.sesi +47 -15
- package/examples/12_classification.sesi +62 -7
- package/examples/13_data_pipeline.sesi +55 -28
- package/examples/14_folder_explainer.sesi +52 -51
- package/examples/15_image_generation.sesi +15 -14
- package/examples/16_modules.sesi +27 -27
- package/examples/19_search_web.sesi +18 -2
- package/examples/20_model_aliases.sesi +22 -0
- package/examples/21_custom_tools.sesi +27 -0
- package/examples/22_reasoning_plus_custom_tools.sesi +19 -0
- package/main/tests/test-args.sesi +7 -0
- package/main/tests/test_args.sesi +7 -0
- package/main/tests/test_general_modules.sesi +127 -0
- package/main/tests/test_grounding.sesi +2 -0
- package/package.json +26 -22
- package/docs/DISTRIBUTED_SYSTEMS.md +0 -71
- package/docs/sesi_ai_chronicles.md +0 -209
- package/main/conversational_classifier_weights.json +0 -45
- package/main/conversational_sentences.json +0 -304
- package/main/epochs.sesi +0 -94
- package/main/gpu_orchestrator.sesi +0 -36
- package/main/hardware_diagnostics.sesi +0 -118
- package/main/inference.sesi +0 -54
- package/main/native_chatbot.sesi +0 -180
- package/main/native_synthesizer.sesi +0 -83
- package/main/nn_personas_trainer.sesi +0 -302
- package/main/nn_responses_trainer.sesi +0 -269
- package/main/nn_sentences_trainer.sesi +0 -330
- package/main/orchestrator.sesi +0 -15
- package/main/personas.json +0 -124
- package/main/personas_classifier_weights.json +0 -45
- package/main/playground.sesi +0 -3
- package/main/predictive_typing.sesi +0 -127
- package/main/query_brain.sesi +0 -45
- package/main/response_classifier_weights.json +0 -45
- package/main/retro_chat.html +0 -239
- package/main/retro_chat_generator.sesi +0 -745
- package/main/sesi_ai.sesi +0 -158
- package/main/sesi_db_chatbot.sesi +0 -280
- package/main/setup_swarm.sesi +0 -5
- package/main/start.sesi +0 -13
- package/main/terminal.log +0 -56
- package/main/terminal_chat.py +0 -385
- package/main/unified_sesi_ai.sesi +0 -334
- package/main/varied_responses.json +0 -304
package/docs/SPECIFICATION.md
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
# Sesi
|
|
1
|
+
# Sesi Language Specification (v1.3)
|
|
2
2
|
|
|
3
3
|
## 1. Philosophy & Design Principles
|
|
4
4
|
|
|
5
5
|
Sesi is built on these core principles:
|
|
6
6
|
|
|
7
|
-
1. **
|
|
8
|
-
2. **
|
|
9
|
-
3. **
|
|
10
|
-
4. **
|
|
11
|
-
5. **
|
|
7
|
+
1. **Conciseness and Legibility**: The syntax is minimal. If a concept can be expressed simply, the language gets out of the way to let you express it.
|
|
8
|
+
2. **Buildable from Scratch**: Sesi is a complete, functioning language with its own lexer, parser, and interpreter.
|
|
9
|
+
3. **Simplicity Enables Power**: Because the core language is simple, complex operations (like hitting APIs or orchestrating processes) become trivial extensions of the language, rather than tangled SDK implementations.
|
|
10
|
+
4. **Transparency Over Magic**: Sesi executes exactly what you write.
|
|
11
|
+
5. **Practicality**: Focus on reducing boilerplate code, emphasizing what developers actually need over academic completeness.
|
|
12
12
|
|
|
13
13
|
## 2. Target Users
|
|
14
14
|
|
|
15
|
-
**Primary**: Developers
|
|
15
|
+
**Primary**: Developers who want a clean, fast, and legible language where writing code, whether purely logic-based or calling out to a Reasoning model, is completely frictionless.
|
|
16
16
|
|
|
17
17
|
**Secondary**:
|
|
18
18
|
|
|
19
19
|
- Engineers transitioning from traditional languages (TypeScript, Python, Go)
|
|
20
|
-
- Developers
|
|
20
|
+
- Developers looking for minimal boilerplate.
|
|
21
21
|
- Teams requiring complex logic with a fraction of the boilerplate
|
|
22
22
|
|
|
23
23
|
**Use Cases**:
|
|
24
24
|
|
|
25
|
-
-
|
|
26
|
-
-
|
|
27
|
-
-
|
|
28
|
-
-
|
|
25
|
+
- Writing clean CLI tools and scripts
|
|
26
|
+
- Interacting with APIs without SDK boilerplate
|
|
27
|
+
- Quickly orchestrating shell commands
|
|
28
|
+
- Rapid prototyping and scripting
|
|
29
29
|
|
|
30
|
-
## 3. V1.
|
|
30
|
+
## 3. V1.3 Feature Set (Current)
|
|
31
31
|
|
|
32
32
|
### Core Language Features
|
|
33
33
|
|
|
@@ -37,20 +37,20 @@ Sesi is built on these core principles:
|
|
|
37
37
|
- ✅ Loops (`while`, `for`)
|
|
38
38
|
- ✅ Error Handling (`try/catch` blocks)
|
|
39
39
|
- ✅ Data types (number, string, bool, array, object)
|
|
40
|
-
- ✅
|
|
40
|
+
- ✅ Process Execution (`spawn`, `exec`, `time`, `random`)
|
|
41
41
|
- ✅ Comments (`//`, `/* */`)
|
|
42
42
|
- ✅ Operators (arithmetic, logical, comparison)
|
|
43
43
|
- ✅ Standard library (print, len, range, etc.)
|
|
44
|
+
- ✅ `prompt` blocks (composable templates for concise formatting)
|
|
45
|
+
- ✅ `structured_output()` (schema-guided structured output with JSON recovery and empty-object fallback on failure)
|
|
46
|
+
- ✅ `tool_call()` (Fully functional function calling for tool use)
|
|
47
|
+
- ✅ `memory` (simple multi-turn script memory and retrieval context management)
|
|
44
48
|
|
|
45
49
|
### Reasoning-Native Features
|
|
46
50
|
|
|
47
|
-
- ✅ `prompt` blocks (composable message templates)
|
|
48
51
|
- ✅ `model()` calls (native model with configuration)
|
|
49
52
|
- ✅ `image()` calls (native image generation with configuration)
|
|
50
53
|
- ✅ `images` config key (multimodal vision input for `model()` and `image()`)
|
|
51
|
-
- ✅ `structured_output()` (schema-guided structured output with JSON recovery and empty-object fallback on failure)
|
|
52
|
-
- ✅ `tool_call()` (Fully functional function calling via models)
|
|
53
|
-
- ✅ Simple memory (conversation context)
|
|
54
54
|
|
|
55
55
|
### Type System
|
|
56
56
|
|
|
@@ -87,6 +87,13 @@ string: "..." | '...'
|
|
|
87
87
|
comment: // ... | /* ... */
|
|
88
88
|
```
|
|
89
89
|
|
|
90
|
+
#### String Escapes & Multiline Rules
|
|
91
|
+
|
|
92
|
+
- Supported escape sequences: `\\n`, `\\t`, `\\r`, `\\\\`, `\\"`, `\\'`
|
|
93
|
+
- Unknown escape sequences are runtime errors during lexing with line and column context
|
|
94
|
+
- Strings can span multiple lines when a literal newline appears before the closing quote
|
|
95
|
+
- Unterminated strings report the starting line and column of the string literal
|
|
96
|
+
|
|
90
97
|
### 4.2 Program Structure
|
|
91
98
|
|
|
92
99
|
```
|
|
@@ -171,7 +178,7 @@ Example:
|
|
|
171
178
|
```sesi
|
|
172
179
|
for i = 0 to 10 {print i}
|
|
173
180
|
try
|
|
174
|
-
{let result =
|
|
181
|
+
{let result = "Hello"
|
|
175
182
|
} catch (e) {
|
|
176
183
|
print e}
|
|
177
184
|
```
|
|
@@ -235,10 +242,10 @@ config_entry := (STRING | identifier) ':' expression
|
|
|
235
242
|
| Key | Applies to | Type | Description |
|
|
236
243
|
| --------------- | ---------------- | ------------------------- | -------------------------------------------------------------------------- |
|
|
237
244
|
| `thinkingLevel` | `model` | `string \| object` | **Recommended**: Effort level (`"minimal"`, `"low"`, `"medium"`, `"high"`) |
|
|
238
|
-
| `temperature` | `model`, `image` | `number` |
|
|
245
|
+
| `temperature` | `model`, `image` | `number` | \*Will be deprecated in Gemini 3.x+\_ (Sampling temperature) |
|
|
239
246
|
| `max_tokens` | `model` | `number` | Max output token count |
|
|
240
|
-
| `top_k` | `model` | `number` |
|
|
241
|
-
| `top_p` | `model` | `number` |
|
|
247
|
+
| `top_k` | `model` | `number` | \*Will be deprecated in Gemini 3.x+\_ |
|
|
248
|
+
| `top_p` | `model` | `number` | \*Will be deprecated in Gemini 3.x+\_ |
|
|
242
249
|
| `ratio` | `image` | `string` | Aspect ratio e.g. `"16:9"` |
|
|
243
250
|
| `size` | `image` | `string` | `"512"`, `"1K"`, `"2K"`, `"4K"` |
|
|
244
251
|
| `images` | `model`, `image` | `string \| array<string>` | Local file path(s) passed as visual input |
|
|
@@ -260,13 +267,21 @@ schema := '{' (identifier ':' type (',' identifier ':' type)*)? '}'
|
|
|
260
267
|
Example:
|
|
261
268
|
|
|
262
269
|
```sesi
|
|
263
|
-
let
|
|
270
|
+
let rawJson = "{\"projectName\": \"Sesi\", \"version\": \"1.3.0\", \"status\": \"active\"}"
|
|
271
|
+
let parsedRegistry = structured_output({projectName: string, version: string, status: string})(rawJson)
|
|
264
272
|
```
|
|
265
273
|
|
|
266
274
|
#### Tool Call
|
|
267
275
|
|
|
268
276
|
```
|
|
269
|
-
tool_call := 'tool_call' '('function_name')' '('model_call')'
|
|
277
|
+
tool_call := 'tool_call' '('function_name')' '('(model_call | expressions)?')'
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
Example (Native Sandboxed Dispatch):
|
|
281
|
+
|
|
282
|
+
```sesi
|
|
283
|
+
fn add(a: number, b: number) -> number { return a + b }
|
|
284
|
+
let sum = tool_call(add)(10, 20)
|
|
270
285
|
```
|
|
271
286
|
|
|
272
287
|
#### Memory (State Management)
|
|
@@ -297,7 +312,7 @@ optional_type := type '?'
|
|
|
297
312
|
|
|
298
313
|
1. **Short-circuit evaluation**: `&&` and `||` short-circuit
|
|
299
314
|
2. **Type coercion**: Automatic for numeric operations; explicit for string/number
|
|
300
|
-
3. **Null propagation**: Operations on `null` return `null` (no exceptions in v1.
|
|
315
|
+
3. **Null propagation**: Operations on `null` return `null` (no exceptions in v1.3)
|
|
301
316
|
4. **Model responses**: Always returned as strings initially; structured_output provides type safety
|
|
302
317
|
|
|
303
318
|
## 6. Scope and Binding
|
|
@@ -357,9 +372,13 @@ time() -> number // Current Unix timestamp
|
|
|
357
372
|
random() -> number // Random float (0.0 to 1.0)
|
|
358
373
|
```
|
|
359
374
|
|
|
375
|
+
### Built-in Global Variables
|
|
376
|
+
|
|
377
|
+
- `args` - `array<string>`: Contains the command-line arguments passed to the script, excluding Sesi runtime options and the script path.
|
|
378
|
+
|
|
360
379
|
## 9. Module System
|
|
361
380
|
|
|
362
|
-
Runtime module execution and standard namespace modules are fully implemented and natively supported in v1.
|
|
381
|
+
Runtime module execution and standard namespace modules are fully implemented and natively supported in v1.3+.
|
|
363
382
|
|
|
364
383
|
### Defining Modules
|
|
365
384
|
|
|
@@ -385,16 +404,16 @@ import math from "std/math" // Math operations
|
|
|
385
404
|
import json from "std/json" // JSON parsing
|
|
386
405
|
```
|
|
387
406
|
|
|
388
|
-
### Module Resolution Order (v1.
|
|
407
|
+
### Module Resolution Order (v1.3+)
|
|
389
408
|
|
|
390
409
|
When you write `import {x} from "mymodule"`, Sesi searches for `mymodule.sesi` in the following order, stopping at the first match:
|
|
391
410
|
|
|
392
|
-
| Priority | Location
|
|
393
|
-
| -------- |
|
|
394
|
-
| 1
|
|
395
|
-
| 2
|
|
396
|
-
| 3
|
|
397
|
-
| 4
|
|
411
|
+
| Priority | Location | Description |
|
|
412
|
+
| -------- | ----------------------------- | -------------------------------------------------------------------------------------- |
|
|
413
|
+
| 1 | **Script's own directory** | Same folder as the currently running `.sesi` file |
|
|
414
|
+
| 2 | **Current working directory** | The directory you ran `sesi` from |
|
|
415
|
+
| 3 | **`SESI_PATH`** | Semicolon-separated (Windows) or colon-separated (Unix) list of additional directories |
|
|
416
|
+
| 4 | **`~/.sesi/lib`** | Global shared library directory — available system-wide |
|
|
398
417
|
|
|
399
418
|
This means imports always resolve correctly regardless of where you run `sesi` from.
|
|
400
419
|
|
|
@@ -470,10 +489,10 @@ print "Image written to logo.png"
|
|
|
470
489
|
- **`max_tokens`**: `number` (maximum response tokens)
|
|
471
490
|
- **`images`**: `string` or `array<string>` (paths to multimodal vision input files)
|
|
472
491
|
- **`cache`**: `bool` (set to `false` to explicitly bypass Sesi Logic Caching)
|
|
473
|
-
- **`temperature`**:
|
|
474
|
-
- **`top_k` / `top_p`**:
|
|
492
|
+
- **`temperature`**: _ Will be deprecated in Gemini 3.x+, use thinkingLevel instead._ — reasoning is pre-optimized for defaults.
|
|
493
|
+
- **`top_k` / `top_p`**: _ Will be deprecated in Gemini 3.x+, use thinkingLevel instead._ — reasoning is pre-optimized for defaults.
|
|
475
494
|
|
|
476
|
-
### Structured Output
|
|
495
|
+
### Reasoning with Structured Output
|
|
477
496
|
|
|
478
497
|
```sesi
|
|
479
498
|
let result = structured_output({title: string, category: string, confidence: number})(model("gemini-3.1-flash-lite") {"Extract metadata from this text:" text})
|
|
@@ -481,7 +500,7 @@ print result.title // Access fields
|
|
|
481
500
|
print result.confidence // Type-safe access
|
|
482
501
|
```
|
|
483
502
|
|
|
484
|
-
### Tool Calling
|
|
503
|
+
### Reasoning with Tool Calling
|
|
485
504
|
|
|
486
505
|
```sesi
|
|
487
506
|
fn calculateTax(amount: number, rate: number) {print amount * rate}
|
|
@@ -489,7 +508,7 @@ let taxAmount = tool_call(calculateTax)(model("gemini-3.1-flash-lite") {"Calcula
|
|
|
489
508
|
taxAmount
|
|
490
509
|
```
|
|
491
510
|
|
|
492
|
-
### Memory
|
|
511
|
+
### Reasoning with Memory
|
|
493
512
|
|
|
494
513
|
```sesi
|
|
495
514
|
memory chat {"System: You are a helpful assistant."}
|
|
@@ -515,7 +534,7 @@ fn analyzeText(text: string) -> string {return model("gemini-3.5-flash") {thinki
|
|
|
515
534
|
print analyzeText("Reasoning is transforming industries")
|
|
516
535
|
```
|
|
517
536
|
|
|
518
|
-
### Example 3: Structured Output
|
|
537
|
+
### Example 3: Reasoning with Structured Output
|
|
519
538
|
|
|
520
539
|
```sesi
|
|
521
540
|
let sentiment = structured_output({label: string, score: number})(model("gemini-3-flash-preview") {"Analyze sentiment of:" userInput})
|
|
@@ -523,7 +542,7 @@ print sentiment.label
|
|
|
523
542
|
print sentiment.score
|
|
524
543
|
```
|
|
525
544
|
|
|
526
|
-
## 12. Undefined Behavior & Limitations (V1.
|
|
545
|
+
## 12. Undefined Behavior & Limitations (V1.3)
|
|
527
546
|
|
|
528
547
|
- **No async/await**: All operations within a script are blocking (including model calls). Concurrency must be achieved via `spawn()`.
|
|
529
548
|
- **No custom types**: Only built-in types are supported natively.
|
|
@@ -1,6 +1,35 @@
|
|
|
1
1
|
// Functions
|
|
2
2
|
fn add(a: number, b: number) {print a + b}
|
|
3
3
|
fn greet(name: string = "World") {print "Hello" name "!"}
|
|
4
|
+
|
|
4
5
|
add(5, 3)
|
|
5
6
|
greet()
|
|
6
|
-
greet("Alice")
|
|
7
|
+
greet("Alice")
|
|
8
|
+
|
|
9
|
+
// Advanced Functions
|
|
10
|
+
fn calculate(operation: string, a: number, b: number) {
|
|
11
|
+
if operation == "add" {
|
|
12
|
+
print a + b
|
|
13
|
+
} else if operation == "subtract" {
|
|
14
|
+
print a - b
|
|
15
|
+
} else if operation == "multiply" {
|
|
16
|
+
print a * b
|
|
17
|
+
} else if operation == "divide" {
|
|
18
|
+
print a / b
|
|
19
|
+
} else {
|
|
20
|
+
print "Invalid operation"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
calculate("add", 5, 3)
|
|
25
|
+
|
|
26
|
+
// Define your functions and call it using a custom tool
|
|
27
|
+
|
|
28
|
+
fn getSesiVersion() {
|
|
29
|
+
return "1.3.2"
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
define_tool("sesi", getSesiVersion, "Get the current Sesi version")
|
|
33
|
+
let v = tool_call(sesi)()
|
|
34
|
+
|
|
35
|
+
print "Current version:" v
|
package/examples/07_prompts.sesi
CHANGED
|
@@ -1,10 +1,34 @@
|
|
|
1
|
-
// Prompt blocks - composable
|
|
1
|
+
// Prompt blocks - composable text templates
|
|
2
2
|
prompt greetingTemplate {"Hello! " "How are you today?"}
|
|
3
|
-
prompt responseTemplate {greetingTemplate "
|
|
3
|
+
prompt responseTemplate {greetingTemplate " I hope you're having a great day!"}
|
|
4
4
|
// Prompts evaluate to strings
|
|
5
5
|
let greeting = responseTemplate
|
|
6
6
|
print greeting
|
|
7
7
|
// Prompts can use variables
|
|
8
8
|
let userName = "Alice"
|
|
9
9
|
prompt personalGreeting {"Hello, " userName "! Welcome back!"}
|
|
10
|
-
print personalGreeting
|
|
10
|
+
print personalGreeting
|
|
11
|
+
|
|
12
|
+
// You can really explore the power of prompt blocks by using it to structure your outputs
|
|
13
|
+
|
|
14
|
+
prompt htmlHead {"<!DOCTYPE html>
|
|
15
|
+
<html lang='en'>
|
|
16
|
+
<head>
|
|
17
|
+
<meta charset='UTF-8'>
|
|
18
|
+
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
|
|
19
|
+
<title>Document</title>
|
|
20
|
+
</head>
|
|
21
|
+
"}
|
|
22
|
+
prompt htmlBody {"<body>
|
|
23
|
+
<h1>Hello World!</h1>
|
|
24
|
+
<p>This is a paragraph</p>
|
|
25
|
+
</body>
|
|
26
|
+
"}
|
|
27
|
+
prompt htmlFooter {"</html>"}
|
|
28
|
+
prompt htmlLayout {htmlHead htmlBody htmlFooter}
|
|
29
|
+
try {
|
|
30
|
+
write_file("index.html", htmlLayout)
|
|
31
|
+
print "HTML file created successfully!"
|
|
32
|
+
} catch(error) {
|
|
33
|
+
print "Error creating HTML file: " error
|
|
34
|
+
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// Reasoning-powered text analysis using model calls
|
|
2
|
-
//
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
// USING IT FOR AI IS OPTIONAL AND NOT REQUIRED TO USE IN YOUR SCRIPTS.
|
|
3
|
+
// COMMENTED OUT BECAUSE AI WILL FORCE THEMSELVES TO RUN IT
|
|
4
|
+
|
|
5
|
+
// let text = "Sesi is transforming how we work and live"
|
|
6
|
+
// let analysis = model("gemini-3.1-flash-lite") {temperature: 0.5, max_tokens: 400} {"Analyze the following text and provide 3 concise key insights. Keep the total response under 120 words. " text}
|
|
7
|
+
// print "Analysis:" analysis
|
|
@@ -1,7 +1,23 @@
|
|
|
1
1
|
// Sentiment analysis with structured output
|
|
2
|
-
//
|
|
2
|
+
// THIS IS OPTIONAL AND NOT REQUIRED TO USE IN YOUR SCRIPTS.
|
|
3
|
+
|
|
3
4
|
let review = "This product is amazing! I love how it works. Highly recommended!"
|
|
4
|
-
let sentiment = structured_output({sentiment: string, confidence: number, keywords: string})(model("gemini-3.1-flash-lite") {"Analyze the sentiment of this review and extract key information.
|
|
5
|
+
let sentiment = structured_output({sentiment: string, confidence: number, keywords: string})(model("gemini-3.1-flash-lite") {"Analyze the sentiment of this review and extract key information. Return JSON with: sentiment (positive/negative/neutral), confidence (0-1), keywords (comma-separated) " review})
|
|
5
6
|
print "Sentiment:" sentiment["sentiment"]
|
|
6
7
|
print "Confidence:" sentiment["confidence"]
|
|
7
|
-
print "Keywords:" sentiment["keywords"]
|
|
8
|
+
print "Keywords:" sentiment["keywords"]
|
|
9
|
+
|
|
10
|
+
// Structured output can be used without model() function as well
|
|
11
|
+
// For example, if you have an API endpoint that returns JSON data, you can use structured_output to parse it.
|
|
12
|
+
|
|
13
|
+
let json_data = web_get("https://jsonplaceholder.typicode.com/todos/1")
|
|
14
|
+
let structured_data = structured_output({title: string, completed: boolean})(json_data)
|
|
15
|
+
print "Title:" structured_data["title"]
|
|
16
|
+
print "Completed:" structured_data["completed"]
|
|
17
|
+
|
|
18
|
+
// You can even pass raw text to structured_output if you want, it just needs to be in JSON format. For example:
|
|
19
|
+
|
|
20
|
+
let raw_text = "{\"title\": \"Buy milk\", \"completed\": false}"
|
|
21
|
+
let structured_data = structured_output({title: string, completed: boolean})(raw_text)
|
|
22
|
+
print "Title:" structured_data["title"]
|
|
23
|
+
print "Completed:" structured_data["completed"]
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// Code generation with Reasoning
|
|
2
|
-
//
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
// USING IT FOR AI IS OPTIONAL AND NOT REQUIRED TO USE IN YOUR SCRIPTS.
|
|
3
|
+
// COMMENTED OUT BECAUSE AI WILL FORCE THEMSELVES TO RUN IT
|
|
4
|
+
|
|
5
|
+
// let requirement = "A function that checks if a number is prime"
|
|
6
|
+
// let generatedCode = model("gemini-3.1-flash-lite") {temperature: 0.2, max_tokens: 500} {"Generate JavaScript code for the following requirement: " requirement " Provide only the code, no explanation."}
|
|
7
|
+
// print "Generated Code:" generatedCode
|
|
@@ -1,16 +1,48 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
memory
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
// You can use memory to store variables throughout your script without redeclaring it
|
|
2
|
+
|
|
3
|
+
memory store_database {"name: string, age: number, role: string"}
|
|
4
|
+
|
|
5
|
+
store_database = {"name": "John", "age": 30, "role": "developer"}
|
|
6
|
+
print "Name:" store_database["name"]
|
|
7
|
+
print "Age:" store_database["age"]
|
|
8
|
+
print "Role:" store_database["role"]
|
|
9
|
+
try {
|
|
10
|
+
write_file("data.txt", to_json(store_database))
|
|
11
|
+
print "Database saved!"
|
|
12
|
+
} catch(error) {
|
|
13
|
+
print "Error:" error
|
|
9
14
|
}
|
|
10
|
-
|
|
11
|
-
let
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
|
|
16
|
+
let new_info = {"name": "Jane", "age": 25, "role": "designer"}
|
|
17
|
+
let merged = store_database
|
|
18
|
+
for key in keys(new_info) {
|
|
19
|
+
merged[key] = new_info[key]
|
|
20
|
+
}
|
|
21
|
+
store_database = merged
|
|
22
|
+
print "Name:" store_database["name"]
|
|
23
|
+
print "Age:" store_database["age"]
|
|
24
|
+
print "Role:" store_database["role"]
|
|
25
|
+
try {
|
|
26
|
+
write_file("data.txt", to_json(store_database))
|
|
27
|
+
print "Database updated!"
|
|
28
|
+
} catch(error) {
|
|
29
|
+
print "Error:" error
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// USING IT FOR AI IS OPTIONAL AND NOT REQUIRED TO USE IN YOUR SCRIPTS.
|
|
33
|
+
// COMMENTED OUT BECAUSE AI WILL FORCE THEMSELVES TO RUN IT
|
|
34
|
+
|
|
35
|
+
// memory conversation {"You are a helpful programming assistant. Respond concisely."}
|
|
36
|
+
// memory conversationfn askBot(question: string) -> string {
|
|
37
|
+
// let message = conversation + "User:" + question
|
|
38
|
+
// let response = model("gemini-3.1-flash-lite") {message}
|
|
39
|
+
// conversation = message + "Assistant:" + response
|
|
40
|
+
// return response
|
|
41
|
+
//}
|
|
42
|
+
// print "Starting conversation..."
|
|
43
|
+
// let answer1 = askBot("What is a closure in JavaScript?")
|
|
44
|
+
// print "Q1 Answer:" answer1
|
|
45
|
+
// let answer2 = askBot("Can you give me an example?")
|
|
46
|
+
// print "Q2 Answer:" answer2
|
|
47
|
+
// let answer3 = askBot("How do I use it in practice?")
|
|
48
|
+
// print "Q3 Answer:" answer3
|
|
@@ -1,8 +1,63 @@
|
|
|
1
|
-
// Data classification
|
|
2
|
-
|
|
1
|
+
// Data classification
|
|
2
|
+
|
|
3
3
|
let items = ["A quick brown fox", "123 Main Street", "user@example.com", "New York City"]
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
|
|
5
|
+
fn isEmail(item: string) -> bool {
|
|
6
|
+
let parts = split(item, "@")
|
|
7
|
+
if len(parts) != 2 {
|
|
8
|
+
return false
|
|
9
|
+
}
|
|
10
|
+
let localPart = parts[0]
|
|
11
|
+
let domainPart = parts[1]
|
|
12
|
+
if len(localPart) == 0 || len(domainPart) == 0 {
|
|
13
|
+
return false
|
|
14
|
+
}
|
|
15
|
+
let domainParts = split(domainPart, ".")
|
|
16
|
+
if len(domainParts) < 2 {
|
|
17
|
+
return false
|
|
18
|
+
}
|
|
19
|
+
for part in domainParts {
|
|
20
|
+
if len(part) == 0 {
|
|
21
|
+
return false
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return true
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
fn isAddress(item: string) -> bool {
|
|
28
|
+
// Simplified check for address-like strings
|
|
29
|
+
let parts = split(item, " ")
|
|
30
|
+
// Must contain numbers and words
|
|
31
|
+
let hasNumber = false
|
|
32
|
+
let hasWord = false
|
|
33
|
+
for part in parts {
|
|
34
|
+
if num(part) != null {
|
|
35
|
+
hasNumber = true
|
|
36
|
+
} else if len(part) > 1 {
|
|
37
|
+
hasWord = true
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return hasNumber && hasWord && len(parts) >= 2
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
print "Classifying items natively:"
|
|
44
|
+
for item in items {
|
|
45
|
+
if isEmail(item) {
|
|
46
|
+
print item "-> EMAIL"
|
|
47
|
+
} else if isAddress(item) {
|
|
48
|
+
print item "-> ADDRESS"
|
|
49
|
+
} else {
|
|
50
|
+
print item "-> TEXT/LOCATION"
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// USING AI IS OPTIONAL AND NOT REQUIRED TO USE IN YOUR SCRIPTS.
|
|
55
|
+
// COMMENTED OUT BECAUSE AI WILL FORCE THEMSELVES TO RUN IT
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
// let items = ["A quick brown fox", "123 Main Street", "user@example.com", "New York City"]
|
|
59
|
+
// fn classifyItem(item: string) -> string {return model("gemini-3.1-flash-lite") {"Classify this item into one of: TEXT, ADDRESS, EMAIL, LOCATION " "Item: " item}}
|
|
60
|
+
// print "Classifying items..."
|
|
61
|
+
// for item in items
|
|
62
|
+
// {let classification = classifyItem(item)
|
|
63
|
+
// print item "->" classification}
|
|
@@ -1,35 +1,62 @@
|
|
|
1
|
-
// Comprehensive example: Reasoning-powered data pipeline
|
|
2
1
|
// This example demonstrates: Functions and control flow, Loops and arrays, Model calls with configuration, Structured output parsing, Memory for multi-step processing
|
|
3
2
|
// Data to process
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
|
|
4
|
+
let numbers = [10, 25, 30, 45, 50]
|
|
5
|
+
let threshold = 30
|
|
6
|
+
fn filterNumbers(list: array, limit: number) -> array {
|
|
7
|
+
let filtered = []
|
|
8
|
+
for n in list {
|
|
9
|
+
if n >= limit {
|
|
10
|
+
push(filtered, n)
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return filtered
|
|
14
|
+
}
|
|
15
|
+
let highNumbers = filterNumbers(numbers, threshold)
|
|
16
|
+
print "Numbers above " + threshold + ":"
|
|
17
|
+
for val in highNumbers {
|
|
18
|
+
print "- " + val
|
|
8
19
|
}
|
|
20
|
+
try {
|
|
21
|
+
write_file("results.txt", "Processed " + len(highNumbers) + " items.")
|
|
22
|
+
print "Log file created."
|
|
23
|
+
} catch(e) {
|
|
24
|
+
print "File error: " + e
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// USING AI IS OPTIONAL AND NOT REQUIRED TO USE IN YOUR SCRIPTS.
|
|
28
|
+
// COMMENTED OUT BECAUSE AI WILL FORCE THEMSELVES TO RUN IT
|
|
29
|
+
|
|
30
|
+
// let reviews = ["This product is amazing! Highly recommended.", "Terrible quality. Waste of money.", "It's okay. Nothing special.", "Love it! Best purchase ever.", "Disappointed. Poor customer service."]
|
|
31
|
+
// Function to analyze single review
|
|
32
|
+
// fn analyzeReview(review: string) -> object {
|
|
33
|
+
// return structured_output({sentiment: string, confidence: number})(model("gemini-3.1-flash-lite") {temperature: 0.3} {"Analyze sentiment. Return JSON with sentiment (positive/negative/neutral) and confidence (0-1). Review:" review})
|
|
34
|
+
// }
|
|
9
35
|
// Process all reviews
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
let
|
|
13
|
-
let
|
|
14
|
-
let
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
let
|
|
19
|
-
let
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
36
|
+
|
|
37
|
+
// print ("Processing " + len(reviews) + " reviews...")
|
|
38
|
+
// let results = []
|
|
39
|
+
// let positiveCount = 0
|
|
40
|
+
// let negativeCount = 0
|
|
41
|
+
// let neutralCount = 0
|
|
42
|
+
// for review in reviews
|
|
43
|
+
// {print "Review:" review
|
|
44
|
+
// let analysis = analyzeReview(review)
|
|
45
|
+
// let sentiment = analysis["sentiment"]
|
|
46
|
+
// let confidence = analysis["confidence"]
|
|
47
|
+
// print "Sentiment:" sentiment "Confidence:" confidence
|
|
48
|
+
// push(results, analysis)
|
|
49
|
+
// if sentiment == "positive" {positiveCount = positiveCount + 1} else if sentiment == "negative" {negativeCount = negativeCount + 1} else {neutralCount = neutralCount + 1}}
|
|
23
50
|
// Summary
|
|
24
|
-
print "=== Summary ==="
|
|
25
|
-
print "Total reviews:" len(reviews)
|
|
26
|
-
print "Positive:" positiveCount
|
|
27
|
-
print "Negative:" negativeCount
|
|
28
|
-
print "Neutral:" neutralCount
|
|
51
|
+
// print "=== Summary ==="
|
|
52
|
+
// print "Total reviews:" len(reviews)
|
|
53
|
+
// print "Positive:" positiveCount
|
|
54
|
+
// print "Negative:" negativeCount
|
|
55
|
+
// print "Neutral:" neutralCount
|
|
29
56
|
// Calculate average sentiment score
|
|
30
|
-
let totalConfidence = 0
|
|
31
|
-
for result in results {totalConfidence = totalConfidence + result["confidence"]}
|
|
32
|
-
let avgConfidence = totalConfidence / len(results)
|
|
33
|
-
print "Average confidence:" avgConfidence
|
|
57
|
+
// let totalConfidence = 0
|
|
58
|
+
// for result in results {totalConfidence = totalConfidence + result["confidence"]}
|
|
59
|
+
// let avgConfidence = totalConfidence / len(results)
|
|
60
|
+
// print "Average confidence:" avgConfidence
|
|
34
61
|
// Overall recommendation
|
|
35
|
-
if positiveCount > negativeCount {print "Overall: RECOMMENDED (more positive reviews)"} else if negativeCount > positiveCount {print "Overall: NOT RECOMMENDED (more negative reviews)"} else {print "Overall: MIXED (balanced reviews)"}
|
|
62
|
+
// if positiveCount > negativeCount {print "Overall: RECOMMENDED (more positive reviews)"} else if negativeCount > positiveCount {print "Overall: NOT RECOMMENDED (more negative reviews)"} else {print "Overall: MIXED (balanced reviews)"}
|