Skip to content

Commit 39c6aa8

Browse files
committed
more chnages
1 parent a3908e8 commit 39c6aa8

5 files changed

Lines changed: 19 additions & 129 deletions

File tree

api/functions/functions.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -114,22 +114,6 @@ func (a *API) InvokeGlobal(ctx context.Context, req InvokeGlobalParams) (any, er
114114
return a.invokePath(ctx, "/function/invoke", req)
115115
}
116116

117-
// Delete deletes a function by ID.
118-
func (a *API) Delete(ctx context.Context, functionID string) error {
119-
if functionID == "" {
120-
return fmt.Errorf("function ID is required")
121-
}
122-
123-
path := fmt.Sprintf("/v1/function/%s", functionID)
124-
resp, err := a.client.DELETE(ctx, path)
125-
if err != nil {
126-
return err
127-
}
128-
defer func() { _ = resp.Body.Close() }()
129-
130-
return nil
131-
}
132-
133117
func (a *API) invokePath(ctx context.Context, path string, req any) (any, error) {
134118
resp, err := a.client.POST(ctx, path, req)
135119
if err != nil {
@@ -160,3 +144,19 @@ func decodeInvokeResponse(body []byte) (any, error) {
160144
}
161145
return output, nil
162146
}
147+
148+
// Delete deletes a function by ID.
149+
func (a *API) Delete(ctx context.Context, functionID string) error {
150+
if functionID == "" {
151+
return fmt.Errorf("function ID is required")
152+
}
153+
154+
path := fmt.Sprintf("/v1/function/%s", functionID)
155+
resp, err := a.client.DELETE(ctx, path)
156+
if err != nil {
157+
return err
158+
}
159+
defer func() { _ = resp.Body.Close() }()
160+
161+
return nil
162+
}

eval/eval.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -480,11 +480,10 @@ func (e *eval[I, R]) runCase(ctx context.Context, span oteltrace.Span, c Case[I,
480480
}
481481

482482
func rootSpanIDFromSpan(span oteltrace.Span) string {
483-
sc := span.SpanContext()
484-
if sc.TraceID().IsValid() {
485-
return sc.TraceID().String()
483+
if span == nil {
484+
return ""
486485
}
487-
return sc.SpanID().String()
486+
return span.SpanContext().TraceID().String()
488487
}
489488

490489
// runTask executes the task function and creates a task span.

eval/eval_test.go

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,17 @@ package eval
22

33
import (
44
"context"
5-
"encoding/json"
65
"errors"
76
"io"
8-
"net/http"
9-
"net/http/httptest"
107
"testing"
118

129
"github.com/stretchr/testify/assert"
1310
"github.com/stretchr/testify/require"
1411
"go.opentelemetry.io/otel/attribute"
1512
"go.opentelemetry.io/otel/codes"
1613

17-
"github.com/braintrustdata/braintrust-sdk-go/api"
18-
"github.com/braintrustdata/braintrust-sdk-go/internal/auth"
1914
"github.com/braintrustdata/braintrust-sdk-go/internal/oteltest"
2015
"github.com/braintrustdata/braintrust-sdk-go/internal/tests"
21-
"github.com/braintrustdata/braintrust-sdk-go/logger"
2216
"github.com/braintrustdata/braintrust-sdk-go/trace"
2317
)
2418

@@ -264,77 +258,6 @@ func TestNewEval_DefaultParallelism(t *testing.T) {
264258
assert.Equal(t, 1, ute2.eval.goroutines)
265259
}
266260

267-
func TestEval_Run_TraceRefUsesRootTraceID(t *testing.T) {
268-
t.Parallel()
269-
270-
var gotRootSpanID string
271-
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
272-
require.Equal(t, http.MethodPost, r.Method)
273-
require.Equal(t, "/function/invoke", r.URL.Path)
274-
275-
var body map[string]any
276-
require.NoError(t, json.NewDecoder(r.Body).Decode(&body))
277-
278-
input, ok := body["input"].(map[string]any)
279-
require.True(t, ok)
280-
traceRef, ok := input["trace_ref"].(map[string]any)
281-
require.True(t, ok)
282-
gotRootSpanID, _ = traceRef["root_span_id"].(string)
283-
284-
require.NoError(t, json.NewEncoder(w).Encode([]map[string]any{
285-
{"role": "user", "content": "hello"},
286-
}))
287-
}))
288-
defer server.Close()
289-
290-
tp, _ := oteltest.Setup(t)
291-
tracer := tp.Tracer(t.Name())
292-
session := auth.NewTestSession(
293-
"test-key",
294-
"org-id",
295-
"org-name",
296-
server.URL,
297-
server.URL,
298-
server.URL,
299-
logger.Discard(),
300-
)
301-
302-
cases := NewDataset([]Case[testInput, testOutput]{
303-
{
304-
Input: testInput{Value: "abc"},
305-
Expected: testOutput{Result: "output-abc"},
306-
},
307-
})
308-
task := T(func(ctx context.Context, input testInput) (testOutput, error) {
309-
return testOutput{Result: "output-" + input.Value}, nil
310-
})
311-
scorer := NewScorer("thread", func(ctx context.Context, result TaskResult[testInput, testOutput]) (Scores, error) {
312-
_, _ = result.Thread(ctx)
313-
return S(1), nil
314-
})
315-
316-
apiClient := api.NewClient("test-key", api.WithAPIURL(server.URL))
317-
318-
e := testNewEval(
319-
session,
320-
tracer,
321-
apiClient,
322-
"exp-123",
323-
"test-exp",
324-
"proj-123",
325-
"test-proj",
326-
cases,
327-
task,
328-
[]Scorer[testInput, testOutput]{scorer},
329-
1,
330-
)
331-
332-
_, err := e.run(context.Background())
333-
require.NoError(t, err)
334-
require.NotEmpty(t, gotRootSpanID)
335-
assert.Regexp(t, "^[0-9a-f]{32}$", gotRootSpanID, "root_span_id should use trace/root ID format")
336-
}
337-
338261
func TestEval_Run_TaskError(t *testing.T) {
339262
t.Parallel()
340263

internal/auth/auth_test.go

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -353,25 +353,6 @@ func TestSession_APIInfo(t *testing.T) {
353353
})
354354
}
355355

