-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathcommit.go
More file actions
372 lines (333 loc) · 13 KB
/
Copy pathcommit.go
File metadata and controls
372 lines (333 loc) · 13 KB
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
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package langsmith
import (
"context"
"errors"
"fmt"
"net/http"
"net/url"
"slices"
"time"
"github.com/langchain-ai/langsmith-go/internal/apijson"
"github.com/langchain-ai/langsmith-go/internal/apiquery"
"github.com/langchain-ai/langsmith-go/internal/param"
"github.com/langchain-ai/langsmith-go/internal/requestconfig"
"github.com/langchain-ai/langsmith-go/option"
"github.com/langchain-ai/langsmith-go/packages/pagination"
)
// CommitService contains methods and other services that help with interacting
// with the langChain API.
//
// Note, unlike clients, this service does not read variables from the environment
// automatically. You should not instantiate this service directly, and instead use
// the [NewCommitService] method instead.
type CommitService struct {
Options []option.RequestOption
}
// NewCommitService generates a new service that applies the given options to each
// request. These options are applied after the parent client's options (if there
// is one), and before any request-specific options.
func NewCommitService(opts ...option.RequestOption) (r *CommitService) {
r = &CommitService{}
r.Options = opts
return
}
// Creates a new commit in a repository. Requires authentication and write access
// to the repository.
func (r *CommitService) New(ctx context.Context, owner string, repo string, body CommitNewParams, opts ...option.RequestOption) (res *CommitNewResponse, err error) {
opts = slices.Concat(r.Options, opts)
if owner == "" {
err = errors.New("missing required owner parameter")
return nil, err
}
if repo == "" {
err = errors.New("missing required repo parameter")
return nil, err
}
path := fmt.Sprintf("api/v1/commits/%s/%s", owner, repo)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return res, err
}
// Retrieves a specific commit by hash, tag, or "latest" for a repository. This
// endpoint supports both authenticated and unauthenticated access. Authenticated
// users can access private repos, while unauthenticated users can only access
// public repos. Commit resolution logic:
//
// - "latest" or empty: Get the most recent commit
// - Less than 8 characters: Only check for tags
// - 8 or more characters: Prioritize commit hash over tag, check both
func (r *CommitService) Get(ctx context.Context, owner string, repo string, commit string, query CommitGetParams, opts ...option.RequestOption) (res *CommitGetResponse, err error) {
opts = slices.Concat(r.Options, opts)
if owner == "" {
err = errors.New("missing required owner parameter")
return nil, err
}
if repo == "" {
err = errors.New("missing required repo parameter")
return nil, err
}
if commit == "" {
err = errors.New("missing required commit parameter")
return nil, err
}
path := fmt.Sprintf("api/v1/commits/%s/%s/%s", owner, repo, commit)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...)
return res, err
}
// List commits for a repository, with pagination support. This endpoint supports
// both authenticated and unauthenticated access. Authenticated users can access
// private repositories; unauthenticated users can only access public repositories.
// The include_stats parameter controls whether download and view statistics are
// computed (defaults to true).
func (r *CommitService) List(ctx context.Context, owner string, repo string, query CommitListParams, opts ...option.RequestOption) (res *pagination.OffsetPaginationCommits[CommitWithLookups], err error) {
var raw *http.Response
opts = slices.Concat(r.Options, opts)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
if owner == "" {
err = errors.New("missing required owner parameter")
return nil, err
}
if repo == "" {
err = errors.New("missing required repo parameter")
return nil, err
}
path := fmt.Sprintf("api/v1/commits/%s/%s", owner, repo)
cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, query, &res, opts...)
if err != nil {
return nil, err
}
err = cfg.Execute()
if err != nil {
return nil, err
}
res.SetPageConfig(cfg, raw)
return res, nil
}
// List commits for a repository, with pagination support. This endpoint supports
// both authenticated and unauthenticated access. Authenticated users can access
// private repositories; unauthenticated users can only access public repositories.
// The include_stats parameter controls whether download and view statistics are
// computed (defaults to true).
func (r *CommitService) ListAutoPaging(ctx context.Context, owner string, repo string, query CommitListParams, opts ...option.RequestOption) *pagination.OffsetPaginationCommitsAutoPager[CommitWithLookups] {
return pagination.NewOffsetPaginationCommitsAutoPager(r.List(ctx, owner, repo, query, opts...))
}
// Response model for get_commit_manifest.
type CommitManifestResponse struct {
CommitHash string `json:"commit_hash" api:"required"`
Manifest map[string]interface{} `json:"manifest" api:"required"`
Examples []CommitManifestResponseExample `json:"examples" api:"nullable"`
JSON commitManifestResponseJSON `json:"-"`
}
// commitManifestResponseJSON contains the JSON metadata for the struct
// [CommitManifestResponse]
type commitManifestResponseJSON struct {
CommitHash apijson.Field
Manifest apijson.Field
Examples apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *CommitManifestResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r commitManifestResponseJSON) RawJSON() string {
return r.raw
}
// Response model for example runs
type CommitManifestResponseExample struct {
ID string `json:"id" api:"required" format:"uuid"`
SessionID string `json:"session_id" api:"required" format:"uuid"`
Inputs map[string]interface{} `json:"inputs" api:"nullable"`
Outputs map[string]interface{} `json:"outputs" api:"nullable"`
StartTime time.Time `json:"start_time" api:"nullable" format:"date-time"`
JSON commitManifestResponseExampleJSON `json:"-"`
}
// commitManifestResponseExampleJSON contains the JSON metadata for the struct
// [CommitManifestResponseExample]
type commitManifestResponseExampleJSON struct {
ID apijson.Field
SessionID apijson.Field
Inputs apijson.Field
Outputs apijson.Field
StartTime apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *CommitManifestResponseExample) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r commitManifestResponseExampleJSON) RawJSON() string {
return r.raw
}
type CommitWithLookups struct {
// The commit ID
ID string `json:"id" format:"uuid"`
// The hash of the commit
CommitHash string `json:"commit_hash"`
// When the commit was created
CreatedAt time.Time `json:"created_at" format:"date-time"`
// Optional human-readable description for the commit
Description string `json:"description"`
// Example run IDs associated with the commit
ExampleRunIDs []string `json:"example_run_ids" format:"uuid"`
// Author's full name
FullName string `json:"full_name"`
// The manifest of the commit
Manifest interface{} `json:"manifest"`
// The SHA of the manifest
ManifestSha []int64 `json:"manifest_sha"`
// Number of API downloads
NumDownloads int64 `json:"num_downloads"`
// Number of web views
NumViews int64 `json:"num_views"`
// The hash of the parent commit
ParentCommitHash string `json:"parent_commit_hash"`
// The ID of the parent commit
ParentID string `json:"parent_id" format:"uuid"`
// Repository ID
RepoID string `json:"repo_id" format:"uuid"`
// When the commit was last updated
UpdatedAt time.Time `json:"updated_at" format:"date-time"`
JSON commitWithLookupsJSON `json:"-"`
}
// commitWithLookupsJSON contains the JSON metadata for the struct
// [CommitWithLookups]
type commitWithLookupsJSON struct {
ID apijson.Field
CommitHash apijson.Field
CreatedAt apijson.Field
Description apijson.Field
ExampleRunIDs apijson.Field
FullName apijson.Field
Manifest apijson.Field
ManifestSha apijson.Field
NumDownloads apijson.Field
NumViews apijson.Field
ParentCommitHash apijson.Field
ParentID apijson.Field
RepoID apijson.Field
UpdatedAt apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *CommitWithLookups) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r commitWithLookupsJSON) RawJSON() string {
return r.raw
}
type CommitNewResponse struct {
Commit CommitWithLookups `json:"commit"`
JSON commitNewResponseJSON `json:"-"`
}
// commitNewResponseJSON contains the JSON metadata for the struct
// [CommitNewResponse]
type commitNewResponseJSON struct {
Commit apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *CommitNewResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r commitNewResponseJSON) RawJSON() string {
return r.raw
}
type CommitGetResponse struct {
CommitHash string `json:"commit_hash"`
Description string `json:"description"`
Examples []CommitGetResponseExample `json:"examples"`
IsDraft bool `json:"is_draft"`
Manifest interface{} `json:"manifest"`
ModelConfig interface{} `json:"model_config"`
ModelProvider string `json:"model_provider"`
JSON commitGetResponseJSON `json:"-"`
}
// commitGetResponseJSON contains the JSON metadata for the struct
// [CommitGetResponse]
type commitGetResponseJSON struct {
CommitHash apijson.Field
Description apijson.Field
Examples apijson.Field
IsDraft apijson.Field
Manifest apijson.Field
ModelConfig apijson.Field
ModelProvider apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *CommitGetResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r commitGetResponseJSON) RawJSON() string {
return r.raw
}
type CommitGetResponseExample struct {
ID string `json:"id" format:"uuid"`
Inputs interface{} `json:"inputs"`
Outputs interface{} `json:"outputs"`
SessionID string `json:"session_id" format:"uuid"`
StartTime string `json:"start_time"`
JSON commitGetResponseExampleJSON `json:"-"`
}
// commitGetResponseExampleJSON contains the JSON metadata for the struct
// [CommitGetResponseExample]
type commitGetResponseExampleJSON struct {
ID apijson.Field
Inputs apijson.Field
Outputs apijson.Field
SessionID apijson.Field
StartTime apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *CommitGetResponseExample) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r commitGetResponseExampleJSON) RawJSON() string {
return r.raw
}
type CommitNewParams struct {
Description param.Field[string] `json:"description"`
Manifest param.Field[interface{}] `json:"manifest"`
ParentCommit param.Field[string] `json:"parent_commit"`
// SkipWebhooks allows skipping webhook notifications. Can be true (boolean) to
// skip all, or an array of webhook UUIDs to skip specific ones.
SkipWebhooks param.Field[interface{}] `json:"skip_webhooks"`
}
func (r CommitNewParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type CommitGetParams struct {
GetExamples param.Field[bool] `query:"get_examples"`
// Comma-separated list of optional fields: "model", "is_draft"
Include param.Field[string] `query:"include"`
// Deprecated: use Include instead
IncludeModel param.Field[bool] `query:"include_model"`
IsView param.Field[bool] `query:"is_view"`
}
// URLQuery serializes [CommitGetParams]'s query parameters as `url.Values`.
func (r CommitGetParams) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatRepeat,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}
type CommitListParams struct {
// IncludeStats determines whether to compute num_downloads and num_views
IncludeStats param.Field[bool] `query:"include_stats"`
// Limit is the pagination limit
Limit param.Field[int64] `query:"limit"`
// Offset is the pagination offset
Offset param.Field[int64] `query:"offset"`
// Tag filters commits to only those with a specific tag (e.g. "production",
// "staging")
Tag param.Field[string] `query:"tag"`
}
// URLQuery serializes [CommitListParams]'s query parameters as `url.Values`.
func (r CommitListParams) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatRepeat,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}