diff --git a/README.md b/README.md index e85411e..e2b1f76 100644 --- a/README.md +++ b/README.md @@ -58,31 +58,19 @@ import ( ) func main() { - ctx := context.Background() l := langfuse.New() - err := l.Trace( - ctx, - &model.Trace{ - Name: "test-trace", - }, - ) + err := l.Trace(&model.Trace{Name: "test-trace"}) if err != nil { panic(err) } - err = l.Span( - ctx, - &model.Span{ - Name: "test-span", - }, - ) + err = l.Span(&model.Span{Name: "test-span"}) if err != nil { panic(err) } err = l.Generation( - ctx, &model.Generation{ Name: "test-generation", Model: "gpt-3.5-turbo", @@ -110,7 +98,6 @@ func main() { } err = l.Event( - ctx, &model.Event{ Name: "test-event", Metadata: model.M{ @@ -129,7 +116,6 @@ func main() { } err = l.GenerationEnd( - ctx, &model.Generation{ Output: model.M{ "completion": "The Q3 OKRs contain goals for multiple teams...", @@ -141,7 +127,6 @@ func main() { } err = l.Score( - ctx, &model.Score{ Name: "test-score", Value: 0.9, @@ -151,10 +136,7 @@ func main() { panic(err) } - err = l.SpanEnd( - ctx, - &model.Span{}, - ) + err = l.SpanEnd(&model.Span{}) if err != nil { panic(err) } diff --git a/examples/cmd/ingestion/main.go b/examples/cmd/ingestion/main.go index b01867f..134244b 100644 --- a/examples/cmd/ingestion/main.go +++ b/examples/cmd/ingestion/main.go @@ -8,31 +8,19 @@ import ( ) func main() { - ctx := context.Background() l := langfuse.New() - err := l.Trace( - ctx, - &model.Trace{ - Name: "test-trace", - }, - ) + err := l.Trace(&model.Trace{Name: "test-trace"}) if err != nil { panic(err) } - err = l.Span( - ctx, - &model.Span{ - Name: "test-span", - }, - ) + err = l.Span(&model.Span{Name: "test-span"}) if err != nil { panic(err) } err = l.Generation( - ctx, &model.Generation{ Name: "test-generation", Model: "gpt-3.5-turbo", @@ -60,7 +48,6 @@ func main() { } err = l.Event( - ctx, &model.Event{ Name: "test-event", Metadata: model.M{ @@ -79,7 +66,6 @@ func main() { } err = l.GenerationEnd( - ctx, &model.Generation{ Output: model.M{ "completion": "The Q3 OKRs contain goals for multiple teams...", @@ -91,7 +77,6 @@ func main() { } err = l.Score( - ctx, &model.Score{ Name: "test-score", Value: 0.9, @@ -101,10 +86,7 @@ func main() { panic(err) } - err = l.SpanEnd( - ctx, - &model.Span{}, - ) + err = l.SpanEnd(&model.Span{}) if err != nil { panic(err) } diff --git a/langfuse.go b/langfuse.go index 9bbde79..13e62ef 100644 --- a/langfuse.go +++ b/langfuse.go @@ -57,7 +57,7 @@ func ingest(client *api.Client, events []model.IngestionEvent) error { return client.Ingestion(context.Background(), &req, &res) } -func (l *Langfuse) Trace(ctx context.Context, t *model.Trace) error { +func (l *Langfuse) Trace(t *model.Trace) error { event := model.IngestionEvent{ ID: uuid.New().String(), Type: model.IngestionEventTypeTraceCreate, @@ -77,7 +77,7 @@ func (l *Langfuse) Trace(ctx context.Context, t *model.Trace) error { } //nolint:dupl -func (l *Langfuse) Generation(ctx context.Context, g *model.Generation) error { +func (l *Langfuse) Generation(g *model.Generation) error { event := model.IngestionEvent{ ID: uuid.New().String(), Type: model.IngestionEventTypeGenerationCreate, @@ -88,7 +88,7 @@ func (l *Langfuse) Generation(ctx context.Context, g *model.Generation) error { g.ID = traceID } - traceID, err := l.extractTraceID(ctx, g.Name) + traceID, err := l.extractTraceID(g.Name) if err != nil { return err } @@ -108,7 +108,7 @@ func (l *Langfuse) Generation(ctx context.Context, g *model.Generation) error { } //nolint:dupl -func (l *Langfuse) GenerationEnd(ctx context.Context, g *model.Generation) error { +func (l *Langfuse) GenerationEnd(g *model.Generation) error { generation, err := l.path.PopIf(path.Generation) if err != nil { return fmt.Errorf("invalid path: %w", err) @@ -138,7 +138,7 @@ func (l *Langfuse) GenerationEnd(ctx context.Context, g *model.Generation) error return nil } -func (l *Langfuse) Score(ctx context.Context, s *model.Score) error { +func (l *Langfuse) Score(s *model.Score) error { event := model.IngestionEvent{ ID: uuid.New().String(), Type: model.IngestionEventTypeScoreCreate, @@ -149,7 +149,7 @@ func (l *Langfuse) Score(ctx context.Context, s *model.Score) error { s.ID = traceID } - traceID, err := l.extractTraceID(ctx, s.Name) + traceID, err := l.extractTraceID(s.Name) if err != nil { return err } @@ -162,7 +162,7 @@ func (l *Langfuse) Score(ctx context.Context, s *model.Score) error { } //nolint:dupl -func (l *Langfuse) Span(ctx context.Context, s *model.Span) error { +func (l *Langfuse) Span(s *model.Span) error { event := model.IngestionEvent{ ID: uuid.New().String(), Type: model.IngestionEventTypeSpanCreate, @@ -173,7 +173,7 @@ func (l *Langfuse) Span(ctx context.Context, s *model.Span) error { s.ID = traceID } - traceID, err := l.extractTraceID(ctx, s.Name) + traceID, err := l.extractTraceID(s.Name) if err != nil { return err } @@ -193,7 +193,7 @@ func (l *Langfuse) Span(ctx context.Context, s *model.Span) error { } //nolint:dupl -func (l *Langfuse) SpanEnd(ctx context.Context, s *model.Span) error { +func (l *Langfuse) SpanEnd(s *model.Span) error { span, err := l.path.PopIf(path.Span) if err != nil { return fmt.Errorf("invalid path: %w", err) @@ -223,7 +223,7 @@ func (l *Langfuse) SpanEnd(ctx context.Context, s *model.Span) error { return nil } -func (l *Langfuse) Event(ctx context.Context, e *model.Event) error { +func (l *Langfuse) Event(e *model.Event) error { event := model.IngestionEvent{ ID: uuid.New().String(), Type: model.IngestionEventTypeEventCreate, @@ -234,7 +234,7 @@ func (l *Langfuse) Event(ctx context.Context, e *model.Event) error { e.ID = traceID } - traceID, err := l.extractTraceID(ctx, e.Name) + traceID, err := l.extractTraceID(e.Name) if err != nil { return err } @@ -250,14 +250,13 @@ func (l *Langfuse) Event(ctx context.Context, e *model.Event) error { return nil } -func (l *Langfuse) extractTraceID(ctx context.Context, traceName string) (string, error) { +func (l *Langfuse) extractTraceID(traceName string) (string, error) { tracePath := l.path.At(0) if tracePath != nil { return tracePath.ID, nil } errTrace := l.Trace( - ctx, &model.Trace{ Name: traceName, },