Skip to content

Commit 165acf5

Browse files
committed
feat: add documentation and new examples
1 parent b4fefc1 commit 165acf5

3 files changed

Lines changed: 141 additions & 5 deletions

File tree

client_test.go

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"log"
7+
"os"
78
"testing"
89
"time"
910

@@ -13,6 +14,8 @@ import (
1314
)
1415

1516
func TestMain(m *testing.M) {
17+
os.Setenv("LANGSMITH_API_KEY", "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")
18+
os.Setenv("LANGSMITH_PROJECT_NAME", "langsmithgo")
1619
m.Run()
1720

1821
}
@@ -308,4 +311,137 @@ func TestRun(t *testing.T) {
308311
}
309312

310313
})
314+
t.Run("use with metadata", func(t *testing.T) {
315+
runId := uuid.New().String()
316+
client, err := NewClient()
317+
if err != nil {
318+
t.Errorf("Error creating client: %v", err)
319+
}
320+
321+
err = client.Run(&RunPayload{
322+
RunID: runId,
323+
Name: "langsmithgo-metadata",
324+
SessionName: "langsmithgo",
325+
RunType: LLM,
326+
Tags: []string{"metadata"},
327+
Inputs: map[string]interface{}{
328+
"prompt": "Sample prompt for metadata test",
329+
},
330+
Extras: map[string]interface{}{
331+
"metadata_key": "metadata_value",
332+
},
333+
})
334+
335+
if err != nil {
336+
t.Errorf("Error running: %v", err)
337+
}
338+
339+
err = client.Run(&RunPayload{
340+
RunID: runId,
341+
Outputs: map[string]interface{}{
342+
"output": "metadata test",
343+
},
344+
})
345+
346+
if err != nil {
347+
t.Errorf("Error running: %v", err)
348+
}
349+
350+
fmt.Println("Metadata test completed successfully")
351+
})
352+
353+
t.Run("use with tools", func(t *testing.T) {
354+
runId := uuid.New().String()
355+
client, err := NewClient()
356+
if err != nil {
357+
t.Errorf("Error creating client: %v", err)
358+
}
359+
360+
err = client.Run(&RunPayload{
361+
RunID: runId,
362+
Name: "langsmithgo-tools",
363+
SessionName: "langsmithgo",
364+
RunType: Tool,
365+
Tags: []string{"tool"},
366+
Inputs: map[string]interface{}{
367+
"tool_input_key": "tool_input_value",
368+
"tool": map[string]interface{}{
369+
"name": "Sample Tool",
370+
"description": "A sample tool used within the run",
371+
"parameters": map[string]interface{}{
372+
"param1": "value1",
373+
"param2": "value2",
374+
},
375+
},
376+
},
377+
Extras: map[string]interface{}{
378+
"OS": "Linux",
379+
},
380+
})
381+
382+
if err != nil {
383+
t.Errorf("Error running: %v", err)
384+
}
385+
386+
err = client.Run(&RunPayload{
387+
RunID: runId,
388+
Outputs: map[string]interface{}{
389+
"output": "tools test",
390+
},
391+
})
392+
393+
if err != nil {
394+
t.Errorf("Error running: %v", err)
395+
}
396+
397+
fmt.Println("Tools test completed successfully")
398+
})
399+
400+
t.Run("use with events", func(t *testing.T) {
401+
runId := uuid.New().String()
402+
client, err := NewClient()
403+
if err != nil {
404+
t.Errorf("Error creating client: %v", err)
405+
}
406+
407+
err = client.Run(&RunPayload{
408+
RunID: runId,
409+
Name: "langsmithgo-events",
410+
SessionName: "langsmithgo",
411+
RunType: LLM,
412+
Tags: []string{"events"},
413+
Inputs: map[string]interface{}{
414+
"prompt": "Sample prompt for events test",
415+
},
416+
Events: []Event{
417+
{
418+
EventName: "Event 1",
419+
Reason: "Initial test event",
420+
Value: "event_value 1",
421+
},
422+
{
423+
EventName: "Event 2",
424+
Reason: "Follow-up test event",
425+
Value: "event_value 2",
426+
},
427+
},
428+
})
429+
430+
if err != nil {
431+
t.Errorf("Error running: %v", err)
432+
}
433+
434+
err = client.Run(&RunPayload{
435+
RunID: runId,
436+
Outputs: map[string]interface{}{
437+
"output": "events test",
438+
},
439+
})
440+
441+
if err != nil {
442+
t.Errorf("Error running: %v", err)
443+
}
444+
445+
fmt.Println("Events test completed successfully")
446+
})
311447
}

contracts.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
)
77

88
const (
9-
BASE_URL = "https://api.smith.langchain.com"
9+
BASE_URL = "https://api.smith.langchain.com/api/v1"
1010
)
1111

1212
type Response struct {
@@ -29,7 +29,7 @@ type RunPayload struct {
2929
Tags []string `json:"tags"`
3030
Outputs map[string]interface{} `json:"outputs"`
3131
EndTime time.Time `json:"end_time"`
32-
Extras map[string]interface{} `json:"extras"`
32+
Extras map[string]interface{} `json:"extra"`
3333
Events []Event `json:"events"`
3434
}
3535

@@ -48,7 +48,7 @@ type SimplePayload struct {
4848
SessionName string `json:"session_name"`
4949
Tags []string `json:"tags,omitempty"`
5050
ParentId string `json:"parent_run_id,omitempty"`
51-
Extras map[string]interface{} `json:"extras,omitempty"`
51+
Extras map[string]interface{} `json:"extra,omitempty"`
5252
Events []Event `json:"events,omitempty"`
5353
Outputs map[string]interface{} `json:"outputs"`
5454
EndTime time.Time `json:"end_time"`
@@ -63,7 +63,7 @@ type PostPayload struct {
6363
SessionName string `json:"session_name"`
6464
Tags []string `json:"tags,omitempty"`
6565
ParentId string `json:"parent_run_id,omitempty"`
66-
Extras map[string]interface{} `json:"extras,omitempty"`
66+
Extras map[string]interface{} `json:"extra,omitempty"`
6767
Events []Event `json:"events,omitempty"`
6868
}
6969

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/devalexandre/langsmithgo
22

3-
go 1.20
3+
go 1.22.0
44

55
require (
66
github.com/google/uuid v1.6.0

0 commit comments

Comments
 (0)