-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtune.ts
145 lines (133 loc) · 5.23 KB
/
tune.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
// 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 JobsAPI from './jobs';
import { JobDeleteResponse, Jobs, ListTuneJobsResponse, TuneJobMetadata } from './jobs';
import * as ModelsAPI from './models';
import { ListTuneModelsResponse, Models } from './models';
export class Tune extends APIResource {
jobs: JobsAPI.Jobs = new JobsAPI.Jobs(this._client);
models: ModelsAPI.Models = new ModelsAPI.Models(this._client);
/**
* Create a tuning job for the specified `Agent` to specialize it to your specific
* domain or use case.
*
* This API initiates an asynchronous tuning task. You can provide the required
* data through one of two ways:
*
* - Provide a `training_file` and an optional `test_file`. If no `test_file` is
* provided, a portion of the `training_file` will be held out as the test set.
* For easy reusability, the `training_file` is automatically saved as a `Tuning`
* `Dataset`, and the `test_file` as an `Evaluation` `Dataset`. You can manage
* them via the `/datasets/tune` and `/datasets/evaluation` endpoints.
*
* - Provide a `Tuning` `Dataset` and an optional `Evaluation` `Dataset`. You can
* create a `Tuning` `Dataset` and `Evaluation` `Dataset` using the
* `/datasets/tune` and `/datasets/evaluation` endpoints respectively.
*
* The API returns a tune job `id` which can be used to check on the status of your
* tuning task through the `GET /tune/jobs/{job_id}/metadata` endpoint.
*
* After the tuning job is complete, the metadata associated with the tune job will
* include evaluation results and a model ID. You can then deploy the tuned model
* to the agent by editing its config with the tuned model ID and the "Edit Agent"
* API (i.e. the `PUT /agents/{agent_id}` API). To deactivate the tuned model, you
* will need to edit the Agent's config again and set the `llm_model_id` field to
* "default". For an end-to-end walkthrough, see the `Tune & Evaluation Guide`.
*/
create(
agentId: string,
body?: TuneCreateParams,
options?: Core.RequestOptions,
): Core.APIPromise<CreateTuneResponse>;
create(agentId: string, options?: Core.RequestOptions): Core.APIPromise<CreateTuneResponse>;
create(
agentId: string,
body: TuneCreateParams | Core.RequestOptions = {},
options?: Core.RequestOptions,
): Core.APIPromise<CreateTuneResponse> {
if (isRequestOptions(body)) {
return this.create(agentId, {}, body);
}
return this._client.post(
`/agents/${agentId}/tune`,
Core.multipartFormRequestOptions({ body, ...options }),
);
}
}
/**
* Response to POST /applications/{application_id}/tune request
*/
export interface CreateTuneResponse {
/**
* ID of the created tune job
*/
id: string;
}
export interface TuneCreateParams {
/**
* Optional. `Dataset` to use for testing model checkpoints, created through the
* `/datasets/evaluate` API.
*/
test_dataset_name?: string | null;
/**
* Optional. Local path to the test data file. The test file should follow the same
* format as the training data file.
*/
test_file?: Core.Uploadable | null;
/**
* `Dataset` to use for training, created through the `/datasets/tune` API. Either
* `train_dataset_name` or `training_file` must be provided, but not both.
*/
train_dataset_name?: string | null;
/**
* Local path to the training data file.
*
* The file should be in JSON array format, where each element of the array is a
* JSON object represents a single training example. The four required fields are
* `guideline`, `prompt`, `reference`, and `knowledge`.
*
* - `knowledge` (`list[str]`): Retrieved knowledge used to generate the reference
* answer. `knowledge` is a list of retrieved text chunks.
*
* - `reference` (`str`): The gold-standard answer to the prompt.
*
* - `guideline` (`str`): Guidelines for model output. If you do not have special
* guidelines for the model's output, you can use the `System Prompt` defined in
* your Agent configuration as the `guideline`.
*
* - `prompt` (`str`): Question for the model to respond to.
*
* Example:
*
* ```json
* [
* {
* "guideline": "The answer should be accurate.",
* "prompt": "What was last quarter's revenue?",
* "reference": "According to recent reports, the Q3 revenue was $1.2 million, a 0.1 million increase from Q2.",
* "knowledge": [
* "Quarterly report: Q3 revenue was $1.2 million.",
* "Quarterly report: Q2 revenue was $1.1 million.",
* ...
* ],
* },
* ...
* ]
* ```
*/
training_file?: Core.Uploadable | null;
}
Tune.Jobs = Jobs;
Tune.Models = Models;
export declare namespace Tune {
export { type CreateTuneResponse as CreateTuneResponse, type TuneCreateParams as TuneCreateParams };
export {
Jobs as Jobs,
type ListTuneJobsResponse as ListTuneJobsResponse,
type TuneJobMetadata as TuneJobMetadata,
type JobDeleteResponse as JobDeleteResponse,
};
export { Models as Models, type ListTuneModelsResponse as ListTuneModelsResponse };
}