Skip to content

Commit

Permalink
[playground] Math: Retry 5 times on JS errors
Browse files Browse the repository at this point in the history
  • Loading branch information
seefeldb committed Oct 20, 2023
1 parent 9820dd5 commit 3472735
Show file tree
Hide file tree
Showing 6 changed files with 377 additions and 70 deletions.
37 changes: 37 additions & 0 deletions seeds/graph-playground/docs/graphs/math-retry.md
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
```
42 changes: 21 additions & 21 deletions seeds/graph-playground/docs/graphs/retry.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,28 @@
```mermaid
%%{init: 'themeVariables': { 'fontFamily': 'Fira Code, monospace' }}%%
graph TD;
input1[/"input <br> id='input-1'"/]:::input -- "tries->tries" --> jsonata4["jsonata <br> id='jsonata-4'"]
jsonata4["jsonata <br> id='jsonata-4'"] -- "tries->tries" --> jsonata4["jsonata <br> id='jsonata-4'"]
input1[/"input <br> id='input-1'"/]:::input -- "text->text" --> promptTemplate6["promptTemplate <br> id='promptTemplate-6'"]
promptTemplate6["promptTemplate <br> id='promptTemplate-6'"] -- "prompt->text" --> promptTemplate6["promptTemplate <br> id='promptTemplate-6'"]
input1[/"input <br> id='input-1'"/]:::input -- "text->text" --> lambda completion["invoke <br> id='lambda completion'"]
input1[/"input <br> id='input-1'"/]:::input -- "lambda->board" --o lambda completion["invoke <br> id='lambda completion'"]
lambda completion["invoke <br> id='lambda completion'"] -- "completion->completion" --> output2{{"output <br> id='output-2'"}}:::output
lambda completion["invoke <br> id='lambda completion'"] -- "$error->data" --> jsonata4["jsonata <br> id='jsonata-4'"]
jsonata4["jsonata <br> id='jsonata-4'"] -- "done->$error" --> output3{{"output <br> id='output-3'"}}:::output
jsonata4["jsonata <br> id='jsonata-4'"] -- "data->json" --> jsonata5["jsonata <br> id='jsonata-5'"]
jsonata5["jsonata <br> id='jsonata-5'"] -- "error->error" --> promptTemplate6["promptTemplate <br> id='promptTemplate-6'"]
jsonata5["jsonata <br> id='jsonata-5'"] -- "completion->completion" --> promptTemplate6["promptTemplate <br> id='promptTemplate-6'"]
promptTemplate6["promptTemplate <br> id='promptTemplate-6'"] -- "prompt->text" --> lambda completion["invoke <br> id='lambda completion'"]
input1[/"input <br> id='input-1'"/]:::input -- "lambda->board" --o lambdacompletion["invoke <br> id='lambda-completion'"]
input1[/"input <br> id='input-1'"/]:::input -- "tries->tries" --> countdown["jsonata <br> id='countdown'"]
countdown["jsonata <br> id='countdown'"] -- "tries->tries" --> countdown["jsonata <br> id='countdown'"]
input1[/"input <br> id='input-1'"/]:::input -- "text->text" --> retryprompt["promptTemplate <br> id='retry-prompt'"]
retryprompt["promptTemplate <br> id='retry-prompt'"] -- "prompt->text" --> retryprompt["promptTemplate <br> id='retry-prompt'"]
input1[/"input <br> id='input-1'"/]:::input -- "text->text" --> lambdacompletion["invoke <br> id='lambda-completion'"]
lambdacompletion["invoke <br> id='lambda-completion'"] -- all --> outputsuccess{{"output <br> id='output-success'"}}:::output
lambdacompletion["invoke <br> id='lambda-completion'"] -- "$error->data" --> countdown["jsonata <br> id='countdown'"]
countdown["jsonata <br> id='countdown'"] -- "done->$error" --> outputerror{{"output <br> id='output-error'"}}:::output
countdown["jsonata <br> id='countdown'"] -- "data->json" --> errorparser["jsonata <br> id='error-parser'"]
errorparser["jsonata <br> id='error-parser'"] -- "error->error" --> retryprompt["promptTemplate <br> id='retry-prompt'"]
errorparser["jsonata <br> id='error-parser'"] -- "completion->completion" --> retryprompt["promptTemplate <br> id='retry-prompt'"]
retryprompt["promptTemplate <br> id='retry-prompt'"] -- "prompt->text" --> lambdacompletion["invoke <br> id='lambda-completion'"]
schemainput1[schema]:::config -- "schema->schema" --o input1
schemaoutput2[schema]:::config -- "schema->schema" --o output2
schemaoutput3[schema]:::config -- "schema->schema" --o output3
expressionjsonata4[expression]:::config -- "expression->expression" --o jsonata4
triesjsonata4[tries]:::config -- "tries->tries" --o jsonata4
rawjsonata4[raw]:::config -- "raw->raw" --o jsonata4
expressionjsonata5[expression]:::config -- "expression->expression" --o jsonata5
rawjsonata5[raw]:::config -- "raw->raw" --o jsonata5
templatepromptTemplate6[template]:::config -- "template->template" --o promptTemplate6
schemaoutputsuccess[schema]:::config -- "schema->schema" --o outputsuccess
schemaoutputerror[schema]:::config -- "schema->schema" --o outputerror
expressioncountdown[expression]:::config -- "expression->expression" --o countdown
triescountdown[tries]:::config -- "tries->tries" --o countdown
rawcountdown[raw]:::config -- "raw->raw" --o countdown
expressionerrorparser[expression]:::config -- "expression->expression" --o errorparser
rawerrorparser[raw]:::config -- "raw->raw" --o errorparser
templateretryprompt[template]:::config -- "template->template" --o retryprompt
classDef default stroke:#ffab40,fill:#fff2ccff,color:#000
classDef input stroke:#3c78d8,fill:#c9daf8ff,color:#000
classDef output stroke:#38761d,fill:#b6d7a8ff,color:#000
Expand Down
184 changes: 184 additions & 0 deletions seeds/graph-playground/graphs/math-retry.json
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"
}
]
}
Loading

0 comments on commit 3472735

Please sign in to comment.