-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[playground] Math: Retry 5 times on JS errors
- Loading branch information
Showing
6 changed files
with
377 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# math-retry | ||
- Original: [`math-retry.ts`](../../src/boards/math-retry.ts) | ||
- Graph: [`math-retry.json`](../../graphs/math-retry.json) | ||
|
||
```mermaid | ||
%%{init: 'themeVariables': { 'fontFamily': 'Fira Code, monospace' }}%% | ||
graph TD; | ||
lambda2["lambda <br> id='lambda-2'"] -- "board->lambda" --> invoke1["invoke <br> id='invoke-1'"] | ||
subgraph sg_lambda2 [lambda-2] | ||
lambda2_secrets3("secrets <br> id='secrets-3'"):::secrets -- "PALM_KEY->PALM_KEY" --> lambda2_mathfunctiongenerator["generateText <br> id='math-function-generator'"] | ||
lambda2_input1[/"input <br> id='input-1'"/]:::input -- "text->text" --> lambda2_mathfunctiongenerator["generateText <br> id='math-function-generator'"] | ||
lambda2_mathfunctiongenerator["generateText <br> id='math-function-generator'"] -- "completion->code" --> lambda2_compute["runJavascript <br> id='compute'"] | ||
lambda2_compute["runJavascript <br> id='compute'"] -- "result->text" --> lambda2_output2{{"output <br> id='output-2'"}}:::output | ||
lambda2_compute["runJavascript <br> id='compute'"] -- "$error->$error" --> lambda2_passthrough4(("passthrough <br> id='passthrough-4'")):::passthrough | ||
lambda2_mathfunctiongenerator["generateText <br> id='math-function-generator'"] -- "completion->completion" --> lambda2_passthrough4(("passthrough <br> id='passthrough-4'")):::passthrough | ||
end | ||
sg_lambda2:::slotted -- "lamdba->lamdba" --o lambda2 | ||
invoke1["invoke <br> id='invoke-1'"] -- "text->text" --> print{{"output <br> id='print'"}}:::output | ||
mathfunction["promptTemplate <br> id='math-function'"] -- "prompt->text" --> invoke1["invoke <br> id='invoke-1'"] | ||
mathquestion[/"input <br> id='math-question'"/]:::input -- "text->question" --> mathfunction["promptTemplate <br> id='math-function'"] | ||
schemamathquestion[schema]:::config -- "schema->schema" --o mathquestion | ||
templatemathfunction[template]:::config -- "template->template" --o mathfunction | ||
pathinvoke1[path]:::config -- "path->path" --o invoke1 | ||
schemaprint[schema]:::config -- "schema->schema" --o print | ||
classDef default stroke:#ffab40,fill:#fff2ccff,color:#000 | ||
classDef input stroke:#3c78d8,fill:#c9daf8ff,color:#000 | ||
classDef output stroke:#38761d,fill:#b6d7a8ff,color:#000 | ||
classDef passthrough stroke:#a64d79,fill:#ead1dcff,color:#000 | ||
classDef slot stroke:#a64d79,fill:#ead1dcff,color:#000 | ||
classDef config stroke:#a64d79,fill:#ead1dcff,color:#000 | ||
classDef secrets stroke:#db4437,fill:#f4cccc,color:#000 | ||
classDef slotted stroke:#a64d79 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
{ | ||
"title": "The Calculator Recipe (with retries)", | ||
"description": "A simple AI pattern that leans on the power of the LLMs to generate language to solve math problems. Retries 5 times.", | ||
"version": "0.0.1", | ||
"edges": [ | ||
{ | ||
"from": "lambda-2", | ||
"to": "invoke-1", | ||
"out": "board", | ||
"in": "lambda" | ||
}, | ||
{ | ||
"from": "invoke-1", | ||
"to": "print", | ||
"out": "text", | ||
"in": "text" | ||
}, | ||
{ | ||
"from": "math-function", | ||
"to": "invoke-1", | ||
"out": "prompt", | ||
"in": "text" | ||
}, | ||
{ | ||
"from": "math-question", | ||
"to": "math-function", | ||
"out": "text", | ||
"in": "question" | ||
} | ||
], | ||
"nodes": [ | ||
{ | ||
"id": "math-question", | ||
"type": "input", | ||
"configuration": { | ||
"schema": { | ||
"type": "object", | ||
"properties": { | ||
"text": { | ||
"type": "string", | ||
"title": "Math problem", | ||
"description": "Ask a math question" | ||
} | ||
}, | ||
"required": [ | ||
"text" | ||
] | ||
} | ||
} | ||
}, | ||
{ | ||
"id": "math-function", | ||
"type": "promptTemplate", | ||
"configuration": { | ||
"template": "Translate the math problem below into a JavaScript function named `compute` that can be executed to provide the answer to the problem\nMath Problem: {{question}}\nSolution:" | ||
} | ||
}, | ||
{ | ||
"id": "invoke-1", | ||
"type": "invoke", | ||
"configuration": { | ||
"path": "./retry.json" | ||
} | ||
}, | ||
{ | ||
"id": "lambda-2", | ||
"type": "lambda", | ||
"configuration": { | ||
"board": { | ||
"kind": "board", | ||
"board": { | ||
"edges": [ | ||
{ | ||
"from": "secrets-3", | ||
"to": "math-function-generator", | ||
"out": "PALM_KEY", | ||
"in": "PALM_KEY" | ||
}, | ||
{ | ||
"from": "input-1", | ||
"to": "math-function-generator", | ||
"out": "text", | ||
"in": "text" | ||
}, | ||
{ | ||
"from": "math-function-generator", | ||
"to": "compute", | ||
"out": "completion", | ||
"in": "code" | ||
}, | ||
{ | ||
"from": "compute", | ||
"to": "output-2", | ||
"out": "result", | ||
"in": "text" | ||
}, | ||
{ | ||
"from": "compute", | ||
"to": "passthrough-4", | ||
"out": "$error", | ||
"in": "$error" | ||
}, | ||
{ | ||
"from": "math-function-generator", | ||
"to": "passthrough-4", | ||
"out": "completion", | ||
"in": "completion" | ||
} | ||
], | ||
"nodes": [ | ||
{ | ||
"id": "input-1", | ||
"type": "input" | ||
}, | ||
{ | ||
"id": "output-2", | ||
"type": "output" | ||
}, | ||
{ | ||
"id": "math-function-generator", | ||
"type": "generateText" | ||
}, | ||
{ | ||
"id": "secrets-3", | ||
"type": "secrets", | ||
"configuration": { | ||
"keys": [ | ||
"PALM_KEY" | ||
] | ||
} | ||
}, | ||
{ | ||
"id": "compute", | ||
"type": "runJavascript", | ||
"configuration": { | ||
"name": "compute" | ||
} | ||
}, | ||
{ | ||
"id": "passthrough-4", | ||
"type": "passthrough" | ||
} | ||
], | ||
"kits": [ | ||
{ | ||
"title": "LLM Starter Kit", | ||
"description": "A kit that provides a few necessary components for wiring boards that use PaLM API.", | ||
"version": "0.0.1", | ||
"url": "npm:@google-labs/llm-starter" | ||
} | ||
] | ||
} | ||
} | ||
} | ||
}, | ||
{ | ||
"id": "print", | ||
"type": "output", | ||
"configuration": { | ||
"schema": { | ||
"type": "object", | ||
"properties": { | ||
"text": { | ||
"type": "string", | ||
"title": "Answer", | ||
"description": "The answer to the math problem" | ||
} | ||
}, | ||
"required": [ | ||
"text" | ||
] | ||
} | ||
} | ||
} | ||
], | ||
"kits": [ | ||
{ | ||
"title": "LLM Starter Kit", | ||
"description": "A kit that provides a few necessary components for wiring boards that use PaLM API.", | ||
"version": "0.0.1", | ||
"url": "npm:@google-labs/llm-starter" | ||
} | ||
] | ||
} |
Oops, something went wrong.