Skip to content

Commit 15dfa47

Browse files
fix: use slices.Concat instead of sometimes modifying r.Options
1 parent 67c0b00 commit 15dfa47

37 files changed

+154
-117
lines changed

agent.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"fmt"
1010
"net/http"
1111
"net/url"
12+
"slices"
1213
"time"
1314

1415
"github.com/llamastack/llama-stack-client-go/internal/apijson"
@@ -47,15 +48,15 @@ func NewAgentService(opts ...option.RequestOption) (r AgentService) {
4748

4849
// Create an agent with the given configuration.
4950
func (r *AgentService) New(ctx context.Context, body AgentNewParams, opts ...option.RequestOption) (res *AgentNewResponse, err error) {
50-
opts = append(r.Options[:], opts...)
51+
opts = slices.Concat(r.Options, opts)
5152
path := "v1/agents"
5253
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
5354
return
5455
}
5556

5657
// Describe an agent by its ID.
5758
func (r *AgentService) Get(ctx context.Context, agentID string, opts ...option.RequestOption) (res *AgentGetResponse, err error) {
58-
opts = append(r.Options[:], opts...)
59+
opts = slices.Concat(r.Options, opts)
5960
if agentID == "" {
6061
err = errors.New("missing required agent_id parameter")
6162
return
@@ -67,15 +68,15 @@ func (r *AgentService) Get(ctx context.Context, agentID string, opts ...option.R
6768

6869
// List all agents.
6970
func (r *AgentService) List(ctx context.Context, query AgentListParams, opts ...option.RequestOption) (res *AgentListResponse, err error) {
70-
opts = append(r.Options[:], opts...)
71+
opts = slices.Concat(r.Options, opts)
7172
path := "v1/agents"
7273
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...)
7374
return
7475
}
7576

7677
// Delete an agent by its ID and its associated sessions and turns.
7778
func (r *AgentService) Delete(ctx context.Context, agentID string, opts ...option.RequestOption) (err error) {
78-
opts = append(r.Options[:], opts...)
79+
opts = slices.Concat(r.Options, opts)
7980
opts = append([]option.RequestOption{option.WithHeader("Accept", "")}, opts...)
8081
if agentID == "" {
8182
err = errors.New("missing required agent_id parameter")

agentsession.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"fmt"
1010
"net/http"
1111
"net/url"
12+
"slices"
1213
"time"
1314

1415
"github.com/llamastack/llama-stack-client-go/internal/apijson"
@@ -40,7 +41,7 @@ func NewAgentSessionService(opts ...option.RequestOption) (r AgentSessionService
4041

4142
// Create a new session for an agent.
4243
func (r *AgentSessionService) New(ctx context.Context, agentID string, body AgentSessionNewParams, opts ...option.RequestOption) (res *AgentSessionNewResponse, err error) {
43-
opts = append(r.Options[:], opts...)
44+
opts = slices.Concat(r.Options, opts)
4445
if agentID == "" {
4546
err = errors.New("missing required agent_id parameter")
4647
return
@@ -52,7 +53,7 @@ func (r *AgentSessionService) New(ctx context.Context, agentID string, body Agen
5253

5354
// Retrieve an agent session by its ID.
5455
func (r *AgentSessionService) Get(ctx context.Context, sessionID string, params AgentSessionGetParams, opts ...option.RequestOption) (res *Session, err error) {
55-
opts = append(r.Options[:], opts...)
56+
opts = slices.Concat(r.Options, opts)
5657
if params.AgentID == "" {
5758
err = errors.New("missing required agent_id parameter")
5859
return
@@ -68,7 +69,7 @@ func (r *AgentSessionService) Get(ctx context.Context, sessionID string, params
6869

6970
// List all session(s) of a given agent.
7071
func (r *AgentSessionService) List(ctx context.Context, agentID string, query AgentSessionListParams, opts ...option.RequestOption) (res *AgentSessionListResponse, err error) {
71-
opts = append(r.Options[:], opts...)
72+
opts = slices.Concat(r.Options, opts)
7273
if agentID == "" {
7374
err = errors.New("missing required agent_id parameter")
7475
return
@@ -80,7 +81,7 @@ func (r *AgentSessionService) List(ctx context.Context, agentID string, query Ag
8081

8182
// Delete an agent session by its ID and its associated turns.
8283
func (r *AgentSessionService) Delete(ctx context.Context, sessionID string, body AgentSessionDeleteParams, opts ...option.RequestOption) (err error) {
83-
opts = append(r.Options[:], opts...)
84+
opts = slices.Concat(r.Options, opts)
8485
opts = append([]option.RequestOption{option.WithHeader("Accept", "")}, opts...)
8586
if body.AgentID == "" {
8687
err = errors.New("missing required agent_id parameter")

agentstep.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"errors"
99
"fmt"
1010
"net/http"
11+
"slices"
1112
"time"
1213

1314
"github.com/llamastack/llama-stack-client-go/internal/apijson"
@@ -37,7 +38,7 @@ func NewAgentStepService(opts ...option.RequestOption) (r AgentStepService) {
3738

3839
// Retrieve an agent step by its ID.
3940
func (r *AgentStepService) Get(ctx context.Context, stepID string, query AgentStepGetParams, opts ...option.RequestOption) (res *AgentStepGetResponse, err error) {
40-
opts = append(r.Options[:], opts...)
41+
opts = slices.Concat(r.Options, opts)
4142
if query.AgentID == "" {
4243
err = errors.New("missing required agent_id parameter")
4344
return

agentturn.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"errors"
99
"fmt"
1010
"net/http"
11+
"slices"
1112
"time"
1213

1314
"github.com/llamastack/llama-stack-client-go/internal/apijson"
@@ -40,7 +41,7 @@ func NewAgentTurnService(opts ...option.RequestOption) (r AgentTurnService) {
4041

4142
// Create a new turn for an agent.
4243
func (r *AgentTurnService) New(ctx context.Context, sessionID string, params AgentTurnNewParams, opts ...option.RequestOption) (res *Turn, err error) {
43-
opts = append(r.Options[:], opts...)
44+
opts = slices.Concat(r.Options, opts)
4445
if params.AgentID == "" {
4546
err = errors.New("missing required agent_id parameter")
4647
return
@@ -60,7 +61,7 @@ func (r *AgentTurnService) NewStreaming(ctx context.Context, sessionID string, p
6061
raw *http.Response
6162
err error
6263
)
63-
opts = append(r.Options[:], opts...)
64+
opts = slices.Concat(r.Options, opts)
6465
opts = append([]option.RequestOption{option.WithJSONSet("stream", true)}, opts...)
6566
if params.AgentID == "" {
6667
err = errors.New("missing required agent_id parameter")
@@ -77,7 +78,7 @@ func (r *AgentTurnService) NewStreaming(ctx context.Context, sessionID string, p
7778

7879
// Retrieve an agent turn by its ID.
7980
func (r *AgentTurnService) Get(ctx context.Context, turnID string, query AgentTurnGetParams, opts ...option.RequestOption) (res *Turn, err error) {
80-
opts = append(r.Options[:], opts...)
81+
opts = slices.Concat(r.Options, opts)
8182
if query.AgentID == "" {
8283
err = errors.New("missing required agent_id parameter")
8384
return
@@ -100,7 +101,7 @@ func (r *AgentTurnService) Get(ctx context.Context, turnID string, query AgentTu
100101
// endpoint can be used to submit the outputs from the tool calls once they are
101102
// ready.
102103
func (r *AgentTurnService) Resume(ctx context.Context, turnID string, params AgentTurnResumeParams, opts ...option.RequestOption) (res *Turn, err error) {
103-
opts = append(r.Options[:], opts...)
104+
opts = slices.Concat(r.Options, opts)
104105
if params.AgentID == "" {
105106
err = errors.New("missing required agent_id parameter")
106107
return
@@ -127,7 +128,7 @@ func (r *AgentTurnService) ResumeStreaming(ctx context.Context, turnID string, p
127128
raw *http.Response
128129
err error
129130
)
130-
opts = append(r.Options[:], opts...)
131+
opts = slices.Concat(r.Options, opts)
131132
opts = append([]option.RequestOption{option.WithJSONSet("stream", true)}, opts...)
132133
if params.AgentID == "" {
133134
err = errors.New("missing required agent_id parameter")

benchmark.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"errors"
99
"fmt"
1010
"net/http"
11+
"slices"
1112

1213
"github.com/llamastack/llama-stack-client-go/internal/apijson"
1314
"github.com/llamastack/llama-stack-client-go/internal/requestconfig"
@@ -38,7 +39,7 @@ func NewBenchmarkService(opts ...option.RequestOption) (r BenchmarkService) {
3839

3940
// Get a benchmark by its ID.
4041
func (r *BenchmarkService) Get(ctx context.Context, benchmarkID string, opts ...option.RequestOption) (res *Benchmark, err error) {
41-
opts = append(r.Options[:], opts...)
42+
opts = slices.Concat(r.Options, opts)
4243
if benchmarkID == "" {
4344
err = errors.New("missing required benchmark_id parameter")
4445
return
@@ -51,7 +52,7 @@ func (r *BenchmarkService) Get(ctx context.Context, benchmarkID string, opts ...
5152
// List all benchmarks.
5253
func (r *BenchmarkService) List(ctx context.Context, opts ...option.RequestOption) (res *[]Benchmark, err error) {
5354
var env ListBenchmarksResponse
54-
opts = append(r.Options[:], opts...)
55+
opts = slices.Concat(r.Options, opts)
5556
path := "v1/eval/benchmarks"
5657
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &env, opts...)
5758
if err != nil {
@@ -63,7 +64,7 @@ func (r *BenchmarkService) List(ctx context.Context, opts ...option.RequestOptio
6364

6465
// Register a benchmark.
6566
func (r *BenchmarkService) Register(ctx context.Context, body BenchmarkRegisterParams, opts ...option.RequestOption) (err error) {
66-
opts = append(r.Options[:], opts...)
67+
opts = slices.Concat(r.Options, opts)
6768
opts = append([]option.RequestOption{option.WithHeader("Accept", "")}, opts...)
6869
path := "v1/eval/benchmarks"
6970
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, nil, opts...)

chatcompletion.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"fmt"
1010
"net/http"
1111
"net/url"
12+
"slices"
1213

1314
"github.com/llamastack/llama-stack-client-go/internal/apijson"
1415
"github.com/llamastack/llama-stack-client-go/internal/apiquery"
@@ -43,7 +44,7 @@ func NewChatCompletionService(opts ...option.RequestOption) (r ChatCompletionSer
4344
// Generate an OpenAI-compatible chat completion for the given messages using the
4445
// specified model.
4546
func (r *ChatCompletionService) New(ctx context.Context, body ChatCompletionNewParams, opts ...option.RequestOption) (res *ChatCompletionNewResponseUnion, err error) {
46-
opts = append(r.Options[:], opts...)
47+
opts = slices.Concat(r.Options, opts)
4748
path := "v1/openai/v1/chat/completions"
4849
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
4950
return
@@ -56,7 +57,7 @@ func (r *ChatCompletionService) NewStreaming(ctx context.Context, body ChatCompl
5657
raw *http.Response
5758
err error
5859
)
59-
opts = append(r.Options[:], opts...)
60+
opts = slices.Concat(r.Options, opts)
6061
opts = append([]option.RequestOption{option.WithJSONSet("stream", true)}, opts...)
6162
path := "v1/openai/v1/chat/completions"
6263
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &raw, opts...)
@@ -65,7 +66,7 @@ func (r *ChatCompletionService) NewStreaming(ctx context.Context, body ChatCompl
6566

6667
// Describe a chat completion by its ID.
6768
func (r *ChatCompletionService) Get(ctx context.Context, completionID string, opts ...option.RequestOption) (res *ChatCompletionGetResponse, err error) {
68-
opts = append(r.Options[:], opts...)
69+
opts = slices.Concat(r.Options, opts)
6970
if completionID == "" {
7071
err = errors.New("missing required completion_id parameter")
7172
return
@@ -78,7 +79,7 @@ func (r *ChatCompletionService) Get(ctx context.Context, completionID string, op
7879
// List all chat completions.
7980
func (r *ChatCompletionService) List(ctx context.Context, query ChatCompletionListParams, opts ...option.RequestOption) (res *pagination.OpenAICursorPage[ChatCompletionListResponse], err error) {
8081
var raw *http.Response
81-
opts = append(r.Options[:], opts...)
82+
opts = slices.Concat(r.Options, opts)
8283
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
8384
path := "v1/openai/v1/chat/completions"
8485
cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, query, &res, opts...)

client.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"context"
77
"net/http"
88
"os"
9+
"slices"
910

1011
"github.com/llamastack/llama-stack-client-go/internal/requestconfig"
1112
"github.com/llamastack/llama-stack-client-go/option"
@@ -132,7 +133,7 @@ func NewClient(opts ...option.RequestOption) (r Client) {
132133
// For even greater flexibility, see [option.WithResponseInto] and
133134
// [option.WithResponseBodyInto].
134135
func (r *Client) Execute(ctx context.Context, method string, path string, params any, res any, opts ...option.RequestOption) error {
135-
opts = append(r.Options, opts...)
136+
opts = slices.Concat(r.Options, opts)
136137
return requestconfig.ExecuteNewRequest(ctx, method, path, params, res, opts...)
137138
}
138139

completion.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package llamastackclient
55
import (
66
"context"
77
"net/http"
8+
"slices"
89

910
"github.com/llamastack/llama-stack-client-go/internal/apijson"
1011
"github.com/llamastack/llama-stack-client-go/internal/requestconfig"
@@ -37,7 +38,7 @@ func NewCompletionService(opts ...option.RequestOption) (r CompletionService) {
3738
// Generate an OpenAI-compatible completion for the given prompt using the
3839
// specified model.
3940
func (r *CompletionService) New(ctx context.Context, body CompletionNewParams, opts ...option.RequestOption) (res *CompletionNewResponse, err error) {
40-
opts = append(r.Options[:], opts...)
41+
opts = slices.Concat(r.Options, opts)
4142
path := "v1/openai/v1/completions"
4243
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
4344
return
@@ -50,7 +51,7 @@ func (r *CompletionService) NewStreaming(ctx context.Context, body CompletionNew
5051
raw *http.Response
5152
err error
5253
)
53-
opts = append(r.Options[:], opts...)
54+
opts = slices.Concat(r.Options, opts)
5455
opts = append([]option.RequestOption{option.WithJSONSet("stream", true)}, opts...)
5556
path := "v1/openai/v1/completions"
5657
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &raw, opts...)

dataset.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"fmt"
1010
"net/http"
1111
"net/url"
12+
"slices"
1213

1314
"github.com/llamastack/llama-stack-client-go/internal/apijson"
1415
"github.com/llamastack/llama-stack-client-go/internal/apiquery"
@@ -40,7 +41,7 @@ func NewDatasetService(opts ...option.RequestOption) (r DatasetService) {
4041

4142
// Get a dataset by its ID.
4243
func (r *DatasetService) Get(ctx context.Context, datasetID string, opts ...option.RequestOption) (res *DatasetGetResponse, err error) {
43-
opts = append(r.Options[:], opts...)
44+
opts = slices.Concat(r.Options, opts)
4445
if datasetID == "" {
4546
err = errors.New("missing required dataset_id parameter")
4647
return
@@ -53,7 +54,7 @@ func (r *DatasetService) Get(ctx context.Context, datasetID string, opts ...opti
5354
// List all datasets.
5455
func (r *DatasetService) List(ctx context.Context, opts ...option.RequestOption) (res *[]ListDatasetsResponseData, err error) {
5556
var env ListDatasetsResponse
56-
opts = append(r.Options[:], opts...)
57+
opts = slices.Concat(r.Options, opts)
5758
path := "v1/datasets"
5859
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &env, opts...)
5960
if err != nil {
@@ -65,7 +66,7 @@ func (r *DatasetService) List(ctx context.Context, opts ...option.RequestOption)
6566

6667
// Append rows to a dataset.
6768
func (r *DatasetService) Appendrows(ctx context.Context, datasetID string, body DatasetAppendrowsParams, opts ...option.RequestOption) (err error) {
68-
opts = append(r.Options[:], opts...)
69+
opts = slices.Concat(r.Options, opts)
6970
opts = append([]option.RequestOption{option.WithHeader("Accept", "")}, opts...)
7071
if datasetID == "" {
7172
err = errors.New("missing required dataset_id parameter")
@@ -86,7 +87,7 @@ func (r *DatasetService) Appendrows(ctx context.Context, datasetID string, body
8687
// - data: List of items for the current page.
8788
// - has_more: Whether there are more items available after this set.
8889
func (r *DatasetService) Iterrows(ctx context.Context, datasetID string, query DatasetIterrowsParams, opts ...option.RequestOption) (res *DatasetIterrowsResponse, err error) {
89-
opts = append(r.Options[:], opts...)
90+
opts = slices.Concat(r.Options, opts)
9091
if datasetID == "" {
9192
err = errors.New("missing required dataset_id parameter")
9293
return
@@ -98,15 +99,15 @@ func (r *DatasetService) Iterrows(ctx context.Context, datasetID string, query D
9899

99100
// Register a new dataset.
100101
func (r *DatasetService) Register(ctx context.Context, body DatasetRegisterParams, opts ...option.RequestOption) (res *DatasetRegisterResponse, err error) {
101-
opts = append(r.Options[:], opts...)
102+
opts = slices.Concat(r.Options, opts)
102103
path := "v1/datasets"
103104
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
104105
return
105106
}
106107

107108
// Unregister a dataset by its ID.
108109
func (r *DatasetService) Unregister(ctx context.Context, datasetID string, opts ...option.RequestOption) (err error) {
109-
opts = append(r.Options[:], opts...)
110+
opts = slices.Concat(r.Options, opts)
110111
opts = append([]option.RequestOption{option.WithHeader("Accept", "")}, opts...)
111112
if datasetID == "" {
112113
err = errors.New("missing required dataset_id parameter")

embedding.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"context"
77
"encoding/json"
88
"net/http"
9+
"slices"
910

1011
"github.com/llamastack/llama-stack-client-go/internal/apijson"
1112
"github.com/llamastack/llama-stack-client-go/internal/requestconfig"
@@ -37,7 +38,7 @@ func NewEmbeddingService(opts ...option.RequestOption) (r EmbeddingService) {
3738
// Generate OpenAI-compatible embeddings for the given input using the specified
3839
// model.
3940
func (r *EmbeddingService) New(ctx context.Context, body EmbeddingNewParams, opts ...option.RequestOption) (res *CreateEmbeddingsResponse, err error) {
40-
opts = append(r.Options[:], opts...)
41+
opts = slices.Concat(r.Options, opts)
4142
path := "v1/openai/v1/embeddings"
4243
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
4344
return

0 commit comments

Comments
 (0)