Skip to content

Commit 14e566a

Browse files
committed
Comments
1 parent 0c40980 commit 14e566a

File tree

2 files changed

+133
-5
lines changed

2 files changed

+133
-5
lines changed

exec/wit/golem-exec.wit

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ package golem:[email protected];
33
interface types {
44
/// Supported language types and optional version
55
record language {
6+
/// The language to use
67
kind: language-kind,
8+
/// Optionally further narrow down the language version
79
version: option<string>,
810
}
911

12+
/// Supported languages
1013
enum language-kind {
1114
javascript,
1215
python,
@@ -21,54 +24,75 @@ interface types {
2124

2225
/// Code or data file
2326
record file {
27+
/// File name
2428
name: string,
29+
/// Raw file contents
2530
content: list<u8>,
26-
encoding: option<encoding>, // defaults to utf8
31+
/// Encoding of `content`, defaults to `utf8`
32+
encoding: option<encoding>,
2733
}
2834

2935
/// Resource limits
3036
record limits {
37+
/// Limit the execution time, in milliseconds
3138
time-ms: option<u64>,
39+
/// Limit the memory usage, in bytes
3240
memory-bytes: option<u64>,
41+
/// Limit the maximum file size, in bytes
3342
file-size-bytes: option<u64>,
43+
/// Limit the number of spawned processes
3444
max-processes: option<u32>,
3545
}
3646

3747
/// Execution outcome per stage
3848
record stage-result {
49+
/// Standard output
3950
stdout: string,
51+
/// Standard error output
4052
stderr: string,
53+
/// Exit code of the process, if any
4154
exit-code: option<s32>,
55+
/// Signal that caused the process to terminate, if any
4256
signal: option<string>,
4357
}
4458

4559
/// Complete execution result
4660
record exec-result {
61+
/// Result of the compilation stage, if any
4762
compile: option<stage-result>,
63+
/// Result of the execution stage
4864
run: stage-result,
65+
/// Execution time in milliseconds
4966
time-ms: option<u64>,
67+
/// Consumed memory in bytes
5068
memory-bytes: option<u64>,
5169
}
5270

5371
/// Execution error types
5472
variant error {
73+
/// The chosen langauge is not supported
5574
unsupported-language,
75+
/// Compilation failed
5676
compilation-failed(stage-result),
77+
/// Execution failed
5778
runtime-failed(stage-result),
79+
/// Timed out
5880
timeout,
81+
/// Resource limits exceeded
5982
resource-exceeded,
83+
/// Internal execution error
6084
internal(string),
6185
}
6286

6387
/// Options for controlling the script runner environment
64-
/// - `stdin` is optional input to provide to the program.
65-
/// - `args` are command line arguments passed to the program.
66-
/// - `env` is a list of environment variables to set for the execution.
67-
/// - `limits` are optional resource limits for the execution.
6888
record run-options {
89+
/// optional input to provide to the program.
6990
stdin: option<string>,
91+
/// command line arguments passed to the program
7092
args: option<list<string>>,
93+
/// a list of environment variables to set for the execution
7194
env: option<list<tuple<string, string>>>,
95+
/// optional resource limits for the execution
7296
limits: option<limits>
7397
}
7498
}

llm/wit/golem-llm.wit

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,51 @@ package golem:[email protected];
33
interface llm {
44
// --- Roles, Error Codes, Finish Reasons ---
55

6+
/// Roles of the conversation
67
enum role {
8+
/// Instructions provided by the user
79
user,
10+
/// Messages generated by the model
811
assistant,
12+
/// Messages describing the system's rules
913
system,
14+
/// Messages describing tool calls
1015
tool,
1116
}
1217

18+
/// Possible error cases for LLM calls
1319
enum error-code {
20+
/// Invalid request parameters
1421
invalid-request,
22+
/// Authentication failed
1523
authentication-failed,
24+
/// Rate limit exceeded
1625
rate-limit-exceeded,
26+
/// Internal error
1727
internal-error,
28+
/// Unsupported operation
1829
unsupported,
30+
/// Unknown error
1931
unknown,
2032
}
2133

34+
/// Reasons for finishing a conversation
2235
enum finish-reason {
36+
/// The conversation finished
2337
stop,
38+
/// Conversation finished because of reaching the maximum length
2439
length,
40+
/// Conversation finished with request for calling tools
2541
tool-calls,
42+
/// Conversation finished because of content filtering
2643
content-filter,
44+
/// Conversation finished with an error
2745
error,
46+
/// Other reason
2847
other,
2948
}
3049

50+
/// Image detail levels
3151
enum image-detail {
3252
low,
3353
high,
@@ -36,153 +56,237 @@ interface llm {
3656

3757
// --- Message Content ---
3858

59+
/// Points to an image by an URL and an optional image detail level
3960
record image-url {
61+
/// The URL of the image
4062
url: string,
63+
/// Level of detail of the image
4164
detail: option<image-detail>,
4265
}
4366

67+
/// Contains an inline image
4468
record image-source {
69+
/// Raw image data
4570
data: list<u8>,
71+
/// MIME type of the image
4672
mime-type: string,
73+
/// Level of detail of the image
4774
detail: option<image-detail>,
4875
}
4976

77+
/// Contains an image, either a remote or an inlined one
5078
variant image-reference {
79+
/// A remote image
5180
url(image-url),
81+
/// An inlined image
5282
inline(image-source),
5383
}
5484

85+
/// One part of the conversation
5586
variant content-part {
87+
/// Text content
5688
text(string),
89+
/// Image content
5790
image(image-reference),
5891
}
5992

93+
/// A message in the conversation
6094
record message {
95+
/// Role of this message
6196
role: role,
97+
/// Name of the sender
6298
name: option<string>,
99+
/// Content of the message
63100
content: list<content-part>,
64101
}
65102

66103
// --- Tooling ---
67104

105+
/// Describes a tool callable by the LLM
68106
record tool-definition {
107+
/// Name of the tool
69108
name: string,
109+
/// Description of the tool
70110
description: option<string>,
111+
/// Schema of the tool's parameters - usually a JSON schema
71112
parameters-schema: string,
72113
}
73114

115+
/// Describes a tool call request
74116
record tool-call {
117+
/// Call identifier
75118
id: string,
119+
/// Name of the tool
76120
name: string,
121+
/// Arguments of the tool call
77122
arguments-json: string,
78123
}
79124

125+
/// Describes a successful tool call
80126
record tool-success {
127+
/// Call identifier
81128
id: string,
129+
/// Name of the tool
82130
name: string,
131+
/// Result of the tool call in JSON
83132
result-json: string,
133+
/// Execution time of the tool call in milliseconds
84134
execution-time-ms: option<u32>,
85135
}
86136

137+
/// Describes a failed tool call
87138
record tool-failure {
139+
/// Call identifier
88140
id: string,
141+
/// Name of the tool
89142
name: string,
143+
/// Error message of the tool call
90144
error-message: string,
145+
/// Error code of the tool call
91146
error-code: option<string>,
92147
}
93148

149+
/// Result of a tool call
94150
variant tool-result {
151+
/// The tool call succeeded
95152
success(tool-success),
153+
/// The tool call failed
96154
error(tool-failure),
97155
}
98156

99157
// --- Configuration ---
100158

159+
/// Simple key-value pair
101160
record kv {
102161
key: string,
103162
value: string,
104163
}
105164

165+
/// LLM configuration
106166
record config {
167+
/// The model to use
107168
model: string,
169+
/// Temperature
108170
temperature: option<f32>,
171+
/// Maximum number of tokens
109172
max-tokens: option<u32>,
173+
/// A sequence where the model stops generating tokens
110174
stop-sequences: option<list<string>>,
175+
/// List of available tools
111176
tools: list<tool-definition>,
177+
/// Tool choice policy
112178
tool-choice: option<string>,
179+
/// Additional LLM provider specific key-value pairs
113180
provider-options: list<kv>,
114181
}
115182

116183
// --- Usage / Metadata ---
117184

185+
/// Token usage statistics
118186
record usage {
187+
/// Number of input tokens used
119188
input-tokens: option<u32>,
189+
/// Number of output tokens generated
120190
output-tokens: option<u32>,
191+
/// Total number of tokens used
121192
total-tokens: option<u32>,
122193
}
123194

195+
/// Metadata about an LLM response
124196
record response-metadata {
197+
/// Reason for finishing the conversation
125198
finish-reason: option<finish-reason>,
199+
/// Usage statistics
126200
usage: option<usage>,
201+
/// Provider-specific ID
127202
provider-id: option<string>,
203+
/// Timestamp
128204
timestamp: option<string>,
205+
/// Provider-specific additional metadata in JSON
129206
provider-metadata-json: option<string>,
130207
}
131208

209+
/// Response from an LLM
132210
record complete-response {
211+
/// Response ID
133212
id: string,
213+
/// Result contents
134214
content: list<content-part>,
215+
/// Tool call requests
135216
tool-calls: list<tool-call>,
217+
/// Response metadata
136218
metadata: response-metadata,
137219
}
138220

139221
// --- Error Handling ---
140222

223+
/// LLM error
141224
record error {
225+
/// Error code
142226
code: error-code,
227+
/// Error message
143228
message: string,
229+
/// More details in JSON, in a provider-specific format
144230
provider-error-json: option<string>,
145231
}
146232

147233
// --- Chat Response Variants ---
148234

235+
/// One resulting event in an LLM conversation
149236
variant chat-event {
237+
/// A response in the conversation
150238
message(complete-response),
239+
/// A request for calling one or more tools
151240
tool-request(list<tool-call>),
241+
/// An error in the conversation
152242
error(error),
153243
}
154244

155245
// --- Streaming ---
156246

247+
/// Changes in a streaming conversation
157248
record stream-delta {
249+
/// New content parts
158250
content: option<list<content-part>>,
251+
/// New tool calls
159252
tool-calls: option<list<tool-call>>,
160253
}
161254

255+
/// Event in a streaming conversation
162256
variant stream-event {
257+
/// New incoming response content or tool call requests
163258
delta(stream-delta),
259+
/// Converstation finished
164260
finish(response-metadata),
261+
/// Conversation failed
165262
error(error),
166263
}
167264

265+
/// Represents an ongoing streaming LLM conversation
168266
resource chat-stream {
267+
/// Polls for the next chunk of stream events
169268
get-next: func() -> option<list<stream-event>>;
269+
/// Blocks until the next chunk of stream events is available
170270
blocking-get-next: func() -> list<stream-event>;
171271
}
172272

173273
// --- Core Functions ---
174274

275+
/// Make a single call to the LLM. Continue the conversation with `continue` if needed.
175276
send: func(
176277
messages: list<message>,
177278
config: config
178279
) -> chat-event;
179280

281+
/// Continues a previous conversation initiated by `send` or a previous `continue`, by sending the updated
282+
/// set of messages, and possible set of tool call results.
180283
continue: func(
181284
messages: list<message>,
182285
tool-results: list<tuple<tool-call, tool-result>>,
183286
config: config
184287
) -> chat-event;
185288

289+
/// Makes a single call to the LLM and gets back a streaming API to receive the response in chunks.
186290
%stream: func(
187291
messages: list<message>,
188292
config: config

0 commit comments

Comments
 (0)