Skip to content

Commit 2cd6aad

Browse files
chore(closes OPEN-8647): add endpoint to retrieve aggregated user data for inference pipelines
1 parent a992a58 commit 2cd6aad

File tree

4 files changed

+128
-3
lines changed

4 files changed

+128
-3
lines changed

.stats.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
configured_endpoints: 26
2-
openapi_spec_hash: 6f6cb98b7755d18274dd51e857508336
3-
config_hash: cc9a32249c08143687799eb8de187d6a
1+
configured_endpoints: 27
2+
openapi_spec_hash: c70c3eccfe803e99c14e97e650b1e314
3+
config_hash: 1f7626e569e1a74574a58d7883170a0e

api.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,14 @@ Response Types:
109109

110110
- <a href="https://pkg.go.dev/github.com/openlayer-ai/openlayer-go">openlayer</a>.<a href="https://pkg.go.dev/github.com/openlayer-ai/openlayer-go#InferencePipelineGetResponse">InferencePipelineGetResponse</a>
111111
- <a href="https://pkg.go.dev/github.com/openlayer-ai/openlayer-go">openlayer</a>.<a href="https://pkg.go.dev/github.com/openlayer-ai/openlayer-go#InferencePipelineUpdateResponse">InferencePipelineUpdateResponse</a>
112+
- <a href="https://pkg.go.dev/github.com/openlayer-ai/openlayer-go">openlayer</a>.<a href="https://pkg.go.dev/github.com/openlayer-ai/openlayer-go#InferencePipelineGetUsersResponse">InferencePipelineGetUsersResponse</a>
112113

113114
Methods:
114115

115116
- <code title="get /inference-pipelines/{inferencePipelineId}">client.InferencePipelines.<a href="https://pkg.go.dev/github.com/openlayer-ai/openlayer-go#InferencePipelineService.Get">Get</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, inferencePipelineID <a href="https://pkg.go.dev/builtin#string">string</a>, query <a href="https://pkg.go.dev/github.com/openlayer-ai/openlayer-go">openlayer</a>.<a href="https://pkg.go.dev/github.com/openlayer-ai/openlayer-go#InferencePipelineGetParams">InferencePipelineGetParams</a>) (\*<a href="https://pkg.go.dev/github.com/openlayer-ai/openlayer-go">openlayer</a>.<a href="https://pkg.go.dev/github.com/openlayer-ai/openlayer-go#InferencePipelineGetResponse">InferencePipelineGetResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
116117
- <code title="put /inference-pipelines/{inferencePipelineId}">client.InferencePipelines.<a href="https://pkg.go.dev/github.com/openlayer-ai/openlayer-go#InferencePipelineService.Update">Update</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, inferencePipelineID <a href="https://pkg.go.dev/builtin#string">string</a>, body <a href="https://pkg.go.dev/github.com/openlayer-ai/openlayer-go">openlayer</a>.<a href="https://pkg.go.dev/github.com/openlayer-ai/openlayer-go#InferencePipelineUpdateParams">InferencePipelineUpdateParams</a>) (\*<a href="https://pkg.go.dev/github.com/openlayer-ai/openlayer-go">openlayer</a>.<a href="https://pkg.go.dev/github.com/openlayer-ai/openlayer-go#InferencePipelineUpdateResponse">InferencePipelineUpdateResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
117118
- <code title="delete /inference-pipelines/{inferencePipelineId}">client.InferencePipelines.<a href="https://pkg.go.dev/github.com/openlayer-ai/openlayer-go#InferencePipelineService.Delete">Delete</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, inferencePipelineID <a href="https://pkg.go.dev/builtin#string">string</a>) <a href="https://pkg.go.dev/builtin#error">error</a></code>
119+
- <code title="get /inference-pipelines/{inferencePipelineId}/users">client.InferencePipelines.<a href="https://pkg.go.dev/github.com/openlayer-ai/openlayer-go#InferencePipelineService.GetUsers">GetUsers</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, inferencePipelineID <a href="https://pkg.go.dev/builtin#string">string</a>, query <a href="https://pkg.go.dev/github.com/openlayer-ai/openlayer-go">openlayer</a>.<a href="https://pkg.go.dev/github.com/openlayer-ai/openlayer-go#InferencePipelineGetUsersParams">InferencePipelineGetUsersParams</a>) (\*<a href="https://pkg.go.dev/github.com/openlayer-ai/openlayer-go">openlayer</a>.<a href="https://pkg.go.dev/github.com/openlayer-ai/openlayer-go#InferencePipelineGetUsersResponse">InferencePipelineGetUsersResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
118120

119121
## Data
120122

inferencepipeline.go

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,22 @@ func (r *InferencePipelineService) Delete(ctx context.Context, inferencePipeline
8282
return
8383
}
8484

85+
// Get aggregated user data for an inference pipeline with pagination and metadata.
86+
//
87+
// Returns a list of users who have interacted with the inference pipeline,
88+
// including their activity statistics such as session counts, record counts, token
89+
// usage, and costs.
90+
func (r *InferencePipelineService) GetUsers(ctx context.Context, inferencePipelineID string, query InferencePipelineGetUsersParams, opts ...option.RequestOption) (res *InferencePipelineGetUsersResponse, err error) {
91+
opts = slices.Concat(r.Options, opts)
92+
if inferencePipelineID == "" {
93+
err = errors.New("missing required inferencePipelineId parameter")
94+
return
95+
}
96+
path := fmt.Sprintf("inference-pipelines/%s/users", inferencePipelineID)
97+
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...)
98+
return
99+
}
100+
85101
type InferencePipelineGetResponse struct {
86102
// The inference pipeline id.
87103
ID string `json:"id,required" format:"uuid"`
@@ -2075,6 +2091,68 @@ func (r inferencePipelineUpdateResponseWorkspaceMonthlyUsageJSON) RawJSON() stri
20752091
return r.raw
20762092
}
20772093

