Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

224 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gradient Labs Go

Go Reference

Go bindings for the Gradient Labs API.

Requirements

  • Go 1.20 or later

Installation

go get github.com/gradientlabs-ai/gradientlabs-go

Documentation

Example Usage

Starting a Conversation

package main

import (
    "context"
    "fmt"
    "log"
    "os"
    "time"

    glabs "github.com/gradientlabs-ai/gradientlabs-go"
)

func main() {
    // Create a new client with your API key
    client, err := glabs.NewClient(
        glabs.WithAPIKey(os.Getenv("GLABS_API_KEY")),
    )
    if err != nil {
        log.Fatal(err)
    }

    ctx := context.Background()

    // Start a new conversation
    conv, err := client.StartConversation(ctx, glabs.StartConversationParams{
        ID:         "conversation-1234",
        CustomerID: "user-1234",
        Channel:    glabs.ChannelWeb,
        Resources: map[string]any{
            "user_profile": map[string]any{
                "name":         "Jane Doe",
                "subscription": "premium",
            },
        },
    })
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("Started conversation: %s\n", conv.ID)

    // Add a message to the conversation
    msg, err := client.AddMessage(ctx, conv.ID, glabs.AddMessageParams{
        ID:              "message-1234",
        Body:            "Hello! I need some help.",
        ParticipantID:   "user-1234",
        ParticipantType: glabs.ParticipantTypeCustomer,
        Created:         time.Now(),
    })
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("Added message: %s\n", msg.ID)

    // Assign the conversation to an AI agent
    err = client.AssignConversation(ctx, conv.ID, &glabs.AssignmentParams{
        AssigneeType: glabs.ParticipantTypeAIAgent,
    })
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println("Conversation assigned to AI agent")
}

For more examples, see the examples directory.

About

Go bindings for the Gradient Labs API 🤖

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages