Skip to content

Commit bf55d83

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

File tree

4 files changed

+449
-26
lines changed

4 files changed

+449
-26
lines changed

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)