From cbb6859e3848852b299b5165161cb2a44a980105 Mon Sep 17 00:00:00 2001 From: Alex Komoroske Date: Sat, 12 Aug 2023 16:06:01 -0700 Subject: [PATCH] Switch back from "t" to "type". Basically a manual revert of 342ccf69a558a9a03e454169cbe490042f6abbea It was weird that "t" was the only property that wasn't typed out. And with improvements in #7 and #6 it's not as necessary. Part of #36. --- README.md | 28 +++--- schemas/config.json | 2 +- schemas/seed.json | 198 ++++++++++++++++++------------------- seeds/example-basic.json | 48 ++++----- seeds/example-complex.json | 84 ++++++++-------- seeds/example-import.json | 20 ++-- seeds/example-utility.json | 50 +++++----- src/grow.ts | 2 +- src/seed.ts | 16 +-- src/types.ts | 116 +++++++++++----------- test/base/a_test.json | 182 +++++++++++++++++----------------- test/base/b_test.json | 6 +- test/base/test.ts | 176 ++++++++++++++++----------------- 13 files changed, 464 insertions(+), 464 deletions(-) diff --git a/README.md b/README.md index c792b34..8689a73 100644 --- a/README.md +++ b/README.md @@ -107,7 +107,7 @@ Create a new file in `seeds/file.json` (you can name it whatever you want as lon }, "seeds": { "": { - "t": "log", + "type": "log", "value": "Hello, world" } } @@ -144,7 +144,7 @@ The simplest value is just a literal value, like a string, a boolean, or a numbe }, "seeds": { "": { - "t": "log", + "type": "log", "value": "Hello, world" } } @@ -161,13 +161,13 @@ But seeds can also reference other seeds: }, "seeds": { "": { - "t": "log", + "type": "log", "value": { "seed": "sub-seed" } }, "sub-seed": { - "t": "template", + "type": "template", "template": "{{name}} is {{age}}", "vars": { "name" : "Alex", @@ -194,7 +194,7 @@ You can also fetch seeds from an adjacent file: }, "seeds": { "": { - "t": "log", + "type": "log", "value": { "packet": "./other.json", "seed": "sub-seed" @@ -216,7 +216,7 @@ You can also fetch a remote packet: }, "seeds": { "": { - "t": "log", + "type": "log", "value": { "packet": "https://komoroske.com/seeds/other.json", "seed": "sub-seed" @@ -244,9 +244,9 @@ For example, this: }, "seeds": { "foo" : { - "t": "log", + "type": "log", "value": { - "t": "log", + "type": "log", "value": true } } @@ -264,13 +264,13 @@ Will unroll to this: }, "seeds": { "foo" : { - "t": "log", + "type": "log", "value": { "seed": "foo-value" } }, "foo-value": { - "t": "log", + "type": "log", "value": true } } @@ -290,9 +290,9 @@ nested seedData: }, "seeds": { "foo" : { - "t": "log", + "type": "log", "value": { - "t": "log", + "type": "log", "seed": "bar", "value": true } @@ -311,13 +311,13 @@ Yields }, "seeds": { "foo" : { - "t": "log", + "type": "log", "value": { "seed": "bar" } }, "bar": { - "t": "log", + "type": "log", "seed": "bar", "value": true } diff --git a/schemas/config.json b/schemas/config.json index fe6b80c..81e034e 100644 --- a/schemas/config.json +++ b/schemas/config.json @@ -86,7 +86,7 @@ "$ref": "#/properties/value" }, "propertyNames": { - "pattern": "^(?!t$)[a-zA-Z0-9-_.]*$" + "pattern": "^(?!type$)[a-zA-Z0-9-_.]*$" } }, { diff --git a/schemas/seed.json b/schemas/seed.json index b652d2a..4bdfb42 100644 --- a/schemas/seed.json +++ b/schemas/seed.json @@ -92,7 +92,7 @@ "$ref": "#/properties/environment/properties/value" }, "propertyNames": { - "pattern": "^(?!t$)[a-zA-Z0-9-_.]*$" + "pattern": "^(?!type$)[a-zA-Z0-9-_.]*$" } }, { @@ -130,7 +130,7 @@ { "type": "object", "properties": { - "t": { + "type": { "type": "string", "const": "prompt" }, @@ -167,7 +167,7 @@ } }, "required": [ - "t", + "type", "prompt" ], "additionalProperties": false @@ -175,7 +175,7 @@ { "type": "object", "properties": { - "t": { + "type": { "type": "string", "const": "embed" }, @@ -207,7 +207,7 @@ } }, "required": [ - "t", + "type", "text" ], "additionalProperties": false @@ -215,7 +215,7 @@ { "type": "object", "properties": { - "t": { + "type": { "type": "string", "const": "memorize" }, @@ -279,7 +279,7 @@ } }, "required": [ - "t", + "type", "value" ], "additionalProperties": false @@ -287,7 +287,7 @@ { "type": "object", "properties": { - "t": { + "type": { "type": "string", "const": "recall" }, @@ -375,14 +375,14 @@ } }, "required": [ - "t" + "type" ], "additionalProperties": false }, { "type": "object", "properties": { - "t": { + "type": { "type": "string", "const": "token_count" }, @@ -421,7 +421,7 @@ } }, "required": [ - "t", + "type", "text" ], "additionalProperties": false @@ -429,7 +429,7 @@ { "type": "object", "properties": { - "t": { + "type": { "type": "string", "const": "log" }, @@ -490,7 +490,7 @@ ] }, "propertyNames": { - "pattern": "^(?!t$)[a-zA-Z0-9-_.]*$" + "pattern": "^(?!type$)[a-zA-Z0-9-_.]*$" } }, { @@ -515,7 +515,7 @@ } }, "required": [ - "t", + "type", "value" ], "additionalProperties": false @@ -523,7 +523,7 @@ { "type": "object", "properties": { - "t": { + "type": { "type": "string", "const": "noop" }, @@ -565,7 +565,7 @@ } }, "required": [ - "t", + "type", "value" ], "additionalProperties": false @@ -573,7 +573,7 @@ { "type": "object", "properties": { - "t": { + "type": { "type": "string", "const": "if" }, @@ -647,7 +647,7 @@ } }, "required": [ - "t", + "type", "test", "then", "else" @@ -657,7 +657,7 @@ { "type": "object", "properties": { - "t": { + "type": { "type": "string", "const": "==" }, @@ -717,7 +717,7 @@ } }, "required": [ - "t", + "type", "a", "b" ], @@ -726,7 +726,7 @@ { "type": "object", "properties": { - "t": { + "type": { "type": "string", "const": "!=" }, @@ -786,7 +786,7 @@ } }, "required": [ - "t", + "type", "a", "b" ], @@ -795,7 +795,7 @@ { "type": "object", "properties": { - "t": { + "type": { "type": "string", "const": "<" }, @@ -855,7 +855,7 @@ } }, "required": [ - "t", + "type", "a", "b" ], @@ -864,7 +864,7 @@ { "type": "object", "properties": { - "t": { + "type": { "type": "string", "const": ">" }, @@ -924,7 +924,7 @@ } }, "required": [ - "t", + "type", "a", "b" ], @@ -933,7 +933,7 @@ { "type": "object", "properties": { - "t": { + "type": { "type": "string", "const": "<=" }, @@ -993,7 +993,7 @@ } }, "required": [ - "t", + "type", "a", "b" ], @@ -1002,7 +1002,7 @@ { "type": "object", "properties": { - "t": { + "type": { "type": "string", "const": ">=" }, @@ -1062,7 +1062,7 @@ } }, "required": [ - "t", + "type", "a", "b" ], @@ -1071,7 +1071,7 @@ { "type": "object", "properties": { - "t": { + "type": { "type": "string", "const": "!" }, @@ -1110,7 +1110,7 @@ } }, "required": [ - "t", + "type", "a" ], "additionalProperties": false @@ -1118,7 +1118,7 @@ { "type": "object", "properties": { - "t": { + "type": { "type": "string", "const": "+" }, @@ -1185,7 +1185,7 @@ } }, "required": [ - "t", + "type", "a" ], "additionalProperties": false @@ -1193,7 +1193,7 @@ { "type": "object", "properties": { - "t": { + "type": { "type": "string", "const": "*" }, @@ -1253,7 +1253,7 @@ } }, "required": [ - "t", + "type", "a" ], "additionalProperties": false @@ -1261,7 +1261,7 @@ { "type": "object", "properties": { - "t": { + "type": { "type": "string", "const": "/" }, @@ -1321,7 +1321,7 @@ } }, "required": [ - "t", + "type", "a", "b" ], @@ -1330,7 +1330,7 @@ { "type": "object", "properties": { - "t": { + "type": { "type": "string", "const": "render" }, @@ -1375,7 +1375,7 @@ } }, "required": [ - "t", + "type", "template", "vars" ], @@ -1384,7 +1384,7 @@ { "type": "object", "properties": { - "t": { + "type": { "type": "string", "const": "compose" }, @@ -1507,7 +1507,7 @@ } }, "required": [ - "t", + "type", "items" ], "additionalProperties": false @@ -1515,7 +1515,7 @@ { "type": "object", "properties": { - "t": { + "type": { "type": "string", "const": "extract" }, @@ -1561,7 +1561,7 @@ } }, "required": [ - "t", + "type", "template", "input" ], @@ -1570,7 +1570,7 @@ { "type": "object", "properties": { - "t": { + "type": { "type": "string", "const": "input" }, @@ -1647,7 +1647,7 @@ } }, "required": [ - "t", + "type", "question" ], "additionalProperties": false @@ -1655,7 +1655,7 @@ { "type": "object", "properties": { - "t": { + "type": { "type": "string", "const": "reference" }, @@ -1715,14 +1715,14 @@ } }, "required": [ - "t" + "type" ], "additionalProperties": false }, { "type": "object", "properties": { - "t": { + "type": { "type": "string", "const": "dynamic" }, @@ -1775,7 +1775,7 @@ } }, "required": [ - "t", + "type", "reference" ], "additionalProperties": false @@ -1783,7 +1783,7 @@ { "type": "object", "properties": { - "t": { + "type": { "type": "string", "const": "fetch" }, @@ -1906,7 +1906,7 @@ } }, "required": [ - "t", + "type", "resource" ], "additionalProperties": false @@ -1914,7 +1914,7 @@ { "type": "object", "properties": { - "t": { + "type": { "type": "string", "const": "keys" }, @@ -1956,7 +1956,7 @@ } }, "required": [ - "t", + "type", "object" ], "additionalProperties": false @@ -1964,7 +1964,7 @@ { "type": "object", "properties": { - "t": { + "type": { "type": "string", "const": "property" }, @@ -1982,7 +1982,7 @@ "$ref": "#/definitions/seedData/anyOf/5/properties/value/anyOf/2/anyOf/1/additionalProperties" }, "propertyNames": { - "pattern": "^(?!t$)[a-zA-Z0-9-_.]*$" + "pattern": "^(?!type$)[a-zA-Z0-9-_.]*$" }, "description": "The object to select a property from" } @@ -2016,7 +2016,7 @@ } }, "required": [ - "t", + "type", "object", "property" ], @@ -2037,7 +2037,7 @@ "private": { "$ref": "#/definitions/seedData/anyOf/0/properties/private" }, - "t": { + "type": { "type": "string", "const": "object" }, @@ -2062,7 +2062,7 @@ } }, "required": [ - "t", + "type", "properties" ], "additionalProperties": false @@ -2082,7 +2082,7 @@ "private": { "$ref": "#/definitions/seedData/anyOf/0/properties/private" }, - "t": { + "type": { "type": "string", "const": "array" }, @@ -2130,7 +2130,7 @@ } }, "required": [ - "t", + "type", "items" ], "additionalProperties": false @@ -2138,7 +2138,7 @@ { "type": "object", "properties": { - "t": { + "type": { "type": "string", "const": "map" }, @@ -2204,7 +2204,7 @@ } }, "required": [ - "t", + "type", "items", "block" ], @@ -2213,7 +2213,7 @@ { "type": "object", "properties": { - "t": { + "type": { "type": "string", "const": "filter" }, @@ -2279,7 +2279,7 @@ } }, "required": [ - "t", + "type", "items", "block" ], @@ -2288,7 +2288,7 @@ { "type": "object", "properties": { - "t": { + "type": { "type": "string", "const": "spread" }, @@ -2354,7 +2354,7 @@ } }, "required": [ - "t", + "type", "a", "b" ], @@ -2363,7 +2363,7 @@ { "type": "object", "properties": { - "t": { + "type": { "type": "string", "const": "index" }, @@ -2450,7 +2450,7 @@ } }, "required": [ - "t", + "type", "container", "search" ], @@ -2459,7 +2459,7 @@ { "type": "object", "properties": { - "t": { + "type": { "type": "string", "const": "slice" }, @@ -2540,7 +2540,7 @@ } }, "required": [ - "t", + "type", "input" ], "additionalProperties": false @@ -2548,7 +2548,7 @@ { "type": "object", "properties": { - "t": { + "type": { "type": "string", "const": "split" }, @@ -2601,7 +2601,7 @@ } }, "required": [ - "t", + "type", "input" ], "additionalProperties": false @@ -2609,7 +2609,7 @@ { "type": "object", "properties": { - "t": { + "type": { "type": "string", "const": "join" }, @@ -2665,7 +2665,7 @@ } }, "required": [ - "t", + "type", "items" ], "additionalProperties": false @@ -2673,7 +2673,7 @@ { "type": "object", "properties": { - "t": { + "type": { "type": "string", "const": "throw" }, @@ -2705,7 +2705,7 @@ } }, "required": [ - "t", + "type", "error" ], "additionalProperties": false @@ -2713,7 +2713,7 @@ { "type": "object", "properties": { - "t": { + "type": { "type": "string", "const": "var" }, @@ -2790,7 +2790,7 @@ } }, "required": [ - "t", + "type", "name" ], "additionalProperties": false @@ -2798,7 +2798,7 @@ { "type": "object", "properties": { - "t": { + "type": { "type": "string", "const": "random" }, @@ -2906,14 +2906,14 @@ } }, "required": [ - "t" + "type" ], "additionalProperties": false }, { "type": "object", "properties": { - "t": { + "type": { "type": "string", "const": "random-seed" }, @@ -2973,7 +2973,7 @@ } }, "required": [ - "t", + "type", "block" ], "additionalProperties": false @@ -2981,7 +2981,7 @@ { "type": "object", "properties": { - "t": { + "type": { "type": "string", "const": "let" }, @@ -3062,7 +3062,7 @@ } }, "required": [ - "t", + "type", "name", "value", "block" @@ -3072,7 +3072,7 @@ { "type": "object", "properties": { - "t": { + "type": { "type": "string", "const": "let-multi" }, @@ -3138,7 +3138,7 @@ } }, "required": [ - "t", + "type", "values", "block" ], @@ -3147,7 +3147,7 @@ { "type": "object", "properties": { - "t": { + "type": { "type": "string", "const": "function" }, @@ -3241,7 +3241,7 @@ } }, "required": [ - "t", + "type", "arguments", "block" ], @@ -3262,7 +3262,7 @@ "private": { "$ref": "#/definitions/seedData/anyOf/0/properties/private" }, - "t": { + "type": { "type": "string", "const": "call" }, @@ -3311,7 +3311,7 @@ } }, "required": [ - "t", + "type", "arguments", "function" ], @@ -3320,7 +3320,7 @@ { "type": "object", "properties": { - "t": { + "type": { "type": "string", "const": "store" }, @@ -3398,7 +3398,7 @@ } }, "required": [ - "t", + "type", "name", "value" ], @@ -3407,7 +3407,7 @@ { "type": "object", "properties": { - "t": { + "type": { "type": "string", "const": "retrieve" }, @@ -3482,7 +3482,7 @@ } }, "required": [ - "t", + "type", "name" ], "additionalProperties": false @@ -3490,7 +3490,7 @@ { "type": "object", "properties": { - "t": { + "type": { "type": "string", "const": "delete" }, @@ -3544,7 +3544,7 @@ } }, "required": [ - "t", + "type", "name" ], "additionalProperties": false @@ -3552,7 +3552,7 @@ { "type": "object", "properties": { - "t": { + "type": { "type": "string", "const": "enumerate" }, @@ -3587,7 +3587,7 @@ } }, "required": [ - "t", + "type", "resource" ], "additionalProperties": false diff --git a/seeds/example-basic.json b/seeds/example-basic.json index aea9e65..b77dcd5 100644 --- a/seeds/example-basic.json +++ b/seeds/example-basic.json @@ -2,34 +2,34 @@ "version": 0, "seeds": { "": { - "t": "prompt", + "type": "prompt", "description": "This is the default seed", "prompt": "Create a limerick about gardens." }, "hello-world": { - "t": "log", + "type": "log", "value": "Hello, world!" }, "input-example": { - "t": "input", + "type": "input", "question": "What is your name?", "default": "Bob" }, "composed-prompt": { - "t": "prompt", + "type": "prompt", "description": "This seed demonstrates a seed that references sub seeds", "prompt": { "seed": "hello-world" } }, "input-prompt": { - "t": "prompt", + "type": "prompt", "prompt": { - "t": "render", + "type": "render", "template": "Write a limerick about a person named {{name}}.", "vars": { "name": { - "t": "input", + "type": "input", "question": "What is the name to use?", "default": "Bob" } @@ -37,7 +37,7 @@ } }, "render-example": { - "t": "render", + "type": "render", "template": "{{name}} is {{age}}", "vars": { "name": "Bob", @@ -46,26 +46,26 @@ } }, "remote-example": { - "t": "log", + "type": "log", "value": { "packet": "https://raw.githubusercontent.com/jkomoros/prompt-garden/main/seeds/example-basic.json", "seed": "hello-world" } }, "nested-example": { - "t": "log", + "type": "log", "value": { "id": "nested", - "t": "log", + "type": "log", "value": 3 } }, "embed-example": { - "t": "embed", + "type": "embed", "text": "This is some text to embed" }, "memorize-example": { - "t": "memorize", + "type": "memorize", "value": [ "Apple", "Car", @@ -74,51 +74,51 @@ ] }, "recall-example": { - "t": "recall", + "type": "recall", "query": "Pear", "k": 1 }, "store-example": { - "t": "store", + "type": "store", "store": "example.com:default", "name": "foo", "value": 3 }, "retrieve-example": { - "t": "retrieve", + "type": "retrieve", "store": "example.com:default", "name": "foo" }, "delete-example": { - "t" : "delete", + "type" : "delete", "store": "example.com:default", "name": "foo" }, "token-count-example": { - "t": "token_count", + "type": "token_count", "text": "This is the text whose tokens should be counted" }, "dynamic-example": { - "t": "dynamic", + "type": "dynamic", "reference": { - "t": "reference", + "type": "reference", "seed_id": "input_prompt" } }, "fetch-example": { - "t": "fetch", + "type": "fetch", "resource": "https://raw.githubusercontent.com/jkomoros/prompt-garden/main/seeds/example-basic.json" }, "multiple-embed-example": { - "t": "array", + "type": "array", "comment": "This embeds the same text twice in a row, a test to make sure embedding caching is working", "items": [ { - "t": "embed", + "type": "embed", "text": "Hello world" }, { - "t": "embed", + "type": "embed", "text": "Hello world" } ] diff --git a/seeds/example-complex.json b/seeds/example-complex.json index 98b4abf..a769681 100644 --- a/seeds/example-complex.json +++ b/seeds/example-complex.json @@ -6,22 +6,22 @@ }, "seeds": { "favorite-things-limerick": { - "t": "let", + "type": "let", "description": "Checks if the user has stored at least one favorite thing (asking for some if they haven't), and then creates a limerick about their favorie things.", "name": "favorite_things", "value": { - "t": "recall", + "type": "recall", "query": "", "k": 20 }, "block": { - "t": "if", + "type": "if", "test": { - "t": ">", + "type": ">", "a": { - "t": "property", + "type": "property", "object": { - "t": "var", + "type": "var", "name": "favorite_things" }, "property": "length" @@ -32,11 +32,11 @@ "seed": "write-favorite-things-limerick" }, "else": { - "t": "array", + "type": "array", "return": "last", "items": [ { - "t": "log", + "type": "log", "value": "You haven't stored memories yet, so let's store a few." }, { @@ -50,21 +50,21 @@ } }, "write-favorite-things-limerick": { - "t": "let", + "type": "let", "description": "Writes a limerick about the users favorite things, retrieved from their memory.", "name": "favorite_things", "value": { - "t": "recall", + "type": "recall", "query": "", "k": 20 }, "block": { - "t": "prompt", + "type": "prompt", "prompt": { - "t": "compose", + "type": "compose", "prefix": "Here are a few of my favorite things:\n", "items": { - "t": "var", + "type": "var", "name": "favorite_things" }, "suffix": "\n\nPlease write a limerick about them." @@ -72,35 +72,35 @@ } }, "remember-favorite-things": { - "t": "let", + "type": "let", "description": "Ask the user to share their favorite things, one at a time, until they don't pass one, and store them in memory", "name": "new_favorite_thing", "value": { - "t": "input", + "type": "input", "question": "Enter a favorite thing, or hit Enter if done" }, "block": { - "t": "if", + "type": "if", "test": { - "t": "==", + "type": "==", "a": { - "t": "var", + "type": "var", "name": "new_favorite_thing" }, "b": "" }, "then": { - "t": "log", + "type": "log", "value": "OK, done adding favorite things." }, "else": { - "t": "array", + "type": "array", "return": "last", "items": [ { - "t": "memorize", + "type": "memorize", "value": { - "t": "var", + "type": "var", "name": "new_favorite_thing" } }, @@ -112,10 +112,10 @@ } }, "name-limerick":{ - "t": "prompt", + "type": "prompt", "description": "Write a limerick using the user's name (prompting them to provide one if they haven't yet)", "prompt": { - "t": "render", + "type": "render", "template": "Write a limerick about a person named {{name}}, where {{name}} is used as a rhyme.", "vars": { "name": { @@ -125,39 +125,39 @@ } }, "prompt-name": { - "t": "retrieve", + "type": "retrieve", "description": "Ask the user for their name, just returning a previously saved name if they already shared it in the past", "name": "user_first_name", "else": { - "t": "let", + "type": "let", "name": "user_first_name", "value": { - "t": "input", + "type": "input", "question": "What name should I call you?", "default": "Bob" }, "block": { - "t": "array", + "type": "array", "return": "last", "items": [ { - "t": "log", + "type": "log", "value": { - "t": "render", + "type": "render", "template": "OK, I'll call you {{name}} from now on.", "vars": { "name": { - "t": "var", + "type": "var", "name": "user_first_name" } } } }, { - "t": "store", + "type": "store", "name": "user_first_name", "value": { - "t": "var", + "type": "var", "name": "user_first_name" } } @@ -166,31 +166,31 @@ } }, "suggest-titles": { - "t": "let", + "type": "let", "name": "arg:input", "value": { - "t": "prompt", + "type": "prompt", "prompt": { - "t": "compose", + "type": "compose", "prefix": "Here are some titles of essays, one per line:\n", "items": { - "t": "map", + "type": "map", "items": { - "t": "recall", + "type": "recall", "memory": { - "t": "input", + "type": "input", "question": "Which memory to use?", "default": "polymath-import" }, "k": 50 }, "block": { - "t": "property", + "type": "property", "object": { - "t": "extract", + "type": "extract", "template": "Title:\n{{title}}\nContent:\n{{content}}", "input": { - "t": "var", + "type": "var", "name": "value" } }, diff --git a/seeds/example-import.json b/seeds/example-import.json index 1c4209e..18bc807 100644 --- a/seeds/example-import.json +++ b/seeds/example-import.json @@ -5,13 +5,13 @@ }, "seeds": { "import-polymath": { - "t": "call", + "type": "call", "arguments": { "arg:items": { "seed": "load-polymath" }, "arg:memory": { - "t": "input", + "type": "input", "question": "Which memory should the items be stored in?", "default": "polymath-import" } @@ -23,32 +23,32 @@ }, "load-polymath": { "description": "Loads bits of content from a polymath library file", - "t": "let", + "type": "let", "name": "import", "value": { - "t": "property", + "type": "property", "property": "bits", "object": { - "t": "fetch", + "type": "fetch", "resource": { - "t": "input", + "type": "input", "question": "Where is the polymath export file to load?", "default": "data/polymath_export.json" } } }, "block": { - "t": "map", + "type": "map", "items": { - "t": "var", + "type": "var", "name": "import" }, "block": { - "t": "render", + "type": "render", "template": "Title:\n{{item.info.title|default:''}}\nContent:\n{{item.text}}", "vars": { "item": { - "t": "var", + "type": "var", "name": "value" } } diff --git a/seeds/example-utility.json b/seeds/example-utility.json index 226baea..e8c73c0 100644 --- a/seeds/example-utility.json +++ b/seeds/example-utility.json @@ -2,28 +2,28 @@ "version": 0, "seeds": { "remove-numbers": { - "t": "function", + "type": "function", "arguments": [ "arg:input" ], "block": { - "t": "join", + "type": "join", "delimiter": "\n", "items": { - "t": "map", + "type": "map", "items": { - "t": "split", + "type": "split", "input": { - "t": "var", + "type": "var", "name": "arg:input" }, "delimiter": "\n" }, "block": { - "t": "call", + "type": "call", "arguments": { "arg:input": { - "t": "var", + "type": "var", "name": "value" } }, @@ -36,17 +36,17 @@ }, "remove-item-number": { "description": "Removes a possible 1) or 1. from the front of a line", - "t": "function", + "type": "function", "arguments": [ "arg:input" ], "block": { - "t": "property", + "type": "property", "object": { - "t": "extract", + "type": "extract", "template": "{{index|int|optional}}{{separator|choice:'. '|choice:') '|optional}}{{content}}", "input": { - "t": "var", + "type": "var", "name": "arg:input" } }, @@ -54,57 +54,57 @@ } }, "memorize-items": { - "t": "function", + "type": "function", "arguments": [ "arg:items", "arg:memory" ], "block": { - "t": "let", + "type": "let", "name": "length", "value": { - "t": "property", + "type": "property", "object": { - "t": "var", + "type": "var", "name": "arg:items" }, "property": "length" }, "block": { - "t": "map", + "type": "map", "items": { - "t": "var", + "type": "var", "name": "arg:items" }, "block": { - "t": "array", + "type": "array", "return": "last", "items": [ { - "t": "log", + "type": "log", "value": { - "t": "render", + "type": "render", "template": "Memorizing item {{i}}/{{length}}", "vars": { "i": { - "t": "var", + "type": "var", "name": "key" }, "length": { - "t": "var", + "type": "var", "name": "length" } } } }, { - "t": "memorize", + "type": "memorize", "memory": { - "t": "var", + "type": "var", "name": "arg:memory" }, "value": { - "t": "var", + "type": "var", "name": "value" } } diff --git a/src/grow.ts b/src/grow.ts index 464cbc3..adcace4 100644 --- a/src/grow.ts +++ b/src/grow.ts @@ -876,7 +876,7 @@ export const grow = async (seed : Seed, env : Environment) : Promise => { seed.garden.profile.log(`### Growing seed ${id}:\n\n${json}\n`); } const data = seed.data; - const typ = data.t; + const typ = data.type; let result : Value = false; switch (typ) { case 'prompt': diff --git a/src/seed.ts b/src/seed.ts index cda7992..482964e 100644 --- a/src/seed.ts +++ b/src/seed.ts @@ -130,7 +130,7 @@ const expandSeedComputedObjects = (data : D, co //We check for type in data, and not seedData.parse, because if there are //nested arrays and objects with seedData in they will fail the seedData //parse. - if ('t' in data) { + if ('type' in data) { //It's a seedData. const seed = data as SeedData; const clone = {...seed}; @@ -140,8 +140,8 @@ const expandSeedComputedObjects = (data : D, co //already of that object, we want to not add an additiona, unncessary //indrection. let comingFrom : ComingFrom = ''; - if (seed.t == 'array') comingFrom = 'array'; - if (seed.t == 'object') comingFrom = 'object'; + if (seed.type == 'array') comingFrom = 'array'; + if (seed.type == 'object') comingFrom = 'object'; let changesMade = false; for (const [key, value] of Object.entries(seed)) { //Cheating with casting to InputValue, which makes a type warning go away :shrug: @@ -173,7 +173,7 @@ const expandSeedComputedObjects = (data : D, co //We have to wrap ourselves in a type:array so the values will //actually be calculated by the engine. const result : SeedDataArray = { - t: 'array', + type: 'array', items: clone }; return [result, true, true]; @@ -198,7 +198,7 @@ const expandSeedComputedObjects = (data : D, co if (comingFrom == 'object') return [clone as SeedDataObject, true, true]; //There are computed values somewhere down beneath us so we have to be a type:object const result : SeedDataObject = { - t: 'object', + type: 'object', properties: clone }; return [result, true, true]; @@ -281,7 +281,7 @@ export class Seed { } get type() : SeedDataType { - return this.data.t; + return this.data.type; } get private() : boolean { @@ -307,7 +307,7 @@ export class Seed { result[key] = makeAbsolute(ref, this.location); } const data = this.data; - if (data.t == 'array') { + if (data.type == 'array') { if (!seedReference.safeParse(data.items).success) { //array is not a direct seed reference so recurse into it for (const [i, value] of data.items.entries()) { @@ -319,7 +319,7 @@ export class Seed { } } } - if (data.t == 'object') { + if (data.type == 'object') { if (!seedReference.safeParse(data.properties).success) { //object is not a direct seed reference so recurse into it for (const [key, value] of Object.entries(data.properties)) { diff --git a/src/types.ts b/src/types.ts index 169c154..7816ace 100644 --- a/src/types.ts +++ b/src/types.ts @@ -43,7 +43,7 @@ const genericIDExtraRegExp = new RegExp('[a-zA-Z0-9-_.]*'); const genericExtraID = z.string().regex(absoluteRegExp(genericIDExtraRegExp)); -const nonTypeRegExp = new RegExp('(?!t$)'); +const nonTypeRegExp = new RegExp('(?!type$)'); const nonTypeKey = z.string().regex(absoluteRegExp(new RegExp(nonTypeRegExp.source + genericIDExtraRegExp.source))); @@ -343,7 +343,7 @@ const makeNestedSeedReferenceProperty = (input : R) => { }; type SeedDataConfiguration, Shape extends z.ZodRawShape> = { - t: Kind, + type: Kind, properties: Shape }; @@ -359,7 +359,7 @@ const makeNestedSeedData = , Shape extends z.Z //This problem is tracked in #16. const modifiedProperties = Object.fromEntries(entries) as {[k in keyof Shape] : z.ZodUnion<[typeof seedReference, Shape[k]]>}; return z.object({ - t: config.t, + type: config.type, }).extend( modifiedProperties //We do the seedDataBase last so the common properties show up last in the autocomplete list. @@ -370,7 +370,7 @@ const makeSeedData = , Shape extends z.ZodRawS const entries = TypedObject.entries(config.properties).map(entry => [entry[0], makeSeedReferenceProperty(entry[1])]); const modifiedProperties = Object.fromEntries(entries) as {[k in keyof Shape] : z.ZodUnion<[typeof seedReference, Shape[k]]>}; return z.object({ - t: config.t, + type: config.type, }).extend( modifiedProperties //We do the seedDataBase last so the common properties show up last in the autocomplete list. @@ -384,7 +384,7 @@ const makeSeedData = , Shape extends z.ZodRawS */ const seedDataConfigPrompt = { - t: z.literal('prompt'), + type: z.literal('prompt'), properties: { prompt: z.string().describe('The full prompt to be passed to the configured commpletion_model') } @@ -396,7 +396,7 @@ const seedDataPrompt = makeSeedData(seedDataConfigPrompt); export type SeedDataPrompt = z.infer; const seedDataConfigEmbed = { - t: z.literal('embed'), + type: z.literal('embed'), properties: { text: z.string().describe('The full text to be embedded') } @@ -414,7 +414,7 @@ const textOrArray = z.union([ const seedDataConfigMemorize = { - t: z.literal('memorize'), + type: z.literal('memorize'), properties: { value: textOrArray.describe('Either a pre-computed embedding or text to be converted to a memory'), memory: memoryID.optional().describe('The name of the memory to use. If not provided, defaults to environment.memory') @@ -427,7 +427,7 @@ const seedDataMemorize = makeSeedData(seedDataConfigMemorize); export type SeedDataMemorize = z.infer; const seedDataConfigRecall = { - t: z.literal('recall'), + type: z.literal('recall'), properties: { query: textOrArray.optional().describe('Either a pre-computed embedding or text to be used as a query'), k: z.number().int().optional().describe('The number of results to return'), @@ -441,7 +441,7 @@ const seedDataRecall = makeSeedData(seedDataConfigRecall); export type SeedDataRecall = z.infer; const seedDataConfigTokenCount = { - t: z.literal('token_count'), + type: z.literal('token_count'), properties: { text: textOrArray.describe('Either a pre-computed embedding or text to count the tokens in'), } @@ -453,7 +453,7 @@ const seedDataTokenCount = makeSeedData(seedDataConfigTokenCount); export type SeedDataTokenCount = z.infer; const seedDataConfigLog = { - t: z.literal('log'), + type: z.literal('log'), properties: { value: inputValue.describe('The message to echo back') } @@ -465,7 +465,7 @@ const seedDataLog = makeSeedData(seedDataConfigLog); export type SeedDataLog = z.infer; const seedDataConfigNoop = { - t: z.literal('noop'), + type: z.literal('noop'), properties: { value: inputValue.describe('The value to return') } @@ -477,7 +477,7 @@ const seedDataNoop = makeSeedData(seedDataConfigNoop); export type SeedDataNoop = z.infer; const seedDataConfigIf = { - t: z.literal('if'), + type: z.literal('if'), properties: { test: z.boolean().describe('The value to examine'), then: inputNonObjectValue.describe('The value to return if the value of test is truthy'), @@ -491,7 +491,7 @@ const seedDataIf = makeSeedData(seedDataConfigIf); export type SeedDataIf = z.infer; const seedDataConfigEqual = { - t: z.literal('=='), + type: z.literal('=='), properties: { a: inputNonObjectValue.describe('The left hand side to compare'), b: inputNonObjectValue.describe('The right hand side to compare') @@ -504,7 +504,7 @@ const seedDataEqual = makeSeedData(seedDataConfigEqual); export type SeedDataEqual = z.infer; const seedDataConfigNotEqual = { - t: z.literal('!='), + type: z.literal('!='), properties: { a: inputNonObjectValue.describe('The left hand side to compare'), b: inputNonObjectValue.describe('The right hand side to compare') @@ -517,7 +517,7 @@ const seedDataNotEqual = makeSeedData(seedDataConfigNotEqual); export type SeedDataNotEqual = z.infer; const seedDataConfigLessThan = { - t: z.literal('<'), + type: z.literal('<'), properties: { a: inputNonObjectValue.describe('The left hand side to compare'), b: inputNonObjectValue.describe('The right hand side to compare') @@ -530,7 +530,7 @@ const seedDataLessThan = makeSeedData(seedDataConfigLessThan); export type SeedDataLessThan = z.infer; const seedDataConfigGreaterThan = { - t: z.literal('>'), + type: z.literal('>'), properties: { a: inputNonObjectValue.describe('The left hand side to compare'), b: inputNonObjectValue.describe('The right hand side to compare') @@ -543,7 +543,7 @@ const seedDataGreaterThan = makeSeedData(seedDataConfigGreaterThan); export type SeedDataGreaterThan = z.infer; const seedDataConfigLessThanOrEqualTo = { - t: z.literal('<='), + type: z.literal('<='), properties: { a: inputNonObjectValue.describe('The left hand side to compare'), b: inputNonObjectValue.describe('The right hand side to compare') @@ -556,7 +556,7 @@ const seedDataLessThanOrEqualTo = makeSeedData(seedDataConfigLessThanOrEqualTo); export type SeedDataLessThanOrEqualTo = z.infer; const seedDataConfigGreaterThanOrEqualTo = { - t: z.literal('>='), + type: z.literal('>='), properties: { a: inputNonObjectValue.describe('The left hand side to compare'), b: inputNonObjectValue.describe('The right hand side to compare') @@ -569,7 +569,7 @@ const seedDataGreaterThanOrEqualTo = makeSeedData(seedDataConfigGreaterThanOrEqu export type SeedDataGreaterThanOrEqualTo = z.infer; const seedDataConfigNot = { - t: z.literal('!'), + type: z.literal('!'), properties: { a: inputNonObjectValue.describe('The left hand side to negate'), } @@ -581,7 +581,7 @@ const seedDataNot = makeSeedData(seedDataConfigNot); export type SeedDataNot = z.infer; const seedDataConfigAdd = { - t: z.literal('+'), + type: z.literal('+'), properties: { a: inputNonObjectValue.describe('The left hand side'), b: inputNonObjectValue.optional().describe('The right hand side') @@ -594,7 +594,7 @@ const seedDataAdd = makeSeedData(seedDataConfigAdd); export type SeedDataAdd = z.infer; const seedDataConfigMultiply = { - t: z.literal('*'), + type: z.literal('*'), properties: { a: inputNonObjectValue.describe('The left hand side'), b: inputNonObjectValue.optional().describe('The right hand side') @@ -607,7 +607,7 @@ const seedDataMultiply = makeSeedData(seedDataConfigMultiply); export type SeedDataMultiply = z.infer; const seedDataConfigDivide = { - t: z.literal('/'), + type: z.literal('/'), properties: { a: inputNonObjectValue.describe('The left hand side'), b: inputNonObjectValue.describe('The right hand side') @@ -620,7 +620,7 @@ const seedDataDivide = makeSeedData(seedDataConfigDivide); export type SeedDataDivide = z.infer; const seedDataConfigRender = { - t: z.literal('render'), + type: z.literal('render'), properties: { template: z.string().describe('The template string to replace {{ vars }} in '), vars: inputValueObject @@ -633,7 +633,7 @@ const seedDataRender = makeSeedData(seedDataConfigRender); export type SeedDataRender = z.infer; const seedDataConfigCompose = { - t: z.literal('compose'), + type: z.literal('compose'), properties: { prefix: z.string().optional().describe('The prefix to the prompt to use'), suffix: z.string().optional().describe('The suffix to the prompt to include'), @@ -649,7 +649,7 @@ const seedDataCompose = makeSeedData(seedDataConfigCompose); export type SeedDataCompose = z.infer; const seedDataConfigExtract = { - t: z.literal('extract'), + type: z.literal('extract'), properties: { template: z.string().describe('The template string to extract {{ vars }} from'), input: z.string().describe('The string to match against the template') @@ -662,7 +662,7 @@ const seedDataExtract = makeSeedData(seedDataConfigExtract); export type SeedDataExtract = z.infer; const seedDataConfigInput = { - t: z.literal('input'), + type: z.literal('input'), properties: { question: z.string().describe('The question to ask the user'), default: z.string().optional().describe('The value to use as default if the user doesn\'t provide anything else'), @@ -676,7 +676,7 @@ const seedDataInput = makeSeedData(seedDataConfigInput); export type SeedDataInput = z.infer; const seedDataConfigReference = { - t: z.literal('reference'), + type: z.literal('reference'), properties: { //Note this has to not be `seed` so other machinery doesn't think this is a seed reference. seed_id: z.string().optional().describe('The id of the seed to include in the reference'), @@ -690,7 +690,7 @@ const seedDataReference = makeSeedData(seedDataConfigReference); export type SeedDataReference = z.infer; const seedDataConfigDynamic = { - t: z.literal('dynamic'), + type: z.literal('dynamic'), properties: { reference: z.string().describe('The packed ID of the seed to reference'), allow_remote: z.boolean().optional().describe('If true, then remote seed fetches will be allowed') @@ -717,7 +717,7 @@ export const fetchFormat = z.union([ export type FetchFormat = z.infer; const seedDataConfigFetch = { - t: z.literal('fetch'), + type: z.literal('fetch'), properties: { resource: seedPacketLocation.describe('The URL of the resource to fetch'), method: fetchMethod.optional().describe('The method (default GET)'), @@ -732,7 +732,7 @@ const seedDataFetch = makeSeedData(seedDataConfigFetch); export type SeedDataFetch = z.infer; const seedDataConfigKeys = { - t: z.literal('keys'), + type: z.literal('keys'), properties: { object: inputValue.describe('The object whose keys to take') } @@ -744,7 +744,7 @@ const seedDataKeys = makeSeedData(seedDataConfigKeys); export type SeedDataKeys = z.infer; const seedDataConfigProperty = { - t: z.literal('property'), + type: z.literal('property'), properties: { object: inputValueObject.describe('The object to select a property from'), property: z.string().describe('The property to extract') @@ -760,14 +760,14 @@ export type SeedDataProperty = z.infer; //Object is special in that even sub-keys of a property might need to be //computed, so handle its definition manually. const seedDataObject = seedDataBase.extend({ - t: z.literal('object'), + type: z.literal('object'), properties: z.record(genericExtraID, makeSeedReferenceProperty(inputValue)) }); const lazySeedData = z.lazy(() => seedData) as never; export const nestedSeedDataObject = seedDataBase.extend({ - t: z.literal('object'), + type: z.literal('object'), properties: z.record(namedspacedID, z.union([ lazySeedData, seedReference, @@ -784,13 +784,13 @@ const arrayReturn = arrayReturnType.optional().describe('Which items to return') //Aray is special in that even sub-keys of a property might need to be //computed, so handle its definition manually. const seedDataArray = seedDataBase.extend({ - t: z.literal('array'), + type: z.literal('array'), items: z.array(makeSeedReferenceProperty(inputValue)), return: arrayReturn }); export const nestedSeedDataArray = seedDataBase.extend({ - t: z.literal('array'), + type: z.literal('array'), items: z.array(z.union([ lazySeedData, seedReference, @@ -806,7 +806,7 @@ export const nestedSeedDataArray = seedDataBase.extend({ export type SeedDataArray = z.infer; const seedDataConfigMap = { - t: z.literal('map'), + type: z.literal('map'), properties: { items: inputValue.describe('The items to iterate over'), block: inputValue.describe('The statement to execute for each item') @@ -819,7 +819,7 @@ const seedDataMap = makeSeedData(seedDataConfigMap); export type SeedDataMap = z.infer; const seedDataConfigFilter = { - t: z.literal('filter'), + type: z.literal('filter'), properties: { items: inputValue.describe('The items to iterate over'), block: inputValue.describe('The statement to execute for each item') @@ -832,7 +832,7 @@ const seedDataFilter = makeSeedData(seedDataConfigFilter); export type SeedDataFilter = z.infer; const seedDataConfigSpread = { - t: z.literal('spread'), + type: z.literal('spread'), properties: { a: inputValue.describe('The first part'), b: inputValue.describe('The second part') @@ -845,7 +845,7 @@ const seedDataSpread = makeSeedData(seedDataConfigSpread); export type SeedDataSpread = z.infer; const seedDataConfigIndex = { - t: z.literal('index'), + type: z.literal('index'), properties: { container: inputValue.describe('The thing to search within'), search: inputValue.describe('The thing to search for'), @@ -859,7 +859,7 @@ const seedDataIndex = makeSeedData(seedDataConfigIndex); export type SeedDataIndex = z.infer; const seedDataConfigSlice = { - t: z.literal('slice'), + type: z.literal('slice'), properties: { input: z.union([z.string(), inputValueArray]).describe('The thing to slice'), start: z.number().int().optional().describe('The index to start from'), @@ -873,7 +873,7 @@ const seedDataSlice = makeSeedData(seedDataConfigSlice); export type SeedDataSlice = z.infer; const seedDataConfigSplit = { - t: z.literal('split'), + type: z.literal('split'), properties: { input: z.string().describe('The string to split'), delimiter: z.string().optional().describe('The delimiter to use') @@ -886,7 +886,7 @@ const seedDataSplit = makeSeedData(seedDataConfigSplit); export type SeedDataSplit = z.infer; const seedDataConfigJoin = { - t: z.literal('join'), + type: z.literal('join'), properties: { items: inputValueArray.describe('The array to join'), delimiter: z.string().optional().describe('The delimiter to use') @@ -899,7 +899,7 @@ const seedDataJoin = makeSeedData(seedDataConfigJoin); export type SeedDataJoin = z.infer; const seedDataConfigThrow = { - t: z.literal('throw'), + type: z.literal('throw'), properties: { error: z.string().describe('The message to show') } @@ -911,7 +911,7 @@ const seedDataThrow = makeSeedData(seedDataConfigThrow); export type SeedDataThrow = z.infer; const seedDataConfigVar = { - t: z.literal('var'), + type: z.literal('var'), properties: { name: varName.describe('The name of the variable in environment to fetch'), else: inputValue.optional().describe('The sub-expression to execute to get a value if value is undefined'), @@ -933,7 +933,7 @@ export const roundType = z.union([ export type RoundType = z.infer; const seedDataConfigRandom = { - t: z.literal('random'), + type: z.literal('random'), properties: { min: z.number().optional().describe('An optional lower bound, defaults to 0.0'), max: z.number().optional().describe('An optional upper bound, defaults to 1.0'), @@ -948,7 +948,7 @@ const seedDataRandom = makeSeedData(seedDataConfigRandom); export type SeedDataRandom = z.infer; const seedDataConfigRandomSeed = { - t: z.literal('random-seed'), + type: z.literal('random-seed'), properties: { seed: z.string().optional().describe('The seed to use for random sub-seeds within block'), block: inputNonObjectValue.describe('The sub-expressions in which the random seed will be changed') @@ -961,7 +961,7 @@ const seedDataRandomSeed = makeSeedData(seedDataConfigRandomSeed); export type SeedDataRandomSeed = z.infer; const seedDataConfigLet = { - t: z.literal('let'), + type: z.literal('let'), properties: { name: varName.describe('The name of the variable in environment to set'), value: inputNonObjectValue.describe('The value to set the named variable to'), @@ -975,7 +975,7 @@ const seedDataLet = makeSeedData(seedDataConfigLet); export type SeedDataLet = z.infer; const seedDataConfigLetMulti = { - t: z.literal('let-multi'), + type: z.literal('let-multi'), properties: { values: z.record(varName, z.union([ lazySeedData, @@ -998,7 +998,7 @@ const functionArguments = z.record(argVarName, z.union([ ])); const seedDataConfigFunction = { - t: z.literal('function'), + type: z.literal('function'), properties: { arguments: z.array(argVarName).describe('The map of name -> variables to set'), defaults: functionArguments.optional().describe('A map of varName to the default value'), @@ -1014,13 +1014,13 @@ export type SeedDataFunction = z.infer; const seedDataCallArguments = functionArguments.describe('The map of name -> variables to set'); const seedDataCall = seedDataBase.extend({ - t: z.literal('call'), + type: z.literal('call'), arguments: makeSeedReferenceProperty(seedDataCallArguments), function: seedReference.describe('The function to call') }); export const nestedSeedDataCall = seedDataBase.extend({ - t: z.literal('call'), + type: z.literal('call'), arguments: z.union([ lazySeedData, seedReference, @@ -1032,7 +1032,7 @@ export const nestedSeedDataCall = seedDataBase.extend({ export type SeedDataCall = z.infer; const seedDataConfigStore = { - t: z.literal('store'), + type: z.literal('store'), properties: { store: storeID.optional().describe('The store ID to use'), name: storeKey.describe('The name of the variable in environment to store'), @@ -1046,7 +1046,7 @@ const seedDataStore = makeSeedData(seedDataConfigStore); export type SeedDataStore = z.infer; const seedDataConfigRetrieve = { - t: z.literal('retrieve'), + type: z.literal('retrieve'), properties: { store: storeID.optional().describe('The store ID to use'), name: storeKey.describe('The name of the variable in environment to retrieve'), @@ -1060,7 +1060,7 @@ const seedDataRetrieve = makeSeedData(seedDataConfigRetrieve); export type SeedDataRetrieve = z.infer; const seedDataConfigDelete = { - t: z.literal('delete'), + type: z.literal('delete'), properties: { store: storeID.optional().describe('The store ID to use'), name: storeKey.describe('The name of the variable in environment to delete'), @@ -1078,7 +1078,7 @@ export const enumerateResourceType = z.union([ ]); const seedDataConfigEnumerate = { - t: z.literal('enumerate'), + type: z.literal('enumerate'), properties: { resource : enumerateResourceType } @@ -1095,7 +1095,7 @@ export type SeedDataEnumerate = z.infer; * */ -export const expandedSeedData = z.discriminatedUnion('t', [ +export const expandedSeedData = z.discriminatedUnion('type', [ seedDataPrompt, seedDataEmbed, seedDataMemorize, @@ -1148,7 +1148,7 @@ export const expandedSeedData = z.discriminatedUnion('t', [ export type ExpandedSeedData = z.infer; -export const seedData = z.discriminatedUnion('t', [ +export const seedData = z.discriminatedUnion('type', [ nestedSeedDataPrompt, nestedSeedDataEmbed, nestedSeedDataMemorize, @@ -1203,7 +1203,7 @@ export const seedData = z.discriminatedUnion('t', [ //recursive nesting type. See the comment in makeNestedSeedData, issue #16. export type SeedData = z.infer; -export type SeedDataType = ExpandedSeedData['t']; +export type SeedDataType = ExpandedSeedData['type']; export const expandedSeedPacket = z.object({ version: z.literal(0), diff --git a/test/base/a_test.json b/test/base/a_test.json index f3c7243..5762fc6 100644 --- a/test/base/a_test.json +++ b/test/base/a_test.json @@ -2,30 +2,30 @@ "version": 0, "seeds": { "": { - "t": "prompt", + "type": "prompt", "prompt": "Create a limerick about gardens." }, "hello-world": { - "t": "log", + "type": "log", "value": "Hello, world!" }, "composed-prompt": { - "t": "prompt", + "type": "prompt", "description": "Tests that a reference with a # works", "prompt": { "seed": "hello-world" } }, "true": { - "t": "log", + "type": "log", "value": true }, "false": { - "t": "log", + "type": "log", "value": false }, "if-true": { - "t": "if", + "type": "if", "test": { "seed": "true" }, @@ -37,7 +37,7 @@ } }, "if-false": { - "t": "if", + "type": "if", "test": { "seed": "false" }, @@ -49,7 +49,7 @@ } }, "render-test": { - "t": "render", + "type": "render", "template": "{{name}} is {{age}}", "vars": { "name": "Bob", @@ -57,52 +57,52 @@ } }, "extract-test": { - "t": "extract", + "type": "extract", "template": "{{name}} is {{age}}", "input": "Alex is 5" }, "non-computed-object": { - "t": "object", + "type": "object", "properties": { "a": 5, "b": true } }, "computed-object": { - "t": "object", + "type": "object", "properties": { "a": { - "t": "log", + "type": "log", "value": 5 }, "b": true } }, "computed-array": { - "t": "array", + "type": "array", "items": [ 3, { - "t": "log", + "type": "log", "value": 5 } ] }, "let-test": { - "t": "let", + "type": "let", "name": "foo", "value": { - "t": "log", + "type": "log", "value": 3 }, "block": { - "t": "render", + "type": "render", "template": "{{age}} is great", "vars": { - "t": "object", + "type": "object", "properties": { "age": { - "t": "var", + "type": "var", "name": "foo" } } @@ -110,29 +110,29 @@ } }, "let-multi-test": { - "t": "let-multi", + "type": "let-multi", "values": { - "t": "object", + "type": "object", "properties": { "name": "Alex", "foo": { - "t": "log", + "type": "log", "value": 3 } } }, "block": { - "t": "render", + "type": "render", "template": "{{age}} is {{name}}", "vars": { - "t": "object", + "type": "object", "properties": { "age": { - "t": "var", + "type": "var", "name": "foo" }, "name": { - "t": "var", + "type": "var", "name": "name" } } @@ -140,21 +140,21 @@ } }, "let-test-secret-key": { - "t": "let", + "type": "let", "name": "openai_secret_key", "value": 5, "block": 5 }, "embed-test": { - "t": "embed", + "type": "embed", "text": "This is text to embed" }, "memorize-test": { - "t": "memorize", + "type": "memorize", "value": "Apple" }, "memorize-multiple-test": { - "t": "memorize", + "type": "memorize", "value": [ "Apple", "Carrot", @@ -163,205 +163,205 @@ ] }, "recall-test": { - "t": "recall", + "type": "recall", "query": "Broccoli", "k": 5 }, "recall-test-no-k": { - "t": "recall", + "type": "recall", "query": "Broccoli" }, "embedding-as-string": { - "t": "render", + "type": "render", "template": { - "t": "embed", + "type": "embed", "text": "This is an embedding" }, "vars": {} }, "token-count-test": { - "t": "token_count", + "type": "token_count", "text": "abcdefgh" }, "token-count-multiple-test": { - "t": "token_count", + "type": "token_count", "text": [ "abcd", "abcdefgh" ] }, "store-test": { - "t": "store", + "type": "store", "name": "foo", "value": 3 }, "retrieve-test": { - "t": "retrieve", + "type": "retrieve", "name": "foo" }, "delete-test": { - "t": "delete", + "type": "delete", "name": "foo" }, "private": { - "t": "noop", + "type": "noop", "private": true, "value": true }, "reference-test": { - "t": "reference", + "type": "reference", "seed_id": "private" }, "dynamic-test": { - "t": "dynamic", + "type": "dynamic", "reference": { - "t": "reference", + "type": "reference", "seed_id": "private" } }, "dynamic-remote-test": { - "t": "dynamic", + "type": "dynamic", "reference": { - "t": "reference", + "type": "reference", "packet": "https://raw.githubusercontent.com/jkomoros/prompt-garden/main/seeds/example-basic.json", "seed_id": "private" } }, "keys-test": { - "t": "keys", + "type": "keys", "object": [ "a", "b" ] }, "map-object-test": { - "t": "map", + "type": "map", "items": { "a": 3, "b": 4 }, "block": { - "t": "render", + "type": "render", "template": "{{key}}:{{value}}", "vars": { "key": { - "t": "var", + "type": "var", "name": "key" }, "value": { - "t": "var", + "type": "var", "name": "value" } } } }, "map-array-test": { - "t": "map", + "type": "map", "items": [ 3, 4 ], "block": { - "t": "render", + "type": "render", "template": "{{key}}:{{value}}", "vars": { "key": { - "t": "var", + "type": "var", "name": "key" }, "value": { - "t": "var", + "type": "var", "name": "value" } } } }, "filter-object-test": { - "t": "filter", + "type": "filter", "items": { "a": 3, "b": 4 }, "block": { - "t": "==", + "type": "==", "a": { - "t": "var", + "type": "var", "name": "value" }, "b": 3 } }, "filter-array-test": { - "t": "filter", + "type": "filter", "items": [ 3, 4 ], "block": { - "t": "==", + "type": "==", "a": { - "t": "var", + "type": "var", "name": "value" }, "b": 3 } }, "throw-test": { - "t": "throw", + "type": "throw", "error": "This is an error" }, "var-with-value-set": { - "t": "let", + "type": "let", "name": "val", "value": 3, "block": { - "t": "var", + "type": "var", "name": "val", "else": { - "t": "throw", + "type": "throw", "error": "This shouldn't happen since val is set" } } }, "var-without-value-set": { - "t": "var", + "type": "var", "name": "val", "else": 5 }, "retrieve-with-value-set": { - "t": "array", + "type": "array", "return": "last", "items": [ { - "t": "store", + "type": "store", "name": "val", "value": 3 }, { - "t": "retrieve", + "type": "retrieve", "name": "val", "else": { - "t": "throw", + "type": "throw", "error": "This shouldn't happen since val is set" } } ] }, "retrieve-without-value-set": { - "t": "retrieve", + "type": "retrieve", "name": "val", "else": 5 }, "random-test": { - "t": "random" + "type": "random" }, "split-test": { - "t": "split", + "type": "split", "input": "one:two", "delimiter": ":" }, "join-test": { - "t": "join", + "type": "join", "items": [ "one", "two" @@ -369,7 +369,7 @@ "delimiter": ":" }, "dotted-property-test": { - "t": "property", + "type": "property", "object": { "a": [ 0, @@ -380,25 +380,25 @@ "property": "a.1" }, "fetch-test": { - "t": "fetch", + "type": "fetch", "resource": "https://raw.githubusercontent.com/jkomoros/prompt-garden/main/seeds/example-basic.json", "method": "POST" }, "function-test": { - "t": "function", + "type": "function", "arguments": [ "arg:message" ], "block": { - "t": "log", + "type": "log", "value": { - "t": "var", + "type": "var", "name": "arg:message" } } }, "function-with-defaults-test": { - "t": "function", + "type": "function", "arguments": [ "arg:message" ], @@ -406,15 +406,15 @@ "arg:message": "Blammo" }, "block": { - "t": "log", + "type": "log", "value": { - "t": "var", + "type": "var", "name": "arg:message" } } }, "call-test": { - "t": "call", + "type": "call", "function": { "seed": "function-test" }, @@ -423,21 +423,21 @@ } }, "call-without-arg-test": { - "t": "call", + "type": "call", "function": { "seed": "function-test" }, "arguments": {} }, "call-default-test": { - "t": "call", + "type": "call", "function": { "seed": "function-with-defaults-test" }, "arguments": {} }, "spread-array-test": { - "t": "spread", + "type": "spread", "a": [ 0, 1 @@ -445,7 +445,7 @@ "b": 2 }, "spread-object-test": { - "t": "spread", + "type": "spread", "a": { "a": 0, "b": 1 @@ -455,12 +455,12 @@ } }, "index-string-test": { - "t": "index", + "type": "index", "container": "foobar", "search": "bar" }, "index-object-test": { - "t": "index", + "type": "index", "container": { "a": 0, "b": 1 @@ -468,7 +468,7 @@ "search": 1 }, "index-array-test": { - "t": "index", + "type": "index", "container": [ 0, 1, @@ -477,11 +477,11 @@ "search": 1 }, "slice-string-test": { - "t": "slice", + "type": "slice", "input": "012345" }, "slice-array-test": { - "t": "slice", + "type": "slice", "input": [ 0, 1, diff --git a/test/base/b_test.json b/test/base/b_test.json index 4d3efd1..397ca6d 100644 --- a/test/base/b_test.json +++ b/test/base/b_test.json @@ -2,18 +2,18 @@ "version": 0, "seeds": { "": { - "t": "log", + "type": "log", "value": "test-other hello world" }, "remote-ref": { - "t": "log", + "type": "log", "value": { "packet": "./a_test.json", "seed": "true" } }, "private-remote-ref": { - "t": "noop", + "type": "noop", "description": "This should fail becuase private is not public", "value": { "packet": "./a_test.json", diff --git a/test/base/test.ts b/test/base/test.ts index d029086..7b1c275 100644 --- a/test/base/test.ts +++ b/test/base/test.ts @@ -116,7 +116,7 @@ describe('Garden smoke test', () => { const garden = loadTestGarden(); const seed = await garden.seed(); //Checking type and throwing narrows type - if (seed.data.t != 'prompt') throw new Error('Unexpected type'); + if (seed.data.type != 'prompt') throw new Error('Unexpected type'); const result = await seed.grow(); if (typeof seed.data.prompt != 'string') throw new Error('Expected a direct string'); const golden = mockedResult(seed.data.prompt); @@ -127,7 +127,7 @@ describe('Garden smoke test', () => { const garden = loadTestGarden(); const seed = await garden.seed('hello-world'); //Checking type and throwing narrows type - if (seed.data.t != 'log') throw new Error('Unexpected type'); + if (seed.data.type != 'log') throw new Error('Unexpected type'); const result = await seed.grow(); const golden = 'Hello, world!'; assert.deepEqual(result, golden); @@ -148,7 +148,7 @@ describe('Garden smoke test', () => { const garden = loadTestGarden(); const seed = await garden.seed('composed-prompt'); const hellowWorldSeed = await garden.seed('hello-world'); - if (hellowWorldSeed.data.t != 'log') throw new Error('Unexpected type'); + if (hellowWorldSeed.data.type != 'log') throw new Error('Unexpected type'); if (typeof hellowWorldSeed.data.value != 'string') throw new Error('Expected a non-computed message'); const result = await seed.grow(); const golden = mockedResult(hellowWorldSeed.data.value); @@ -239,7 +239,7 @@ describe('Garden smoke test', () => { const garden = loadTestGarden(); assert.doesNotThrow(() => { garden.plantSeed({packet: '', seed: 'blammo'}, { - 't': 'log', + 'type': 'log', 'value': true, 'id': 'blammo' }); @@ -250,7 +250,7 @@ describe('Garden smoke test', () => { const garden = loadTestGarden(); assert.throws(() => { garden.plantSeed({packet: '', seed: 'slammo'}, { - 't': 'log', + 'type': 'log', 'value': true, 'id': 'blammo' }); @@ -266,9 +266,9 @@ describe('Garden smoke test', () => { version: 0, seeds: { '': { - 't': 'log', + 'type': 'log', 'value': { - 't': 'log', + 'type': 'log', 'value': true } } @@ -290,10 +290,10 @@ describe('Garden smoke test', () => { version: 0, seeds: { '': { - 't': 'log', + 'type': 'log', 'value': { 'id': 'foo', - 't': 'log', + 'type': 'log', 'value': true } } @@ -315,10 +315,10 @@ describe('Garden smoke test', () => { version: 0, seeds: { '': { - 't': 'log', + 'type': 'log', 'value': { 'id': '', - 't': 'log', + 'type': 'log', 'value': true } } @@ -552,7 +552,7 @@ describe('Garden smoke test', () => { it ('testing compose seed basic', async () => { const garden = loadTestGarden(); const seedData : SeedDataCompose = { - t: 'compose', + type: 'compose', prefix: 'Prefix', suffix: 'Suffix', items: [ @@ -575,7 +575,7 @@ Suffix`; it ('testing compose seed short max tokens', async () => { const garden = loadTestGarden(); const seedData : SeedDataCompose = { - t: 'compose', + type: 'compose', prefix: 'Prefix', suffix: 'Suffix', items: [ @@ -598,7 +598,7 @@ Suffix`; it ('testing compose seed negative max tokens', async () => { const garden = loadTestGarden(); const seedData : SeedDataCompose = { - t: 'compose', + type: 'compose', prefix: 'Prefix', suffix: 'Suffix', items: [ @@ -625,13 +625,13 @@ Suffix`; 'version': 0, 'seeds': { 'foo': { - 't': 'var', + 'type': 'var', 'name': { 'seed': 'bar-typo' } }, 'bar': { - 't': 'noop', + 'type': 'noop', 'value': 'hello, world' } } @@ -650,7 +650,7 @@ Suffix`; }, seeds: { 'env-test': { - t: 'var', + type: 'var', name: 'komoroske.com:test' } } @@ -671,11 +671,11 @@ Suffix`; }, seeds: { 'env-test': { - t: 'var', + type: 'var', name: 'komoroske.com:test' }, 'other-test': { - t: 'let', + type: 'let', name: 'komoroske.com:test', value: 5, block: { @@ -701,20 +701,20 @@ Suffix`; }, seeds: { 'env-test': { - t: 'array', + type: 'array', items: [ { - t: 'var', + type: 'var', name: 'komoroske.com:test' }, { - t: 'var', + type: 'var', name: 'komoroske.com:other' } ] }, 'other-test': { - t: 'let', + type: 'let', name: 'komoroske.com:other', value: 5, block: { @@ -742,7 +742,7 @@ Suffix`; }, seeds: { 'other-test': { - t: 'var', + type: 'var', name: 'foo' } } @@ -764,7 +764,7 @@ Suffix`; }, seeds: { 'other-test': { - t: 'store', + type: 'store', name: 'foo', value: 3 } @@ -786,7 +786,7 @@ Suffix`; }, seeds: { 'other-test': { - t: 'memorize', + type: 'memorize', value: 'text' } } @@ -1066,13 +1066,13 @@ describe('expandSeedPacket tests', () => { version: 0, seeds: { '': { - 't': 'log', + 'type': 'log', 'value': { 'seed': 'other' } }, 'other': { - 't': 'log', + 'type': 'log', 'value': true } } @@ -1083,13 +1083,13 @@ describe('expandSeedPacket tests', () => { environment: {}, seeds: { '': { - 't': 'log', + 'type': 'log', 'value': { 'seed': 'other' } }, 'other': { - 't': 'log', + 'type': 'log', 'value': true } } @@ -1102,9 +1102,9 @@ describe('expandSeedPacket tests', () => { version: 0, seeds: { '': { - 't': 'log', + 'type': 'log', 'value': { - 't': 'log', + 'type': 'log', 'value': true } } @@ -1116,13 +1116,13 @@ describe('expandSeedPacket tests', () => { environment: {}, seeds: { '': { - 't': 'log', + 'type': 'log', 'value': { 'seed': '-value' } }, '-value': { - 't': 'log', + 'type': 'log', private: true, 'value': true } @@ -1136,9 +1136,9 @@ describe('expandSeedPacket tests', () => { version: 0, seeds: { '': { - 't': 'log', + 'type': 'log', 'value': { - 't': 'log', + 'type': 'log', private: false, 'value': true } @@ -1151,13 +1151,13 @@ describe('expandSeedPacket tests', () => { environment: {}, seeds: { '': { - 't': 'log', + 'type': 'log', 'value': { 'seed': '-value' } }, '-value': { - 't': 'log', + 'type': 'log', private: false, 'value': true } @@ -1172,10 +1172,10 @@ describe('expandSeedPacket tests', () => { environment: {}, seeds: { '': { - 't': 'log', + 'type': 'log', 'value': { 'id': 'foo', - 't': 'log', + 'type': 'log', 'value': true } } @@ -1187,7 +1187,7 @@ describe('expandSeedPacket tests', () => { environment: {}, seeds: { '': { - 't': 'log', + 'type': 'log', 'value': { 'seed': 'foo' } @@ -1195,7 +1195,7 @@ describe('expandSeedPacket tests', () => { 'foo': { 'id': 'foo', private: true, - 't': 'log', + 'type': 'log', 'value': true } } @@ -1209,10 +1209,10 @@ describe('expandSeedPacket tests', () => { environment: {}, seeds: { '': { - 't': 'object', + 'type': 'object', 'properties': { 'a' : { - 't': 'log', + 'type': 'log', 'value': true }, 'b': true @@ -1226,7 +1226,7 @@ describe('expandSeedPacket tests', () => { environment: {}, seeds: { '': { - 't': 'object', + 'type': 'object', 'properties': { 'a': { 'seed': '-a' @@ -1235,7 +1235,7 @@ describe('expandSeedPacket tests', () => { } }, '-a': { - 't': 'log', + 'type': 'log', private: true, 'value': true } @@ -1250,10 +1250,10 @@ describe('expandSeedPacket tests', () => { environment: {}, seeds: { '': { - 't': 'array', + 'type': 'array', 'items': [ { - 't': 'log', + 'type': 'log', 'value': true }, true @@ -1267,7 +1267,7 @@ describe('expandSeedPacket tests', () => { environment: {}, seeds: { '': { - 't': 'array', + 'type': 'array', 'items': [ { 'seed': '-0' @@ -1276,7 +1276,7 @@ describe('expandSeedPacket tests', () => { ] }, '-0': { - 't': 'log', + 'type': 'log', private: true, 'value': true } @@ -1291,12 +1291,12 @@ describe('expandSeedPacket tests', () => { environment: {}, seeds: { '': { - 't': 'noop', + 'type': 'noop', 'value': { - 't': 'array', + 'type': 'array', 'items': [ { - 't': 'noop', + 'type': 'noop', 'value': 3 }, true @@ -1311,12 +1311,12 @@ describe('expandSeedPacket tests', () => { environment: {}, seeds: { '-value-0': { - 't': 'noop', + 'type': 'noop', private: true, 'value': 3 }, '-value': { - 't': 'array', + 'type': 'array', private: true, 'items': [ { @@ -1326,7 +1326,7 @@ describe('expandSeedPacket tests', () => { ] }, '': { - 't': 'noop', + 'type': 'noop', 'value': { 'seed': '-value' } @@ -1342,10 +1342,10 @@ describe('expandSeedPacket tests', () => { environment: {}, seeds: { '': { - 't': 'noop', + 'type': 'noop', 'value': [ { - 't': 'log', + 'type': 'log', 'value': true }, true @@ -1359,13 +1359,13 @@ describe('expandSeedPacket tests', () => { environment: {}, seeds: { '': { - 't': 'noop', + 'type': 'noop', 'value': { 'seed': '-value' } }, '-value': { - 't': 'array', + 'type': 'array', private: true, 'items': [ { @@ -1375,7 +1375,7 @@ describe('expandSeedPacket tests', () => { ] }, '-value-0': { - 't': 'log', + 'type': 'log', private: true, 'value': true } @@ -1390,12 +1390,12 @@ describe('expandSeedPacket tests', () => { environment: {}, seeds: { '': { - 't': 'noop', + 'type': 'noop', 'value': { - 't': 'object', + 'type': 'object', 'properties': { 'a': { - 't': 'noop', + 'type': 'noop', 'value': 3 }, 'b': true @@ -1410,12 +1410,12 @@ describe('expandSeedPacket tests', () => { environment: {}, seeds: { '-value-a': { - 't': 'noop', + 'type': 'noop', private: true, 'value': 3 }, '-value': { - 't': 'object', + 'type': 'object', private: true, 'properties': { 'a': { @@ -1425,7 +1425,7 @@ describe('expandSeedPacket tests', () => { } }, '': { - 't': 'noop', + 'type': 'noop', 'value': { 'seed': '-value' } @@ -1441,10 +1441,10 @@ describe('expandSeedPacket tests', () => { environment: {}, seeds: { '': { - 't': 'noop', + 'type': 'noop', 'value': { 'a': { - 't': 'log', + 'type': 'log', 'value': true }, 'b': true @@ -1458,13 +1458,13 @@ describe('expandSeedPacket tests', () => { environment: {}, seeds: { '': { - 't': 'noop', + 'type': 'noop', 'value': { 'seed': '-value' } }, '-value': { - 't': 'object', + 'type': 'object', private: true, 'properties': { 'a': { @@ -1474,7 +1474,7 @@ describe('expandSeedPacket tests', () => { } }, '-value-a': { - 't': 'log', + 'type': 'log', private: true, 'value': true } @@ -1489,7 +1489,7 @@ describe('expandSeedPacket tests', () => { environment: {}, seeds: { '': { - t: 'render', + type: 'render', template: '{{name}} is {{age}}', vars: { name: { @@ -1506,14 +1506,14 @@ describe('expandSeedPacket tests', () => { environment: {}, seeds: { '': { - t: 'render', + type: 'render', template: '{{name}} is {{age}}', vars: { seed: '-vars', } }, '-vars': { - t: 'object', + type: 'object', private: true, properties: { name: { @@ -1533,11 +1533,11 @@ describe('expandSeedPacket tests', () => { environment: {}, seeds: { '': { - 't': 'noop', + 'type': 'noop', 'value': { 'a': [ { - 't': 'log', + 'type': 'log', 'value': true }, 3 @@ -1553,13 +1553,13 @@ describe('expandSeedPacket tests', () => { environment: {}, seeds: { '': { - 't': 'noop', + 'type': 'noop', 'value': { 'seed': '-value' } }, '-value': { - 't': 'object', + 'type': 'object', private: true, 'properties': { 'a': { @@ -1569,7 +1569,7 @@ describe('expandSeedPacket tests', () => { } }, '-value-a': { - 't': 'array', + 'type': 'array', private: true, 'items': [ { @@ -1579,7 +1579,7 @@ describe('expandSeedPacket tests', () => { ] }, '-value-a-0': { - 't': 'log', + 'type': 'log', private: true, 'value': true } @@ -1594,13 +1594,13 @@ describe('expandSeedPacket tests', () => { environment: {}, seeds: { '': { - 't': 'noop', + 'type': 'noop', 'value': { 'a': { - 't': 'array', + 'type': 'array', 'items': [ { - 't': 'log', + 'type': 'log', 'value': true }, 3 @@ -1617,13 +1617,13 @@ describe('expandSeedPacket tests', () => { environment: {}, seeds: { '': { - 't': 'noop', + 'type': 'noop', 'value': { 'seed': '-value' } }, '-value': { - 't': 'object', + 'type': 'object', private: true, 'properties': { 'a': { @@ -1633,7 +1633,7 @@ describe('expandSeedPacket tests', () => { } }, '-value-a': { - 't': 'array', + 'type': 'array', private: true, 'items': [ { @@ -1643,7 +1643,7 @@ describe('expandSeedPacket tests', () => { ] }, '-value-a-0': { - 't': 'log', + 'type': 'log', private: true, 'value': true }