-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathshared.ts
681 lines (551 loc) · 14.8 KB
/
shared.ts
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import * as Shared from './shared';
import * as InferenceAPI from './inference';
import * as ToolRuntimeAPI from './tool-runtime/tool-runtime';
export interface AgentConfig {
instructions: string;
model: string;
client_tools?: Array<ToolRuntimeAPI.ToolDef>;
enable_session_persistence?: boolean;
input_shields?: Array<string>;
max_infer_iters?: number;
output_shields?: Array<string>;
/**
* Configuration for JSON schema-guided response generation.
*/
response_format?: ResponseFormat;
sampling_params?: SamplingParams;
/**
* Whether tool use is required or automatic. This is a hint to the model which may
* not be followed. It depends on the Instruction Following capabilities of the
* model.
*/
tool_choice?: 'auto' | 'required';
/**
* Configuration for tool use.
*/
tool_config?: AgentConfig.ToolConfig;
/**
* Prompt format for calling custom / zero shot tools.
*/
tool_prompt_format?: 'json' | 'function_tag' | 'python_list';
toolgroups?: Array<string | AgentConfig.UnionMember1>;
}
export namespace AgentConfig {
/**
* Configuration for tool use.
*/
export interface ToolConfig {
/**
* (Optional) Config for how to override the default system prompt. -
* `SystemMessageBehavior.append`: Appends the provided system message to the
* default system prompt. - `SystemMessageBehavior.replace`: Replaces the default
* system prompt with the provided system message. The system message can include
* the string '{{function_definitions}}' to indicate where the function definitions
* should be inserted.
*/
system_message_behavior: 'append' | 'replace';
/**
* (Optional) Whether tool use is required or automatic. Defaults to
* ToolChoice.auto.
*/
tool_choice?: 'auto' | 'required';
/**
* (Optional) Instructs the model how to format tool calls. By default, Llama Stack
* will attempt to use a format that is best adapted to the model. -
* `ToolPromptFormat.json`: The tool calls are formatted as a JSON object. -
* `ToolPromptFormat.function_tag`: The tool calls are enclosed in a
* <function=function_name> tag. - `ToolPromptFormat.python_list`: The tool calls
* are output as Python syntax -- a list of function calls.
*/
tool_prompt_format?: 'json' | 'function_tag' | 'python_list';
}
export interface UnionMember1 {
args: Record<string, boolean | number | string | Array<unknown> | unknown | null>;
name: string;
}
}
export interface BatchCompletion {
batch: Array<InferenceAPI.CompletionResponse>;
}
/**
* Response from a chat completion request.
*/
export interface ChatCompletionResponse {
/**
* The complete response message
*/
completion_message: CompletionMessage;
/**
* Optional log probabilities for generated tokens
*/
logprobs?: Array<InferenceAPI.TokenLogProbs>;
metrics?: Array<ChatCompletionResponse.Metric>;
}
export namespace ChatCompletionResponse {
export interface Metric {
metric: string;
span_id: string;
timestamp: string;
trace_id: string;
type: 'metric';
unit: string;
value: number;
attributes?: Record<string, string | number | boolean | null>;
}
}
/**
* A message containing the model's (assistant) response in a chat conversation.
*/
export interface CompletionMessage {
/**
* The content of the model's response
*/
content: InterleavedContent;
/**
* Must be "assistant" to identify this as the model's response
*/
role: 'assistant';
/**
* Reason why the model stopped generating. Options are: -
* `StopReason.end_of_turn`: The model finished generating the entire response. -
* `StopReason.end_of_message`: The model finished generating but generated a
* partial response -- usually, a tool call. The user may call the tool and
* continue the conversation with the tool's response. -
* `StopReason.out_of_tokens`: The model ran out of token budget.
*/
stop_reason: 'end_of_turn' | 'end_of_message' | 'out_of_tokens';
/**
* List of tool calls. Each tool call is a ToolCall object.
*/
tool_calls?: Array<ToolCall>;
}
export type ContentDelta = ContentDelta.TextDelta | ContentDelta.ImageDelta | ContentDelta.ToolCallDelta;
export namespace ContentDelta {
export interface TextDelta {
text: string;
type: 'text';
}
export interface ImageDelta {
image: string;
type: 'image';
}
export interface ToolCallDelta {
parse_status: 'started' | 'in_progress' | 'failed' | 'succeeded';
tool_call: Shared.ToolCallOrString;
type: 'tool_call';
}
}
export interface Document {
/**
* A image content item
*/
content:
| string
| Document.ImageContentItem
| Document.TextContentItem
| Array<InterleavedContentItem>
| Document.URL;
document_id: string;
metadata: Record<string, boolean | number | string | Array<unknown> | unknown | null>;
mime_type?: string;
}
export namespace Document {
/**
* A image content item
*/
export interface ImageContentItem {
/**
* Image as a base64 encoded string or an URL
*/
image: ImageContentItem.Image;
/**
* Discriminator type of the content item. Always "image"
*/
type: 'image';
}
export namespace ImageContentItem {
/**
* Image as a base64 encoded string or an URL
*/
export interface Image {
/**
* base64 encoded image data as string
*/
data?: string;
/**
* A URL of the image or data URL in the format of data:image/{type};base64,{data}.
* Note that URL could have length limits.
*/
url?: Image.URL;
}
export namespace Image {
/**
* A URL of the image or data URL in the format of data:image/{type};base64,{data}.
* Note that URL could have length limits.
*/
export interface URL {
uri: string;
}
}
}
/**
* A text content item
*/
export interface TextContentItem {
/**
* Text content
*/
text: string;
/**
* Discriminator type of the content item. Always "text"
*/
type: 'text';
}
export interface URL {
uri: string;
}
}
/**
* A image content item
*/
export type InterleavedContent =
| string
| InterleavedContent.ImageContentItem
| InterleavedContent.TextContentItem
| Array<InterleavedContentItem>;
export namespace InterleavedContent {
/**
* A image content item
*/
export interface ImageContentItem {
/**
* Image as a base64 encoded string or an URL
*/
image: ImageContentItem.Image;
/**
* Discriminator type of the content item. Always "image"
*/
type: 'image';
}
export namespace ImageContentItem {
/**
* Image as a base64 encoded string or an URL
*/
export interface Image {
/**
* base64 encoded image data as string
*/
data?: string;
/**
* A URL of the image or data URL in the format of data:image/{type};base64,{data}.
* Note that URL could have length limits.
*/
url?: Image.URL;
}
export namespace Image {
/**
* A URL of the image or data URL in the format of data:image/{type};base64,{data}.
* Note that URL could have length limits.
*/
export interface URL {
uri: string;
}
}
}
/**
* A text content item
*/
export interface TextContentItem {
/**
* Text content
*/
text: string;
/**
* Discriminator type of the content item. Always "text"
*/
type: 'text';
}
}
/**
* A image content item
*/
export type InterleavedContentItem =
| InterleavedContentItem.ImageContentItem
| InterleavedContentItem.TextContentItem;
export namespace InterleavedContentItem {
/**
* A image content item
*/
export interface ImageContentItem {
/**
* Image as a base64 encoded string or an URL
*/
image: ImageContentItem.Image;
/**
* Discriminator type of the content item. Always "image"
*/
type: 'image';
}
export namespace ImageContentItem {
/**
* Image as a base64 encoded string or an URL
*/
export interface Image {
/**
* base64 encoded image data as string
*/
data?: string;
/**
* A URL of the image or data URL in the format of data:image/{type};base64,{data}.
* Note that URL could have length limits.
*/
url?: Image.URL;
}
export namespace Image {
/**
* A URL of the image or data URL in the format of data:image/{type};base64,{data}.
* Note that URL could have length limits.
*/
export interface URL {
uri: string;
}
}
}
/**
* A text content item
*/
export interface TextContentItem {
/**
* Text content
*/
text: string;
/**
* Discriminator type of the content item. Always "text"
*/
type: 'text';
}
}
/**
* A message from the user in a chat conversation.
*/
export type Message = UserMessage | SystemMessage | ToolResponseMessage | CompletionMessage;
export type ParamType =
| ParamType.StringType
| ParamType.NumberType
| ParamType.BooleanType
| ParamType.ArrayType
| ParamType.ObjectType
| ParamType.JsonType
| ParamType.UnionType
| ParamType.ChatCompletionInputType
| ParamType.CompletionInputType
| ParamType.AgentTurnInputType;
export namespace ParamType {
export interface StringType {
type: 'string';
}
export interface NumberType {
type: 'number';
}
export interface BooleanType {
type: 'boolean';
}
export interface ArrayType {
type: 'array';
}
export interface ObjectType {
type: 'object';
}
export interface JsonType {
type: 'json';
}
export interface UnionType {
type: 'union';
}
export interface ChatCompletionInputType {
type: 'chat_completion_input';
}
export interface CompletionInputType {
type: 'completion_input';
}
export interface AgentTurnInputType {
type: 'agent_turn_input';
}
}
export interface QueryConfig {
max_chunks: number;
max_tokens_in_context: number;
query_generator_config: QueryGeneratorConfig;
}
export type QueryGeneratorConfig =
| QueryGeneratorConfig.DefaultRagQueryGeneratorConfig
| QueryGeneratorConfig.LlmragQueryGeneratorConfig;
export namespace QueryGeneratorConfig {
export interface DefaultRagQueryGeneratorConfig {
separator: string;
type: 'default';
}
export interface LlmragQueryGeneratorConfig {
model: string;
template: string;
type: 'llm';
}
}
export interface QueryResult {
/**
* A image content item
*/
content?: InterleavedContent;
}
/**
* Configuration for JSON schema-guided response generation.
*/
export type ResponseFormat = ResponseFormat.JsonSchemaResponseFormat | ResponseFormat.GrammarResponseFormat;
export namespace ResponseFormat {
/**
* Configuration for JSON schema-guided response generation.
*/
export interface JsonSchemaResponseFormat {
/**
* The JSON schema the response should conform to. In a Python SDK, this is often a
* `pydantic` model.
*/
json_schema: Record<string, boolean | number | string | Array<unknown> | unknown | null>;
/**
* Must be "json_schema" to identify this format type
*/
type: 'json_schema';
}
/**
* Configuration for grammar-guided response generation.
*/
export interface GrammarResponseFormat {
/**
* The BNF grammar specification the response should conform to
*/
bnf: Record<string, boolean | number | string | Array<unknown> | unknown | null>;
/**
* Must be "grammar" to identify this format type
*/
type: 'grammar';
}
}
export interface ReturnType {
type:
| 'string'
| 'number'
| 'boolean'
| 'array'
| 'object'
| 'json'
| 'union'
| 'chat_completion_input'
| 'completion_input'
| 'agent_turn_input';
}
export interface SafetyViolation {
metadata: Record<string, boolean | number | string | Array<unknown> | unknown | null>;
violation_level: 'info' | 'warn' | 'error';
user_message?: string;
}
export interface SamplingParams {
strategy:
| SamplingParams.GreedySamplingStrategy
| SamplingParams.TopPSamplingStrategy
| SamplingParams.TopKSamplingStrategy;
max_tokens?: number;
repetition_penalty?: number;
}
export namespace SamplingParams {
export interface GreedySamplingStrategy {
type: 'greedy';
}
export interface TopPSamplingStrategy {
type: 'top_p';
temperature?: number;
top_p?: number;
}
export interface TopKSamplingStrategy {
top_k: number;
type: 'top_k';
}
}
export interface ScoringResult {
aggregated_results: Record<string, boolean | number | string | Array<unknown> | unknown | null>;
score_rows: Array<Record<string, boolean | number | string | Array<unknown> | unknown | null>>;
}
/**
* A system message providing instructions or context to the model.
*/
export interface SystemMessage {
/**
* The content of the "system prompt". If multiple system messages are provided,
* they are concatenated. The underlying Llama Stack code may also add other system
* messages (for example, for formatting tool definitions).
*/
content: InterleavedContent;
/**
* Must be "system" to identify this as a system message
*/
role: 'system';
}
export interface ToolCall {
arguments: Record<
string,
| string
| number
| boolean
| Array<string | number | boolean | null>
| Record<string, string | number | boolean | null>
| null
>;
call_id: string;
tool_name: 'brave_search' | 'wolfram_alpha' | 'photogen' | 'code_interpreter' | (string & {});
}
export type ToolCallOrString = string | ToolCall;
export interface ToolParamDefinition {
param_type: string;
default?: boolean | number | string | Array<unknown> | unknown | null;
description?: string;
required?: boolean;
}
/**
* A message representing the result of a tool invocation.
*/
export interface ToolResponseMessage {
/**
* Unique identifier for the tool call this response is for
*/
call_id: string;
/**
* The response content from the tool
*/
content: InterleavedContent;
/**
* Must be "tool" to identify this as a tool response
*/
role: 'tool';
/**
* Name of the tool that was called
*/
tool_name: 'brave_search' | 'wolfram_alpha' | 'photogen' | 'code_interpreter' | (string & {});
}
/**
* A message from the user in a chat conversation.
*/
export interface UserMessage {
/**
* The content of the message, which can include text and other media
*/
content: InterleavedContent;
/**
* Must be "user" to identify this as a user message
*/
role: 'user';
/**
* (Optional) This field is used internally by Llama Stack to pass RAG context.
* This field may be removed in the API in the future.
*/
context?: InterleavedContent;
}