2094+
type InferencePipelineGetUsersResponse struct {
2095+
// Array of user aggregation data
2096+
Items []InferencePipelineGetUsersResponseItem `json:"items,required"`
2097+
JSON inferencePipelineGetUsersResponseJSON `json:"-"`
2098+
}
2099+
2100+
// inferencePipelineGetUsersResponseJSON contains the JSON metadata for the struct
2101+
// [InferencePipelineGetUsersResponse]
2102+
type inferencePipelineGetUsersResponseJSON struct {
2103+
Items apijson.Field
2104+
raw string
2105+
ExtraFields map[string]apijson.Field
2106+
}
2107+
2108+
func (r *InferencePipelineGetUsersResponse) UnmarshalJSON(data []byte) (err error) {
2109+
return apijson.UnmarshalRoot(data, r)
2110+
}
2111+
2112+
func (r inferencePipelineGetUsersResponseJSON) RawJSON() string {
2113+
return r.raw
2114+
}
2115+
2116+
type InferencePipelineGetUsersResponseItem struct {
2117+
// The unique user identifier
2118+
ID string `json:"id,required"`
2119+
// Total cost for this user
2120+
Cost float64 `json:"cost,required"`
2121+
// Timestamp of the user's first event/trace
2122+
DateOfFirstRecord time.Time `json:"dateOfFirstRecord,required" format:"date-time"`
2123+
// Timestamp of the user's last event/trace
2124+
DateOfLastRecord time.Time `json:"dateOfLastRecord,required" format:"date-time"`
2125+
// Total number of traces/rows for this user
2126+
Records int64 `json:"records,required"`
2127+
// Count of unique sessions for this user
2128+
Sessions int64 `json:"sessions,required"`
2129+
// Total token count for this user
2130+
Tokens float64 `json:"tokens,required"`
2131+
JSON inferencePipelineGetUsersResponseItemJSON `json:"-"`
2132+
}
2133+
2134+
// inferencePipelineGetUsersResponseItemJSON contains the JSON metadata for the
2135+
// struct [InferencePipelineGetUsersResponseItem]
2136+
type inferencePipelineGetUsersResponseItemJSON struct {
2137+
ID apijson.Field
2138+
Cost apijson.Field
2139+
DateOfFirstRecord apijson.Field
2140+
DateOfLastRecord apijson.Field
2141+
Records apijson.Field
2142+
Sessions apijson.Field
2143+
Tokens apijson.Field
2144+
raw string
2145+
ExtraFields map[string]apijson.Field
2146+
}
2147+
2148+
func (r *InferencePipelineGetUsersResponseItem) UnmarshalJSON(data []byte) (err error) {
2149+
return apijson.UnmarshalRoot(data, r)
2150+
}
2151+
2152+
func (r inferencePipelineGetUsersResponseItemJSON) RawJSON() string {
2153+
return r.raw
2154+
}
2155+
20782156
type InferencePipelineGetParams struct {
20792157
// Expand specific nested objects.
20802158
Expand param.Field[[]InferencePipelineGetParamsExpand] `query:"expand"`
@@ -2117,3 +2195,19 @@ type InferencePipelineUpdateParams struct {
21172195
func (r InferencePipelineUpdateParams) MarshalJSON() (data []byte, err error) {
21182196
return apijson.MarshalRoot(r)
21192197
}
2198+
2199+
type InferencePipelineGetUsersParams struct {
2200+
// The page to return in a paginated query.
2201+
Page param.Field[int64] `query:"page"`
2202+
// Maximum number of items to return per page.
2203+
PerPage param.Field[int64] `query:"perPage"`
2204+
}
2205+
2206+
// URLQuery serializes [InferencePipelineGetUsersParams]'s query parameters as
2207+
// `url.Values`.
2208+
func (r InferencePipelineGetUsersParams) URLQuery() (v url.Values) {
2209+
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
2210+
ArrayFormat: apiquery.ArrayQueryFormatComma,
2211+
NestedFormat: apiquery.NestedQueryFormatBrackets,
2212+
})
2213+
}

inferencepipeline_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,32 @@ func TestInferencePipelineDelete(t *testing.T) {
9292
t.Fatalf("err should be nil: %s", err.Error())
9393
}
9494
}
95+
96+
func TestInferencePipelineGetUsersWithOptionalParams(t *testing.T) {
97+
baseURL := "http://localhost:4010"
98+
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
99+
baseURL = envURL
100+
}
101+
if !testutil.CheckTestServer(t, baseURL) {
102+
return
103+
}
104+
client := openlayer.NewClient(
105+
option.WithBaseURL(baseURL),
106+
option.WithAPIKey("My API Key"),
107+
)
108+
_, err := client.InferencePipelines.GetUsers(
109+
context.TODO(),
110+
"182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
111+
openlayer.InferencePipelineGetUsersParams{
112+
Page: openlayer.F(int64(1)),
113+
PerPage: openlayer.F(int64(1)),
114+
},
115+
)
116+
if err != nil {
117+
var apierr *openlayer.Error
118+
if errors.As(err, &apierr) {
119+
t.Log(string(apierr.DumpRequest(true)))
120+
}
121+
t.Fatalf("err should be nil: %s", err.Error())
122+
}
123+
}

0 commit comments

Comments
 (0)