Skip to content

Commit

Permalink
Merge pull request #4 from devalexandre/feat/add-examples
Browse files Browse the repository at this point in the history
Feat/add examples
  • Loading branch information
devalexandre authored Jun 20, 2024
2 parents 881ee0c + 165acf5 commit 0b77bbc
Show file tree
Hide file tree
Showing 34 changed files with 15,761 additions and 5 deletions.
136 changes: 136 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"log"
"os"
"testing"
"time"

Expand All @@ -13,6 +14,8 @@ import (
)

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

}
Expand Down Expand Up @@ -308,4 +311,137 @@ func TestRun(t *testing.T) {
}

})
t.Run("use with metadata", func(t *testing.T) {
runId := uuid.New().String()
client, err := NewClient()
if err != nil {
t.Errorf("Error creating client: %v", err)
}

err = client.Run(&RunPayload{
RunID: runId,
Name: "langsmithgo-metadata",
SessionName: "langsmithgo",
RunType: LLM,
Tags: []string{"metadata"},
Inputs: map[string]interface{}{
"prompt": "Sample prompt for metadata test",
},
Extras: map[string]interface{}{
"metadata_key": "metadata_value",
},
})

if err != nil {
t.Errorf("Error running: %v", err)
}

err = client.Run(&RunPayload{
RunID: runId,
Outputs: map[string]interface{}{
"output": "metadata test",
},
})

if err != nil {
t.Errorf("Error running: %v", err)
}

fmt.Println("Metadata test completed successfully")
})

t.Run("use with tools", func(t *testing.T) {
runId := uuid.New().String()
client, err := NewClient()
if err != nil {
t.Errorf("Error creating client: %v", err)
}

err = client.Run(&RunPayload{
RunID: runId,
Name: "langsmithgo-tools",
SessionName: "langsmithgo",
RunType: Tool,
Tags: []string{"tool"},
Inputs: map[string]interface{}{
"tool_input_key": "tool_input_value",
"tool": map[string]interface{}{
"name": "Sample Tool",
"description": "A sample tool used within the run",
"parameters": map[string]interface{}{
"param1": "value1",
"param2": "value2",
},
},
},
Extras: map[string]interface{}{
"OS": "Linux",
},
})

if err != nil {
t.Errorf("Error running: %v", err)
}

err = client.Run(&RunPayload{
RunID: runId,
Outputs: map[string]interface{}{
"output": "tools test",
},
})

if err != nil {
t.Errorf("Error running: %v", err)
}

fmt.Println("Tools test completed successfully")
})

t.Run("use with events", func(t *testing.T) {
runId := uuid.New().String()
client, err := NewClient()
if err != nil {
t.Errorf("Error creating client: %v", err)
}

err = client.Run(&RunPayload{
RunID: runId,
Name: "langsmithgo-events",
SessionName: "langsmithgo",
RunType: LLM,
Tags: []string{"events"},
Inputs: map[string]interface{}{
"prompt": "Sample prompt for events test",
},
Events: []Event{
{
EventName: "Event 1",
Reason: "Initial test event",
Value: "event_value 1",
},
{
EventName: "Event 2",
Reason: "Follow-up test event",
Value: "event_value 2",
},
},
})

if err != nil {
t.Errorf("Error running: %v", err)
}

err = client.Run(&RunPayload{
RunID: runId,
Outputs: map[string]interface{}{
"output": "events test",
},
})

if err != nil {
t.Errorf("Error running: %v", err)
}

fmt.Println("Events test completed successfully")
})
}
8 changes: 4 additions & 4 deletions contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

const (
BASE_URL = "https://api.smith.langchain.com"
BASE_URL = "https://api.smith.langchain.com/api/v1"
)

