forked from langchain-ai/langsmith-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlangsmith_examples_test.go
73 lines (62 loc) · 1.87 KB
/
langsmith_examples_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package langsmith_test
import (
"context"
"fmt"
"net/http/httputil"
"os"
"github.com/google/uuid"
"github.com/langchain-ai/langsmith-sdk/go/langsmith"
)
func ExampleClient_CreateRunRunsPost() {
client, err := langsmith.NewClientWithResponses(langsmith.DefaultBaseURL, langsmith.WithAPIKey(os.Getenv("LANGCHAIN_API_KEY")))
if err != nil {
panic(err)
}
runType := langsmith.Llm
inputs := map[string]interface{}{
"model": "text-davinci-002",
"prompt": "Hello, world!",
}
body := langsmith.CreateRunRunsPostJSONRequestBody{
Name: "Example Run",
RunType: runType,
Inputs: &langsmith.RunCreateSchemaExtended_Inputs{},
}
body.Inputs.FromRunCreateSchemaExtendedInputs0(inputs)
resp, err := client.CreateRunRunsPost(context.Background(), body)
if err != nil {
panic(err)
}
defer resp.Body.Close()
// print the response using httputil.DumpResponse
rbody, _ := httputil.DumpResponse(resp, true)
fmt.Println(string(rbody))
fmt.Println("Run created successfully")
// output: Run created successfully
}
func ExampleClient_UpdateRunRunsRunIdPatch() {
client, err := langsmith.NewClientWithResponses(langsmith.DefaultBaseURL, langsmith.WithAPIKey(os.Getenv("LANGCHAIN_API_KEY")))
if err != nil {
panic(err)
}
runID, err := uuid.Parse("123e4567-e89b-12d3-a456-426655440000")
if err != nil {
panic(err)
}
outputs := map[string]interface{}{
"text": "The response from the language model.",
}
body := langsmith.UpdateRunRunsRunIdPatchJSONRequestBody{
Outputs: &langsmith.RunUpdateSchemaExtended_Outputs{},
}
body.Outputs.FromRunUpdateSchemaExtendedOutputs0(outputs)
resp, err := client.UpdateRunRunsRunIdPatch(context.Background(), runID, body)
if err != nil {
panic(err)
}
defer resp.Body.Close()
rbody, _ := httputil.DumpResponse(resp, true)
fmt.Println(string(rbody))
fmt.Println("Run updated successfully")
// output: Run updated successfully
}