44 "context"
55 "fmt"
66 "log"
7+ "os"
78 "testing"
89 "time"
910
@@ -13,6 +14,8 @@ import (
1314)
1415
1516func 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}
0 commit comments