type Response struct {
Expand All @@ -29,7 +29,7 @@ type RunPayload struct {
Tags []string `json:"tags"`
Outputs map[string]interface{} `json:"outputs"`
EndTime time.Time `json:"end_time"`
Extras map[string]interface{} `json:"extras"`
Extras map[string]interface{} `json:"extra"`
Events []Event `json:"events"`
}

Expand All @@ -48,7 +48,7 @@ type SimplePayload struct {
SessionName string `json:"session_name"`
Tags []string `json:"tags,omitempty"`
ParentId string `json:"parent_run_id,omitempty"`
Extras map[string]interface{} `json:"extras,omitempty"`
Extras map[string]interface{} `json:"extra,omitempty"`
Events []Event `json:"events,omitempty"`
Outputs map[string]interface{} `json:"outputs"`
EndTime time.Time `json:"end_time"`
Expand All @@ -63,7 +63,7 @@ type PostPayload struct {
SessionName string `json:"session_name"`
Tags []string `json:"tags,omitempty"`
ParentId string `json:"parent_run_id,omitempty"`
Extras map[string]interface{} `json:"extras,omitempty"`
Extras map[string]interface{} `json:"extra,omitempty"`
Events []Event `json:"events,omitempty"`
}

Expand Down
20 changes: 20 additions & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Dependencies
/node_modules

# Production
/build

# Generated files
.docusaurus
.cache-loader

# Misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
41 changes: 41 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Website

This website is built using [Docusaurus](https://docusaurus.io/), a modern static website generator.

### Installation

```
$ yarn
```

### Local Development

```
$ yarn start
```

This command starts a local development server and opens up a browser window. Most changes are reflected live without having to restart the server.

### Build

```
$ yarn build
```

This command generates static content into the `build` directory and can be served using any static contents hosting service.

### Deployment

Using SSH:

```
$ USE_SSH=true yarn deploy
```

Not using SSH:

```
$ GIT_USER=<Your GitHub username> yarn deploy
```

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.
3 changes: 3 additions & 0 deletions docs/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
presets: [require.resolve('@docusaurus/core/lib/babel/preset')],
};
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
---
slug: langsmithgo-integrating-llms-and-ai-tools-in-go-applications
title: "LangsmithGo: Integrating LLMs and AI Tools in Go Applications"
authors: [alexandre]
tags: [news]
---

# LangsmithGo: Integrating LLMs and AI Tools in Go Applications

## Introduction

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.

## What is Langsmith?

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.

## LangsmithGo: The Go Library for Langsmith

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.

## Benefits of LangsmithGo

1. Simple Integration: LangsmithGo offers an easy-to-use interface to integrate LLMs into Go applications.
2. Flexibility: Supports various types of runs, including LLMs, tools, execution chains, and more.
3. Monitoring and Management: Allows adding metadata, tools, and events to runs, facilitating monitoring and management.
4. OpenAI Compatibility: Native support for OpenAI models, such as GPT-3 and GPT-3.5-turbo.

## How to Use LangsmithGo

Let's explore some practical examples of how to use LangsmithGo to create and manage runs of LLMs and AI tools.

### Installation

```sh
go get github.com/tmc/langsmithgo
```

### Configuration

```go

import (
"os"
)

func init() {
os.Setenv("LANGSMITH_API_KEY", "your_api_key_here")
os.Setenv("LANGSMITH_PROJECT_NAME", "your_project_name_here")
}

```

### Creating an LLM Run

Here is an example of how to create an LLM run with LangsmithGo:

```go

package main

import (
"context"
"fmt"
"log"

"github.com/google/uuid"
"github.com/tmc/langchaingo/llms"
"github.com/tmc/langchaingo/llms/openai"
"github.com/tmc/langsmithgo"
)

func main() {
client, err := langsmithgo.NewClient()
if err != nil {
log.Fatalf("Error creating client: %v", err)
}

llm, err := openai.New()
if err != nil {
log.Fatalf("Error creating LLM: %v", err)
}

runId := uuid.New().String()
prompt := "The first man to walk on the moon"
ctx := context.Background()

err = client.Run(&langsmithgo.RunPayload{
RunID: runId,
Name: "example-llm-run",
SessionName: "example-session",
RunType: langsmithgo.LLM,
Inputs: map[string]interface{}{
"prompt": prompt,
},
})

if err != nil {
log.Fatalf("Error running: %v", err)
}

completion, err := llms.GenerateFromSinglePrompt(ctx, llm, prompt)
if err != nil {
log.Fatalf("Error generating completion: %v", err)
}

err = client.Run(&langsmithgo.RunPayload{
RunID: runId,
Outputs: map[string]interface{}{
"output": completion,
},
})

if err != nil {
log.Fatalf("Error running: %v", err)
}

fmt.Println(completion)
}

```

## Conclusion

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!

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!
5 changes: 5 additions & 0 deletions docs/blog/authors.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
alexandre:
name: Alexandre Evangelista de Souza
title: Maintainer of LangSmithGo
url: https://github.com/devalexandre
image_url: https://github.com/devalexandre.png
Loading

0 comments on commit 0b77bbc

Please sign in to comment.