Skip to content

Commit 0b77bbc

Browse files
authored
Merge pull request #4 from devalexandre/feat/add-examples
Feat/add examples
2 parents 881ee0c + 165acf5 commit 0b77bbc

34 files changed

Lines changed: 15761 additions & 5 deletions

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

docs/.gitignore

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Dependencies
2+
/node_modules
3+
4+
# Production
5+
/build
6+
7+
# Generated files
8+
.docusaurus
9+
.cache-loader
10+
11+
# Misc
12+
.DS_Store
13+
.env.local
14+
.env.development.local
15+
.env.test.local
16+
.env.production.local
17+
18+
npm-debug.log*
19+
yarn-debug.log*
20+
yarn-error.log*

docs/README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Website
2+
3+
This website is built using [Docusaurus](https://docusaurus.io/), a modern static website generator.
4+
5+
### Installation
6+
7+
```
8+
$ yarn
9+
```
10+
11+
### Local Development
12+
13+
```
14+
$ yarn start
15+
```
16+
17+
This command starts a local development server and opens up a browser window. Most changes are reflected live without having to restart the server.
18+
19+
### Build
20+
21+
```
22+
$ yarn build
23+
```
24+
25+
This command generates static content into the `build` directory and can be served using any static contents hosting service.
26+
27+
### Deployment
28+
29+
Using SSH:
30+
31+
```
32+
$ USE_SSH=true yarn deploy
33+
```
34+
35+
Not using SSH:
36+
37+
```
38+
$ GIT_USER=<Your GitHub username> yarn deploy
39+
```
40+
41+
If you are using GitHub pages for hosting, this command is a convenient way to build the website and push to the `gh-pages` branch.

docs/babel.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
presets: [require.resolve('@docusaurus/core/lib/babel/preset')],
3+
};
93.9 KB
Loading
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
---
2+
slug: langsmithgo-integrating-llms-and-ai-tools-in-go-applications
3+
title: "LangsmithGo: Integrating LLMs and AI Tools in Go Applications"
4+
authors: [alexandre]
5+
tags: [news]
6+
---
7+
8+
# LangsmithGo: Integrating LLMs and AI Tools in Go Applications
9+
10+
## Introduction
11+
12+
Welcome to the official LangsmithGo project blog! Today, we will explore what LangsmithGo is, its benefits, and how it can be used to integrate language models (LLMs) and artificial intelligence (AI) tools into your Go applications. If you are a Go developer interested in AI, this article is for you.
13+
14+
## What is Langsmith?
15+
16+
Langsmith is a powerful platform designed to facilitate the integration of language models and AI tools into various applications. It offers a robust API that allows developers to create, manage, and monitor runs of language models, as well as support the addition of metadata, tools, and events. With Langsmith, you can leverage the potential of LLMs such as GPT-3 and GPT-3.5-turbo, among others, in your software solutions.
17+
18+
## LangsmithGo: The Go Library for Langsmith
19+
20+
LangsmithGo is the Go library that allows you to interact with the Langsmith API in a simple and efficient manner. It abstracts the complexities of communicating with the API, offering easy-to-use methods for creating and managing runs of LLMs and AI tools. With LangsmithGo, Go developers can quickly integrate advanced natural language processing capabilities into their applications.
21+
22+
## Benefits of LangsmithGo
23+
24+
1. Simple Integration: LangsmithGo offers an easy-to-use interface to integrate LLMs into Go applications.
25+
2. Flexibility: Supports various types of runs, including LLMs, tools, execution chains, and more.
26+
3. Monitoring and Management: Allows adding metadata, tools, and events to runs, facilitating monitoring and management.
27+
4. OpenAI Compatibility: Native support for OpenAI models, such as GPT-3 and GPT-3.5-turbo.
28+
29+
## How to Use LangsmithGo
30+
31+
Let's explore some practical examples of how to use LangsmithGo to create and manage runs of LLMs and AI tools.
32+
33+
### Installation
34+
35+
```sh
36+
go get github.com/tmc/langsmithgo
37+
```
38+
39+
### Configuration
40+
41+
```go
42+
43+
import (
44+
"os"
45+
)
46+
47+
func init() {
48+
os.Setenv("LANGSMITH_API_KEY", "your_api_key_here")
49+
os.Setenv("LANGSMITH_PROJECT_NAME", "your_project_name_here")
50+
}
51+
52+
```
53+
54+
### Creating an LLM Run
55+
56+
Here is an example of how to create an LLM run with LangsmithGo:
57+
58+
```go
59+
60+
package main
61+
62+
import (
63+
"context"
64+
"fmt"
65+
"log"
66+
67+
"github.com/google/uuid"
68+
"github.com/tmc/langchaingo/llms"
69+
"github.com/tmc/langchaingo/llms/openai"
70+
"github.com/tmc/langsmithgo"
71+
)
72+
73+
func main() {
74+
client, err := langsmithgo.NewClient()
75+
if err != nil {
76+
log.Fatalf("Error creating client: %v", err)
77+
}
78+
79+
llm, err := openai.New()
80+
if err != nil {
81+
log.Fatalf("Error creating LLM: %v", err)
82+
}
83+
84+
runId := uuid.New().String()
85+
prompt := "The first man to walk on the moon"
86+
ctx := context.Background()
87+
88+
err = client.Run(&langsmithgo.RunPayload{
89+
RunID: runId,
90+
Name: "example-llm-run",
91+
SessionName: "example-session",
92+
RunType: langsmithgo.LLM,
93+
Inputs: map[string]interface{}{
94+
"prompt": prompt,
95+
},
96+
})
97+
98+
if err != nil {
99+
log.Fatalf("Error running: %v", err)
100+
}
101+
102+
completion, err := llms.GenerateFromSinglePrompt(ctx, llm, prompt)
103+
if err != nil {
104+
log.Fatalf("Error generating completion: %v", err)
105+
}
106+
107+
err = client.Run(&langsmithgo.RunPayload{
108+
RunID: runId,
109+
Outputs: map[string]interface{}{
110+
"output": completion,
111+
},
112+
})
113+
114+
if err != nil {
115+
log.Fatalf("Error running: %v", err)
116+
}
117+
118+
fmt.Println(completion)
119+
}
120+
121+
```
122+
123+
## Conclusion
124+
125+
LangsmithGo is a powerful tool for Go developers who want to integrate language models and AI tools into their applications. With its simple and flexible interface, you can quickly start creating, managing, and monitoring runs of LLMs, enriched with metadata, tools, and events. Try LangsmithGo today and elevate your Go applications to the next level!
126+
127+
Follow our blog for more tutorials, examples, and updates on LangsmithGo. If you have any questions or suggestions, feel free to contact us. Happy coding!

docs/blog/authors.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
alexandre:
2+
name: Alexandre Evangelista de Souza
3+
title: Maintainer of LangSmithGo
4+
url: https://github.com/devalexandre
5+
image_url: https://github.com/devalexandre.png

0 commit comments

Comments
 (0)