Skip to content

Commit 46141ad

Browse files
committed
Test failure path in LLM flow
1 parent 5a288a2 commit 46141ad

File tree

5 files changed

+459
-36
lines changed

5 files changed

+459
-36
lines changed

flows/actions/testdata/call_llm.json

+10-10
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"@input.text"
2525
],
2626
"locals": {
27-
"_llm_output": "<FAILED>"
27+
"_llm_output": "\u003cFAILED\u003e"
2828
},
2929
"inspection": {
3030
"dependencies": [
@@ -66,26 +66,26 @@
6666
},
6767
"events": [
6868
{
69+
"type": "llm_called",
6970
"created_on": "2018-10-18T14:20:30.000123456Z",
70-
"elapsed_ms": 0,
71-
"input": "Hi everybody",
72-
"instructions": "Categorize the following text as positive or negative",
71+
"step_uuid": "9688d21d-95aa-4bed-afc7-f31b35731a3d",
7372
"llm": {
74-
"name": "Claude",
75-
"uuid": "51ade705-8338-40a9-8a77-37657a936966"
73+
"uuid": "51ade705-8338-40a9-8a77-37657a936966",
74+
"name": "Claude"
7675
},
77-
"output": "You asked:\n\nCategorize the following text as positive or negative\n\nHi everybody",
78-
"step_uuid": "9688d21d-95aa-4bed-afc7-f31b35731a3d",
76+
"instructions": "Categorize the following text as positive or negative",
77+
"input": "Hi everybody",
78+
"output": "negative",
7979
"tokens_used": 123,
80-
"type": "llm_called"
80+
"elapsed_ms": 0
8181
}
8282
],
8383
"templates": [
8484
"Categorize the following text as positive or negative",
8585
"@input.text"
8686
],
8787
"locals": {
88-
"_llm_output": "You asked:\n\nCategorize the following text as positive or negative\n\nHi everybody"
88+
"_llm_output": "negative"
8989
},
9090
"inspection": {
9191
"dependencies": [

test/services/llm.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package services
22

33
import (
44
"context"
5+
"errors"
56
"strings"
67

78
"github.com/nyaruka/goflow/flows"
@@ -16,9 +17,11 @@ func NewLLM() *LLMService {
1617

1718
func (s *LLMService) Response(ctx context.Context, instructions, input string, maxTokens int) (*flows.LLMResponse, error) {
1819
var output string
19-
if strings.HasPrefix(input, "\\return ") { // an input like "\return foo" will return "foo"
20+
if strings.HasPrefix(input, "\\error ") { // an input like "\error foo" will return the error "foo"
21+
return nil, errors.New(input[7:])
22+
} else if strings.HasPrefix(input, "\\return ") { // an input like "\return foo" will return "foo"
2023
output = input[8:]
21-
} else if strings.HasPrefix(input, "Categorize") { // instructions like "Categorize... Category2, Category3" will return "Category3"
24+
} else if strings.HasPrefix(instructions, "Categorize") { // instructions like "Categorize... Category2, Category3" will return "Category3"
2225
words := strings.Fields(instructions)
2326
output = words[len(words)-1]
2427
} else {

0 commit comments

Comments
 (0)