-
Notifications
You must be signed in to change notification settings - Fork 8
/
frame.go
134 lines (113 loc) · 3.86 KB
/
frame.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package gptscript
import (
"fmt"
"time"
)
type ToolCategory string
type EventType string
const (
ProviderToolCategory ToolCategory = "provider"
CredentialToolCategory ToolCategory = "credential"
ContextToolCategory ToolCategory = "context"
InputToolCategory ToolCategory = "input"
OutputToolCategory ToolCategory = "output"
NoCategory ToolCategory = ""
EventTypeRunStart EventType = "runStart"
EventTypeCallStart EventType = "callStart"
EventTypeCallContinue EventType = "callContinue"
EventTypeCallSubCalls EventType = "callSubCalls"
EventTypeCallProgress EventType = "callProgress"
EventTypeChat EventType = "callChat"
EventTypeCallConfirm EventType = "callConfirm"
EventTypeCallFinish EventType = "callFinish"
EventTypeRunFinish EventType = "runFinish"
EventTypePrompt EventType = "prompt"
)
type Frame struct {
Run *RunFrame `json:"run,omitempty"`
Call *CallFrame `json:"call,omitempty"`
Prompt *PromptFrame `json:"prompt,omitempty"`
}
type RunFrame struct {
ID string `json:"id"`
Program Program `json:"program"`
Input string `json:"input"`
Output string `json:"output"`
Error string `json:"error"`
Start time.Time `json:"start"`
End time.Time `json:"end"`
State RunState `json:"state"`
ChatState any `json:"chatState"`
Type EventType `json:"type"`
}
type CallFrames map[string]CallFrame
func (c CallFrames) ParentCallFrame() CallFrame {
for _, call := range c {
if call.ParentID == "" && call.ToolCategory == NoCategory {
return call
}
}
return CallFrame{}
}
type CallFrame struct {
CallContext `json:",inline"`
Type EventType `json:"type"`
Start time.Time `json:"start"`
End time.Time `json:"end"`
Input string `json:"input"`
Output []Output `json:"output"`
Usage Usage `json:"usage"`
ChatResponseCached bool `json:"chatResponseCached"`
ToolResults int `json:"toolResults"`
LLMRequest any `json:"llmRequest"`
LLMResponse any `json:"llmResponse"`
}
type Usage struct {
PromptTokens int `json:"promptTokens,omitempty"`
CompletionTokens int `json:"completionTokens,omitempty"`
TotalTokens int `json:"totalTokens,omitempty"`
}
type Output struct {
Content string `json:"content"`
SubCalls map[string]Call `json:"subCalls"`
}
type Program struct {
Name string `json:"name,omitempty"`
EntryToolID string `json:"entryToolId,omitempty"`
ToolSet ToolSet `json:"toolSet,omitempty"`
}
type ToolSet map[string]Tool
type Call struct {
ToolID string `json:"toolID,omitempty"`
Input string `json:"input,omitempty"`
}
type CallContext struct {
ID string `json:"id"`
Tool Tool `json:"tool"`
AgentGroup []ToolReference `json:"agentGroup,omitempty"`
CurrentAgent ToolReference `json:"currentAgent,omitempty"`
DisplayText string `json:"displayText"`
InputContext []InputContext `json:"inputContext"`
ToolCategory ToolCategory `json:"toolCategory,omitempty"`
ToolName string `json:"toolName,omitempty"`
ParentID string `json:"parentID,omitempty"`
}
type InputContext struct {
ToolID string `json:"toolID,omitempty"`
Content string `json:"content,omitempty"`
}
type PromptFrame struct {
ID string `json:"id,omitempty"`
Type EventType `json:"type,omitempty"`
Time time.Time `json:"time,omitempty"`
Message string `json:"message,omitempty"`
Fields []string `json:"fields,omitempty"`
Sensitive bool `json:"sensitive,omitempty"`
Metadata map[string]string `json:"metadata,omitempty"`
}
func (p *PromptFrame) String() string {
return fmt.Sprintf(`Message: %s
Fields: %v
Sensitive: %v`, p.Message, p.Fields, p.Sensitive,
)
}