Skip to content

Commit

Permalink
fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
henomis committed Mar 26, 2024
1 parent e1fd9d7 commit b22ce84
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 55 deletions.
24 changes: 3 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -110,7 +98,6 @@ func main() {
}

err = l.Event(
ctx,
&model.Event{
Name: "test-event",
Metadata: model.M{
Expand All @@ -129,7 +116,6 @@ func main() {
}

err = l.GenerationEnd(
ctx,
&model.Generation{
Output: model.M{
"completion": "The Q3 OKRs contain goals for multiple teams...",
Expand All @@ -141,7 +127,6 @@ func main() {
}

err = l.Score(
ctx,
&model.Score{
Name: "test-score",
Value: 0.9,
Expand All @@ -151,10 +136,7 @@ func main() {
panic(err)
}

err = l.SpanEnd(
ctx,
&model.Span{},
)
err = l.SpanEnd(&model.Span{})
if err != nil {
panic(err)
}
Expand Down
24 changes: 3 additions & 21 deletions examples/cmd/ingestion/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -60,7 +48,6 @@ func main() {
}

err = l.Event(
ctx,
&model.Event{
Name: "test-event",
Metadata: model.M{
Expand All @@ -79,7 +66,6 @@ func main() {
}

err = l.GenerationEnd(
ctx,
&model.Generation{
Output: model.M{
"completion": "The Q3 OKRs contain goals for multiple teams...",
Expand All @@ -91,7 +77,6 @@ func main() {
}

err = l.Score(
ctx,
&model.Score{
Name: "test-score",
Value: 0.9,
Expand All @@ -101,10 +86,7 @@ func main() {
panic(err)
}

err = l.SpanEnd(
ctx,
&model.Span{},
)
err = l.SpanEnd(&model.Span{})
if err != nil {
panic(err)
}
Expand Down
25 changes: 12 additions & 13 deletions langfuse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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
}
Expand All @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -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
}
Expand All @@ -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,
Expand All @@ -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
}
Expand All @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -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
}
Expand All @@ -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,
},
Expand Down

0 comments on commit b22ce84

Please sign in to comment.