-
Notifications
You must be signed in to change notification settings - Fork 1
/
input.go
95 lines (81 loc) · 2.24 KB
/
input.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package node
import "github.com/primalmotion/simplai/engine"
// Input represents the data passed to
// a Node.
type Input struct {
keys map[string]any
input string
scratchpad string
llmOptions []engine.LLMOption
debug bool
}
// NewInput returns a new Input with the given string
// and llm.Options. Note that the llm.Option will be
// carried out until it reaches a LLM Node. After
// that they will be discarded.
func NewInput(in string, options ...engine.LLMOption) Input {
return Input{
input: in,
keys: map[string]any{},
llmOptions: options,
}
}
// WithInput returns a copy of the receiver
// replacing the previous input.
func (i Input) WithInput(in string) Input {
i.input = in
return i
}
// Input returns the current input string.
func (i Input) Input() string {
return i.input
}
// Set returns a copy of the receiver with the given
// key and value added to it.
func (i Input) Set(k string, v any) Input {
i.keys[k] = v
return i
}
// Get returns the value of the given key.
func (i Input) Get(key string) any {
return i.keys[key]
}
// WithLLMOptions returns a copy of the receiver with the given llm.Options
// added to it.
func (i Input) WithLLMOptions(options ...engine.LLMOption) Input {
i.llmOptions = append([]engine.LLMOption{}, options...)
return i
}
// LLMOptions returns the current llm.Options.
func (i Input) LLMOptions() []engine.LLMOption {
return i.llmOptions
}
// ResetLLMOptions returns a copy of the Input
// after removing all llm.Options. This is
// called by the LLM nodes.
func (i Input) ResetLLMOptions() Input {
i.llmOptions = nil
return i
}
// WithScratchpad returns a copy of the receiver with
// the given scratchpad added.
func (i Input) WithScratchpad(scratchpad string) Input {
i.scratchpad = scratchpad
return i
}
// Scratchpad returns the current scratchpad.
func (i Input) Scratchpad() string {
return i.scratchpad
}
// WithDebug returns a copy of the receiver with the
// Debug flag activated. The Node will usually print
// detailed information about them when they deal with
// an input with Debug set to true.
func (i Input) WithDebug(debug bool) Input {
i.debug = debug
return i
}
// Debug returns the state of the debug mode.
func (i Input) Debug() bool {
return i.debug
}