Skip to content

Commit

Permalink
Add a noop seed_type.
Browse files Browse the repository at this point in the history
Like `log`, but without logging.

Part of #39.
  • Loading branch information
jkomoros committed Jul 6, 2023
1 parent 345412d commit f558098
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 7 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -362,14 +362,21 @@ Environment:
#### log
Logs the given message to console and returns it. This 'noop' seed is useful for testing the machinery that calcualtes sub-seeds.
Logs the given message to console and returns it. This 'noop' seed is useful for testing the machinery that calcualtes sub-seeds. If you just want a placeholder seed with no loggin, see `noop`.
Required parameters:
- `value` - The value to echo back.
Environment:
- `mock` - If true, then skips logging to console and just returns it.
#### noop
Simply calculates and returns the value. Useful if you need a seed as a placeholder.
Required parameters:
- `value` - The value to echo back.
#### if
Checks the test condition and if truthy, returns the sub-seed's value of then, otherwise else.
Expand Down
49 changes: 45 additions & 4 deletions seed-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,47 @@
],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"id": {
"$ref": "#/definitions/seedData/anyOf/0/properties/id"
},
"description": {
"$ref": "#/definitions/seedData/anyOf/0/properties/description"
},
"type": {
"type": "string",
"const": "noop"
},
"value": {
"anyOf": [
{
"$ref": "#/definitions/seedData"
},
{
"$ref": "#/definitions/seedData/anyOf/0/properties/prompt/anyOf/1"
},
{
"anyOf": [
{
"$ref": "#/definitions/seedData/anyOf/5/properties/value/anyOf/2/anyOf/0"
},
{
"$ref": "#/definitions/seedData/anyOf/5/properties/value/anyOf/2/anyOf/1"
}
],
"description": "The value to return"
}
]
}
},
"required": [
"type",
"value"
],
"additionalProperties": false
},
{
"type": "object",
"properties": {
Expand Down Expand Up @@ -1229,7 +1270,7 @@
"$ref": "#/definitions/seedData/anyOf/5/properties/value/anyOf/2/anyOf/0"
},
{
"$ref": "#/definitions/seedData/anyOf/14/properties/vars/anyOf/2"
"$ref": "#/definitions/seedData/anyOf/15/properties/vars/anyOf/2"
},
{
"$ref": "#/definitions/seedData/anyOf/5/properties/value/anyOf/2/anyOf/1"
Expand Down Expand Up @@ -1267,7 +1308,7 @@
"items": {
"anyOf": [
{
"$ref": "#/definitions/seedData/anyOf/19/properties/properties/additionalProperties/anyOf/0"
"$ref": "#/definitions/seedData/anyOf/20/properties/properties/additionalProperties/anyOf/0"
},
{
"$ref": "#/definitions/seedData/anyOf/0/properties/prompt/anyOf/1"
Expand All @@ -1288,7 +1329,7 @@
"return": {
"anyOf": [
{
"$ref": "#/definitions/seedData/anyOf/19/properties/properties/additionalProperties/anyOf/0"
"$ref": "#/definitions/seedData/anyOf/20/properties/properties/additionalProperties/anyOf/0"
},
{
"$ref": "#/definitions/seedData/anyOf/0/properties/prompt/anyOf/1"
Expand Down Expand Up @@ -1571,7 +1612,7 @@
"$ref": "#/definitions/seedData/anyOf/5/properties/value/anyOf/2/anyOf/0"
},
{
"$ref": "#/definitions/seedData/anyOf/14/properties/vars/anyOf/2"
"$ref": "#/definitions/seedData/anyOf/15/properties/vars/anyOf/2"
},
{
"$ref": "#/definitions/seedData/anyOf/5/properties/value/anyOf/2/anyOf/1"
Expand Down
12 changes: 11 additions & 1 deletion src/grow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ import {
SeedDataDelete,
arrayReturnType,
SeedDataLetMulti,
EnvironmentData
EnvironmentData,
SeedDataNoop
} from './types.js';

import {
Expand Down Expand Up @@ -285,6 +286,12 @@ const growLog = async (seed : Seed<SeedDataLog>, env : Environment) : Promise<Va
return value;
};

const growNoop = async (seed : Seed<SeedDataNoop>, env : Environment) : Promise<Value> => {
const data = seed.data;
const value = await getProperty(seed, env, data.value);
return value;
};

const growIf = async (seed : Seed<SeedDataIf>, env : Environment) : Promise<Value> => {
const data = seed.data;
const test = Boolean(await getProperty(seed, env, data.test));
Expand Down Expand Up @@ -566,6 +573,9 @@ export const grow = async (seed : Seed, env : Environment) : Promise<Value> => {
case 'log':
result = await growLog(seed as Seed<SeedDataLog>, env);
break;
case 'noop':
result = await growNoop(seed as Seed<SeedDataNoop>, env);
break;
case 'if':
result = await growIf(seed as Seed<SeedDataIf>, env);
break;
Expand Down
14 changes: 14 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,18 @@ const seedDataLog = makeSeedData(seedDataConfigLog);

export type SeedDataLog = z.infer<typeof seedDataLog>;

const seedDataConfigNoop = {
type: z.literal('noop'),
properties: {
value: inputNonObjectValue.describe('The value to return')
}
};

const nestedSeedDataNoop = makeNestedSeedData(seedDataConfigNoop);
const seedDataNoop = makeSeedData(seedDataConfigNoop);

export type SeedDataNoop = z.infer<typeof seedDataNoop>;

const seedDataConfigIf = {
type: z.literal('if'),
properties: {
Expand Down Expand Up @@ -698,6 +710,7 @@ export const expandedSeedData = z.discriminatedUnion('type', [
seedDataRecall,
seedDataTokenCount,
seedDataLog,
seedDataNoop,
seedDataIf,
seedDataEqual,
seedDataNotEqual,
Expand Down Expand Up @@ -730,6 +743,7 @@ export const seedData = z.discriminatedUnion('type', [
nestedSeedDataRecall,
nestedSeedDataTokenCount,
nestedSeedDataLog,
nestedSeedDataNoop,
nestedSeedDataIf,
nestedSeedDataEqual,
nestedSeedDataNotEqual,
Expand Down
2 changes: 1 addition & 1 deletion test/base/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ Suffix`;
}
},
'bar': {
'type': 'log',
'type': 'noop',
'value': 'hello, world'
}
}
Expand Down

0 comments on commit f558098

Please sign in to comment.