356-
func TestSession_API(t *testing.T) {
357-
t.Parallel()
358-
359-
session := NewTestSession(
360-
"test-key-123",
361-
"org-id",
362-
"org-name",
363-
"https://api.braintrust.dev",
364-
"https://www.braintrust.dev",
365-
"https://www.braintrust.dev",
366-
logger.Discard(),
367-
)
368-
369-
apiClient := session.API()
370-
require.NotNil(t, apiClient)
371-
require.NotNil(t, apiClient.Functions())
372-
require.NotNil(t, apiClient.Objects())
373-
}
374-
375356
// TestSession_OrgName tests that OrgName() returns org name after login
376357
func TestSession_OrgName(t *testing.T) {
377358
t.Parallel()

internal/auth/session.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"fmt"
66
"sync"
77

8-
"github.com/braintrustdata/braintrust-sdk-go/api"
98
"github.com/braintrustdata/braintrust-sdk-go/internal/https"
109
"github.com/braintrustdata/braintrust-sdk-go/logger"
1110
)
@@ -126,18 +125,6 @@ func (s *Session) APIInfo() APIInfo {
126125
}
127126
}
128127

129-
// API returns an API client configured from the current session.
130-
// It uses APIInfo() so it works before login completes and automatically
131-
// picks up server-provided APIURL once available.
132-
func (s *Session) API() *api.API {
133-
apiInfo := s.APIInfo()
134-
return api.NewClient(
135-
apiInfo.APIKey,
136-
api.WithAPIURL(apiInfo.APIURL),
137-
api.WithLogger(s.logger),
138-
)
139-
}
140-
141128
func (s *Session) getLoginResult() (bool, *loginResult) {
142129
s.mu.RLock()
143130
defer s.mu.RUnlock()

0 commit comments

Comments
 (0)