-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathagents.ts
694 lines (597 loc) · 19.1 KB
/
agents.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
682
683
684
685
686
687
688
689
690
691
692
693
694
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from '../../resource';
import { isRequestOptions } from '../../core';
import * as Core from '../../core';
import * as QueryAPI from './query';
import {
Query,
QueryCreateParams,
QueryFeedbackParams,
QueryFeedbackResponse,
QueryMetricsParams,
QueryMetricsResponse,
QueryResponse,
QueryRetrievalInfoParams,
RetrievalInfoResponse,
} from './query';
import * as DatasetsAPI from './datasets/datasets';
import { CreateDatasetResponse, DatasetMetadata, Datasets, ListDatasetsResponse } from './datasets/datasets';
import * as EvaluateAPI from './evaluate/evaluate';
import { CreateEvaluationResponse, Evaluate, EvaluateCreateParams } from './evaluate/evaluate';
import * as TuneAPI from './tune/tune';
import { CreateTuneResponse, Tune, TuneCreateParams } from './tune/tune';
import { Page, type PageParams } from '../../pagination';
export class Agents extends APIResource {
query: QueryAPI.Query = new QueryAPI.Query(this._client);
evaluate: EvaluateAPI.Evaluate = new EvaluateAPI.Evaluate(this._client);
datasets: DatasetsAPI.Datasets = new DatasetsAPI.Datasets(this._client);
tune: TuneAPI.Tune = new TuneAPI.Tune(this._client);
/**
* Create a new `Agent` with a specific configuration.
*
* This creates a specialized RAG `Agent` which queries over one or multiple
* `Datastores` to retrieve relevant data on which its generations are grounded.
*
* Retrieval and generation parameters are defined in the provided `Agent`
* configuration.
*
* If no `datastore_id` is provided in the configuration, this API automatically
* creates an empty `Datastore` and configures the `Agent` to use the newly created
* `Datastore`.
*
* > Note that self-serve users are currently required to create agents through our
* > UI. Otherwise, they will receive the following message: "This endpoint is
* > disabled as you need to go through checkout. Please use the UI to make this
* > request."
*/
create(body: AgentCreateParams, options?: Core.RequestOptions): Core.APIPromise<CreateAgentOutput> {
return this._client.post('/agents', { body, ...options });
}
/**
* Modify a given `Agent` to utilize the provided configuration.
*
* Fields not included in the request body will not be modified.
*/
update(agentId: string, body: AgentUpdateParams, options?: Core.RequestOptions): Core.APIPromise<unknown> {
return this._client.put(`/agents/${agentId}`, { body, ...options });
}
/**
* Retrieve a list of all `Agents`.
*/
list(query?: AgentListParams, options?: Core.RequestOptions): Core.PagePromise<AgentsPage, Agent>;
list(options?: Core.RequestOptions): Core.PagePromise<AgentsPage, Agent>;
list(
query: AgentListParams | Core.RequestOptions = {},
options?: Core.RequestOptions,
): Core.PagePromise<AgentsPage, Agent> {
if (isRequestOptions(query)) {
return this.list({}, query);
}
return this._client.getAPIList('/agents', AgentsPage, { query, ...options });
}
/**
* Delete a given `Agent`. This is an irreversible operation.
*
* Note: `Datastores` which are associated with the `Agent` will not be deleted,
* even if no other `Agent` is using them. To delete a `Datastore`, use the
* `DELETE /datastores/{datastore_id}` API.
*/
delete(agentId: string, options?: Core.RequestOptions): Core.APIPromise<unknown> {
return this._client.delete(`/agents/${agentId}`, options);
}
/**
* Get metadata and configuration of a given `Agent`.
*/
metadata(agentId: string, options?: Core.RequestOptions): Core.APIPromise<AgentMetadata> {
return this._client.get(`/agents/${agentId}/metadata`, options);
}
}
export class AgentsPage extends Page<Agent> {}
export interface Agent {
/**
* ID of the agent
*/
id: string;
/**
* Description of the agent
*/
description: string;
/**
* Name of the agent
*/
name: string;
}
/**
* Response to GET Agent request
*/
export interface AgentMetadata {
/**
* The IDs of the datastore(s) associated with the agent
*/
datastore_ids: Array<string>;
/**
* Name of the agent
*/
name: string;
/**
* The following advanced parameters are experimental and subject to change.
*/
agent_configs?: AgentMetadata.AgentConfigs;
/**
* Description of the agent
*/
description?: string;
/**
* The prompt to an LLM which determines whether retrieved chunks are relevant to a
* given query and filters out irrelevant chunks. This prompt is applied per chunk.
*/
filter_prompt?: string;
/**
* The model ID to use for generation. Tuned models can only be used for the agents
* on which they were tuned. If no model is specified, the default model is used.
* Set to `default` to switch from a tuned model to the default model.
*/
llm_model_id?: string;
/**
* These queries will show up as suggestions in the Contextual UI when users load
* the agent. We recommend including common queries that users will ask, as well as
* complex queries so users understand the types of complex queries the system can
* handle. The max length of all the suggested queries is 1000.
*/
suggested_queries?: Array<string>;
/**
* Instructions that your agent references when generating responses. Note that we
* do not guarantee that the system will follow these instructions exactly.
*/
system_prompt?: string;
}
export namespace AgentMetadata {
/**
* The following advanced parameters are experimental and subject to change.
*/
export interface AgentConfigs {
/**
* Parameters that affect filtering and reranking of retrieved knowledge
*/
filter_and_rerank_config?: AgentConfigs.FilterAndRerankConfig;
/**
* Parameters that affect response generation
*/
generate_response_config?: AgentConfigs.GenerateResponseConfig;
/**
* Parameters that affect the agent's overall RAG workflow
*/
global_config?: AgentConfigs.GlobalConfig;
/**
* Parameters that affect how the agent retrieves from datastore(s)
*/
retrieval_config?: AgentConfigs.RetrievalConfig;
}
export namespace AgentConfigs {
/**
* Parameters that affect filtering and reranking of retrieved knowledge
*/
export interface FilterAndRerankConfig {
/**
* The number of highest ranked chunks after reranking to be used
*/
top_k_reranked_chunks?: number;
}
/**
* Parameters that affect response generation
*/
export interface GenerateResponseConfig {
/**
* This parameter controls generation of groundedness scores.
*/
calculate_groundedness?: boolean;
/**
* This parameter adjusts how the model treats repeated tokens during text
* generation.
*/
frequency_penalty?: number;
/**
* The maximum number of tokens the model can generate in a response.
*/
max_new_tokens?: number;
/**
* This parameter controls the randomness of how the model selects the next tokens
* during text generation.
*/
seed?: number;
/**
* The sampling temperature, which affects the randomness in the response.
*/
temperature?: number;
/**
* A parameter for nucleus sampling, an alternative to `temperature` which also
* affects the randomness of the response.
*/
top_p?: number;
}
/**
* Parameters that affect the agent's overall RAG workflow
*/
export interface GlobalConfig {
/**
* Enables filtering of retrieved chunks with a separate LLM
*/
enable_filter?: boolean;
/**
* Enables multi-turn conversations. This feature is currently experimental and
* will be improved.
*/
enable_multi_turn?: boolean;
/**
* Enables reranking of retrieved chunks
*/
enable_rerank?: boolean;
}
/**
* Parameters that affect how the agent retrieves from datastore(s)
*/
export interface RetrievalConfig {
/**
* The weight of lexical search during retrieval
*/
lexical_alpha?: number;
/**
* The weight of semantic search during retrieval
*/
semantic_alpha?: number;
/**
* The maximum number of retrieved chunks from the datastore.
*/
top_k_retrieved_chunks?: number;
}
}
}
/**
* Response to POST /agents request
*/
export interface CreateAgentOutput {
/**
* ID of the agent
*/
id: string;
/**
* IDs of the datastores associated with the agent. If no datastore was provided as
* part of the request, this is a singleton list containing the ID of the
* automatically created datastore.
*/
datastore_ids: Array<string>;
}
export interface ListAgentsResponse {
/**
* Total number of available agents
*/
total_count: number;
/**
* List of active agents
*/
agents?: Array<Agent>;
/**
* Next cursor to continue pagination. Omitted if there are no more agents to
* retrieve.
*/
next_cursor?: string;
}
export type AgentUpdateResponse = unknown;
export type AgentDeleteResponse = unknown;
export interface AgentCreateParams {
/**
* Name of the agent
*/
name: string;
/**
* The following advanced parameters are experimental and subject to change.
*/
agent_configs?: AgentCreateParams.AgentConfigs;
/**
* The IDs of the datastore to associate with this agent.
*/
datastore_ids?: Array<string>;
/**
* Description of the agent
*/
description?: string;
/**
* The prompt to an LLM which determines whether retrieved chunks are relevant to a
* given query and filters out irrelevant chunks.
*/
filter_prompt?: string;
/**
* These queries will show up as suggestions in the Contextual UI when users load
* the agent. We recommend including common queries that users will ask, as well as
* complex queries so users understand the types of complex queries the system can
* handle. The max length of all the suggested queries is 1000.
*/
suggested_queries?: Array<string>;
/**
* Instructions that your agent references when generating responses. Note that we
* do not guarantee that the system will follow these instructions exactly.
*/
system_prompt?: string;
}
export namespace AgentCreateParams {
/**
* The following advanced parameters are experimental and subject to change.
*/
export interface AgentConfigs {
/**
* Parameters that affect filtering and reranking of retrieved knowledge
*/
filter_and_rerank_config?: AgentConfigs.FilterAndRerankConfig;
/**
* Parameters that affect response generation
*/
generate_response_config?: AgentConfigs.GenerateResponseConfig;
/**
* Parameters that affect the agent's overall RAG workflow
*/
global_config?: AgentConfigs.GlobalConfig;
/**
* Parameters that affect how the agent retrieves from datastore(s)
*/
retrieval_config?: AgentConfigs.RetrievalConfig;
}
export namespace AgentConfigs {
/**
* Parameters that affect filtering and reranking of retrieved knowledge
*/
export interface FilterAndRerankConfig {
/**
* The number of highest ranked chunks after reranking to be used
*/
top_k_reranked_chunks?: number;
}
/**
* Parameters that affect response generation
*/
export interface GenerateResponseConfig {
/**
* This parameter controls generation of groundedness scores.
*/
calculate_groundedness?: boolean;
/**
* This parameter adjusts how the model treats repeated tokens during text
* generation.
*/
frequency_penalty?: number;
/**
* The maximum number of tokens the model can generate in a response.
*/
max_new_tokens?: number;
/**
* This parameter controls the randomness of how the model selects the next tokens
* during text generation.
*/
seed?: number;
/**
* The sampling temperature, which affects the randomness in the response.
*/
temperature?: number;
/**
* A parameter for nucleus sampling, an alternative to `temperature` which also
* affects the randomness of the response.
*/
top_p?: number;
}
/**
* Parameters that affect the agent's overall RAG workflow
*/
export interface GlobalConfig {
/**
* Enables filtering of retrieved chunks with a separate LLM
*/
enable_filter?: boolean;
/**
* Enables multi-turn conversations. This feature is currently experimental and
* will be improved.
*/
enable_multi_turn?: boolean;
/**
* Enables reranking of retrieved chunks
*/
enable_rerank?: boolean;
}
/**
* Parameters that affect how the agent retrieves from datastore(s)
*/
export interface RetrievalConfig {
/**
* The weight of lexical search during retrieval
*/
lexical_alpha?: number;
/**
* The weight of semantic search during retrieval
*/
semantic_alpha?: number;
/**
* The maximum number of retrieved chunks from the datastore.
*/
top_k_retrieved_chunks?: number;
}
}
}
export interface AgentUpdateParams {
/**
* The following advanced parameters are experimental and subject to change.
*/
agent_configs?: AgentUpdateParams.AgentConfigs;
/**
* IDs of the datastore to associate with the agent.
*/
datastore_ids?: Array<string>;
/**
* The prompt to an LLM which determines whether retrieved chunks are relevant to a
* given query and filters out irrelevant chunks.
*/
filter_prompt?: string;
/**
* The model ID to use for generation. Tuned models can only be used for the agents
* on which they were tuned. If no model is specified, the default model is used.
* Set to `default` to switch from a tuned model to the default model.
*/
llm_model_id?: string;
/**
* These queries will show up as suggestions in the Contextual UI when users load
* the agent. We recommend including common queries that users will ask, as well as
* complex queries so users understand the types of complex queries the system can
* handle. The max length of all the suggested queries is 1000.
*/
suggested_queries?: Array<string>;
/**
* Instructions that your agent references when generating responses. Note that we
* do not guarantee that the system will follow these instructions exactly.
*/
system_prompt?: string;
}
export namespace AgentUpdateParams {
/**
* The following advanced parameters are experimental and subject to change.
*/
export interface AgentConfigs {
/**
* Parameters that affect filtering and reranking of retrieved knowledge
*/
filter_and_rerank_config?: AgentConfigs.FilterAndRerankConfig;
/**
* Parameters that affect response generation
*/
generate_response_config?: AgentConfigs.GenerateResponseConfig;
/**
* Parameters that affect the agent's overall RAG workflow
*/
global_config?: AgentConfigs.GlobalConfig;
/**
* Parameters that affect how the agent retrieves from datastore(s)
*/
retrieval_config?: AgentConfigs.RetrievalConfig;
}
export namespace AgentConfigs {
/**
* Parameters that affect filtering and reranking of retrieved knowledge
*/
export interface FilterAndRerankConfig {
/**
* The number of highest ranked chunks after reranking to be used
*/
top_k_reranked_chunks?: number;
}
/**
* Parameters that affect response generation
*/
export interface GenerateResponseConfig {
/**
* This parameter controls generation of groundedness scores.
*/
calculate_groundedness?: boolean;
/**
* This parameter adjusts how the model treats repeated tokens during text
* generation.
*/
frequency_penalty?: number;
/**
* The maximum number of tokens the model can generate in a response.
*/
max_new_tokens?: number;
/**
* This parameter controls the randomness of how the model selects the next tokens
* during text generation.
*/
seed?: number;
/**
* The sampling temperature, which affects the randomness in the response.
*/
temperature?: number;
/**
* A parameter for nucleus sampling, an alternative to `temperature` which also
* affects the randomness of the response.
*/
top_p?: number;
}
/**
* Parameters that affect the agent's overall RAG workflow
*/
export interface GlobalConfig {
/**
* Enables filtering of retrieved chunks with a separate LLM
*/
enable_filter?: boolean;
/**
* Enables multi-turn conversations. This feature is currently experimental and
* will be improved.
*/
enable_multi_turn?: boolean;
/**
* Enables reranking of retrieved chunks
*/
enable_rerank?: boolean;
}
/**
* Parameters that affect how the agent retrieves from datastore(s)
*/
export interface RetrievalConfig {
/**
* The weight of lexical search during retrieval
*/
lexical_alpha?: number;
/**
* The weight of semantic search during retrieval
*/
semantic_alpha?: number;
/**
* The maximum number of retrieved chunks from the datastore.
*/
top_k_retrieved_chunks?: number;
}
}
}
export interface AgentListParams extends PageParams {}
Agents.AgentsPage = AgentsPage;
Agents.Query = Query;
Agents.Evaluate = Evaluate;
Agents.Datasets = Datasets;
Agents.Tune = Tune;
export declare namespace Agents {
export {
type Agent as Agent,
type AgentMetadata as AgentMetadata,
type CreateAgentOutput as CreateAgentOutput,
type ListAgentsResponse as ListAgentsResponse,
type AgentUpdateResponse as AgentUpdateResponse,
type AgentDeleteResponse as AgentDeleteResponse,
AgentsPage as AgentsPage,
type AgentCreateParams as AgentCreateParams,
type AgentUpdateParams as AgentUpdateParams,
type AgentListParams as AgentListParams,
};
export {
Query as Query,
type QueryResponse as QueryResponse,
type RetrievalInfoResponse as RetrievalInfoResponse,
type QueryFeedbackResponse as QueryFeedbackResponse,
type QueryMetricsResponse as QueryMetricsResponse,
type QueryCreateParams as QueryCreateParams,
type QueryFeedbackParams as QueryFeedbackParams,
type QueryMetricsParams as QueryMetricsParams,
type QueryRetrievalInfoParams as QueryRetrievalInfoParams,
};
export {
Evaluate as Evaluate,
type CreateEvaluationResponse as CreateEvaluationResponse,
type EvaluateCreateParams as EvaluateCreateParams,
};
export {
Datasets as Datasets,
type CreateDatasetResponse as CreateDatasetResponse,
type DatasetMetadata as DatasetMetadata,
type ListDatasetsResponse as ListDatasetsResponse,
};
export {
Tune as Tune,
type CreateTuneResponse as CreateTuneResponse,
type TuneCreateParams as TuneCreateParams,
};
}