langfuse

package module
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 1, 2024 License: MIT Imports: 7 Imported by: 7

README

Langfuse Go SDK

GoDoc Go Report Card GitHub release

This is Langfuse's unofficial Go client, designed to enable you to use Langfuse's services easily from your own applications.

Langfuse

Langfuse traces, evals, prompt management and metrics to debug and improve your LLM application.

API support

Index Operations Status
Trace 🟢
Generation 🟢
Span 🟢
Event 🟢
Score 🟢

Getting started

Installation

You can load langfuse-go into your project by using:

go get github.com/henomis/langfuse-go
Configuration

Just like the official Python SDK, these three environment variables will be used to configure the Langfuse client:

  • LANGFUSE_HOST: The host of the Langfuse service.
  • LANGFUSE_PUBLIC_KEY: Your public key for the Langfuse service.
  • LANGFUSE_SECRET_KEY: Your secret key for the Langfuse service.
Usage

Please refer to the examples folder to see how to use the SDK.

Here below a simple usage example:

package main

import (
	"context"

	"github.com/henomis/langfuse-go"
	"github.com/henomis/langfuse-go/model"
)

func main() {
	l := langfuse.New()

	err := l.Trace(&model.Trace{Name: "test-trace"})
	if err != nil {
		panic(err)
	}

	err = l.Span(&model.Span{Name: "test-span"})
	if err != nil {
		panic(err)
	}

	err = l.Generation(
		&model.Generation{
			Name:  "test-generation",
			Model: "gpt-3.5-turbo",
			ModelParameters: model.M{
				"maxTokens":   "1000",
				"temperature": "0.9",
			},
			Input: []model.M{
				{
					"role":    "system",
					"content": "You are a helpful assistant.",
				},
				{
					"role":    "user",
					"content": "Please generate a summary of the following documents \nThe engineering department defined the following OKR goals...\nThe marketing department defined the following OKR goals...",
				},
			},
			Metadata: model.M{
				"key": "value",
			},
		},
	)
	if err != nil {
		panic(err)
	}

	err = l.Event(
		&model.Event{
			Name: "test-event",
			Metadata: model.M{
				"key": "value",
			},
			Input: model.M{
				"key": "value",
			},
			Output: model.M{
				"key": "value",
			},
		},
	)
	if err != nil {
		panic(err)
	}

	err = l.GenerationEnd(
		&model.Generation{
			Output: model.M{
				"completion": "The Q3 OKRs contain goals for multiple teams...",
			},
		},
	)
	if err != nil {
		panic(err)
	}

	err = l.Score(
		&model.Score{
			Name:  "test-score",
			Value: 0.9,
		},
	)
	if err != nil {
		panic(err)
	}

	err = l.SpanEnd(&model.Span{})
	if err != nil {
		panic(err)
	}

	l.Flush(context.Background())

}

Who uses langfuse-go?

  • LinGoose Go framework for building awesome LLM apps

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Langfuse

type Langfuse struct {
	// contains filtered or unexported fields
}

func New

func New(ctx context.Context) *Langfuse

func (*Langfuse) Event

func (l *Langfuse) Event(e *model.Event, parentID *string) (*model.Event, error)

func (*Langfuse) Flush

func (l *Langfuse) Flush(ctx context.Context)

func (*Langfuse) Generation

func (l *Langfuse) Generation(g *model.Generation, parentID *string) (*model.Generation, error)

func (*Langfuse) GenerationEnd

func (l *Langfuse) GenerationEnd(g *model.Generation) (*model.Generation, error)

func (*Langfuse) Score

func (l *Langfuse) Score(s *model.Score) (*model.Score, error)

func (*Langfuse) Span

func (l *Langfuse) Span(s *model.Span, parentID *string) (*model.Span, error)

func (*Langfuse) SpanEnd

func (l *Langfuse) SpanEnd(s *model.Span) (*model.Span, error)

func (*Langfuse) Trace

func (l *Langfuse) Trace(t *model.Trace) (*model.Trace, error)

func (*Langfuse) WithFlushInterval

func (l *Langfuse) WithFlushInterval(d time.Duration) *Langfuse

Directories

Path Synopsis
examples
cmd/ingestion command
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL