### Create, Get, and List Datasets with Go Source: https://github.com/git-hulk/langfuse-go/blob/master/README.md Demonstrates how to create, retrieve, and list datasets using the Langfuse Go SDK. Ensure you have initialized the Langfuse client with your host and keys. ```go import ( "context" langfuse "github.com/git-hulk/langfuse-go" "github.com/git-hulk/langfuse-go/pkg/datasets" ) func main() { langfuse := langfuse.NewClient("YOUR_HOST", "YOUR_PUBLIC_KEY", "YOUR_PRIVATE_KEY") ctx := context.Background() // Create a new dataset createdDataset, err := langfuse.Datasets().Create(ctx, &datasets.CreateDatasetRequest{ Name: "evaluation-dataset", Description: "Dataset for model evaluation", Metadata: map[string]interface{}{"version": "1.0"}, }) // Get a dataset by name dataset, err := langfuse.Datasets().Get(ctx, "evaluation-dataset") // List datasets listDatasets, err := langfuse.Datasets().List(ctx, datasets.ListParams{ Page: 1, Limit: 20, }) } ``` -------------------------------- ### Run Integration Tests Source: https://github.com/git-hulk/langfuse-go/blob/master/CLAUDE.md Executes integration tests. Requires environment setup. ```bash go run integration/integration.go ``` -------------------------------- ### Create, Get, List, and Compile Prompts Source: https://github.com/git-hulk/langfuse-go/blob/master/README.md Demonstrates creating, retrieving, listing, and compiling prompts using the Langfuse Go SDK. Supports both text and chat message formats with placeholders. ```go import ( "context" langfuse "github.com/git-hulk/langfuse-go" "github.com/git-hulk/langfuse-go/pkg/prompts" ) func main() { langfuse := langfuse.NewClient("YOUR_HOST", "YOUR_PUBLIC_KEY", "YOUR_PRIVATE_KEY") ctx := context.Background() createdPrompt, err := langfuse.Prompts().Create(ctx, prompts.PromptEntry{ Name: "welcome-message", Prompt: []prompts.ChatMessageWithPlaceHolder { {Role: "system", Content: "You are a helpful assistant."}, {Role: "user", Content: "Hello!"}, } }) prompt, err := langfuse.Prompts().Get(ctx, prompts.GetParams{Name: "welcome-message"}) listResponse, err := langfuse.Prompts().List(ctx, prompts.ListParams{Limit: 20}) // Compile a text prompt textPrompt, err := langfuse.Prompts().Get(ctx, prompts.GetParams{ Name: "welcome-message-text", Label: "latest", Version: 1, }) compiledText, err := textPrompt.Compile(map[string]any{ "name": "Alice", }) renderedText := compiledText.(string) // Compile a chat prompt with placeholders compiledChat, err := prompt.Compile(map[string]any{ "user": "Bob", "examples": []prompts.ChatMessageWithPlaceHolder{ {Role: "user", Content: "Hello {{ user }}"}, }, }) chatMessages := compiledChat.([]prompts.ChatMessageWithPlaceHolder) } ``` -------------------------------- ### Create, Get, List, and Delete Models Source: https://github.com/git-hulk/langfuse-go/blob/master/README.md Shows how to create, retrieve, list, and delete model configurations using the Langfuse Go SDK. Useful for registering and managing AI models. ```go import ( "context" langfuse "github.com/git-hulk/langfuse-go" "github.com/git-hulk/langfuse-go/pkg/models" ) func main() { langfuse := langfuse.NewClient("YOUR_HOST", "YOUR_PUBLIC_KEY", "YOUR_PRIVATE_KEY") ctx := context.Background() // Create a new model createdModel, err := langfuse.Models().Create(ctx, &models.ModelEntry{ ModelName: "gpt-4", MatchPattern: "gpt-4*", InputPrice: 0.03, OutputPrice: 0.06, Unit: "TOKENS", }) // Get a model by ID model, err := langfuse.Models().Get(ctx, "model-id") // List models listModels, err := langfuse.Models().List(ctx, models.ListParams{ Page: 1, Limit: 20, }) // Delete a model err = langfuse.Models().Delete(ctx, "model-id") } ``` -------------------------------- ### Start and End Traces and Spans Source: https://github.com/git-hulk/langfuse-go/blob/master/README.md Initiates a new trace and span, then ends them. Ensure to close the client to flush pending traces. ```go import ( "context" langfuse "github.com/git-hulk/langfuse-go" ) func main() { langfuse := langfuse.NewClient("YOUR_HOST", "YOUR_PUBLIC_KEY", "YOUR_PRIVATE_KEY") ctx := context.Background() trace := langfuse.StartTrace(ctx, "it's a trace") span := trace.StartSpan("it's a span") span.End() trace.End() langfuse.Close() // flushes all pending traces } ``` -------------------------------- ### Create, Get, List, and Delete Scores Source: https://github.com/git-hulk/langfuse-go/blob/master/README.md Illustrates creating, retrieving, listing, and deleting evaluation scores for traces with filtering options. Supports numeric and other data types. ```go import ( "context" langfuse "github.com/git-hulk/langfuse-go" "github.com/git-hulk/langfuse-go/pkg/scores" ) func main() { langfuse := langfuse.NewClient("YOUR_HOST", "YOUR_PUBLIC_KEY", "YOUR_PRIVATE_KEY") ctx := context.Background() // Create a score for a trace createdScore, err := langfuse.Scores().Create(ctx, &scores.CreateScoreRequest{ TraceID: "trace-123", Name: "accuracy", Value: 0.95, DataType: scores.ScoreDataTypeNumeric, Comment: "High accuracy score", }) // Get a score by ID score, err := langfuse.Scores().Get(ctx, "score-id") // List scores with filters scoresList, err := langfuse.Scores().List(ctx, scores.ListParams{ Page: 1, Limit: 20, Name: "accuracy", Source: scores.ScoreSourceAPI, }) // Delete a score err = langfuse.Scores().Delete(ctx, "score-id") } ``` -------------------------------- ### Create, Get, and List Comments Source: https://github.com/git-hulk/langfuse-go/blob/master/README.md Handles the creation of new comments on traces, retrieval of a specific comment by ID, and listing comments with filtering capabilities. ```go import ( "context" langfuse "github.com/git-hulk/langfuse-go" "github.com/git-hulk/langfuse-go/pkg/comments" ) func main() { langfuse := langfuse.NewClient("YOUR_HOST", "YOUR_PUBLIC_KEY", "YOUR_PRIVATE_KEY") ctx := context.Background() // Create a comment on a trace createdComment, err := langfuse.Comments().Create(ctx, &comments.CreateCommentRequest{ ObjectType: comments.ObjectTypeTrace, ObjectID: "trace-123", Content: "This trace looks good!", }) // Get a comment by ID comment, err := langfuse.Comments().Get(ctx, "comment-id") // List comments with filters commentsList, err := langfuse.Comments().List(ctx, comments.ListParams{ ObjectType: comments.ObjectTypeTrace, ObjectID: "trace-123", Page: 1, Limit: 10, }) } ``` -------------------------------- ### Get and List Sessions Source: https://github.com/git-hulk/langfuse-go/blob/master/README.md Retrieves a specific session by ID or lists sessions with various filtering options like timestamps and environment. ```go import ( "context" "time" langfuse "github.com/git-hulk/langfuse-go" "github.com/git-hulk/langfuse-go/pkg/sessions" ) func main() { langfuse := langfuse.NewClient("YOUR_HOST", "YOUR_PUBLIC_KEY", "YOUR_PRIVATE_KEY") ctx := context.Background() // Get a session by ID with its traces session, err := langfuse.Sessions().Get(ctx, "session-123") // List sessions with filters sessionsList, err := langfuse.Sessions().List(ctx, sessions.ListParams{ Page: 1, Limit: 10, FromTimestamp: time.Now().Add(-24 * time.Hour), ToTimestamp: time.Now(), Environment: []string{"production"}, }) } ``` -------------------------------- ### Upload Media Files with Go Source: https://github.com/git-hulk/langfuse-go/blob/master/README.md Shows how to upload media files using the Langfuse Go SDK, either from a file path or byte data. You can also retrieve media records and get presigned upload URLs. ```go import ( "context" "os" langfuse "github.com/git-hulk/langfuse-go" "github.com/git-hulk/langfuse-go/pkg/media" ) func main() { langfuse := langfuse.NewClient("YOUR_HOST", "YOUR_PUBLIC_KEY", "YOUR_PRIVATE_KEY") ctx := context.Background() // Upload a file from filesystem uploadResp, err := langfuse.Media().UploadFile(ctx, &media.UploadFileRequest{ TraceID: "trace-123", Field: "input", FilePath: "./image.png", ContentType: media.ContentTypeImagePNG, // Optional, auto-detected if not provided }) // Upload from byte data imageData, _ := os.ReadFile("./image.jpg") uploadResp, err = langfuse.Media().UploadFromBytes(ctx, &media.UploadFromBytesRequest{ TraceID: "trace-123", Field: "output", ContentType: media.ContentTypeImageJPEG, Data: imageData, }) // Get media record mediaRecord, err := langfuse.Media().Get(ctx, uploadResp.MediaID) // Get presigned upload URL for custom upload flow uploadURL, err := langfuse.Media().GetUploadURL(ctx, &media.GetUploadURLRequest{ TraceID: "trace-123", ContentType: media.ContentTypeImagePNG, ContentLength: len(imageData), SHA256Hash: "base64-encoded-sha256-hash", Field: "metadata", }) } ``` -------------------------------- ### Initialize Resty Client and Feature Client Source: https://github.com/git-hulk/langfuse-go/blob/master/CLAUDE.md Demonstrates setting up the main Resty HTTP client with base URL and authentication, then initializing a feature client using the configured HTTP client. ```go // Main client sets base URL and auth once restyCli := resty.New(). SetBaseURL(host+"/api/public"). SetBasicAuth(publicKey, secretKey) // Feature clients reuse the configured HTTP client client := features.NewClient(restyCli) ``` -------------------------------- ### Build Project Source: https://github.com/git-hulk/langfuse-go/blob/master/README.md Compile all packages within the project. ```bash go build ./... # Build all packages ``` -------------------------------- ### Manage Langfuse Projects and API Keys Source: https://github.com/git-hulk/langfuse-go/blob/master/README.md This snippet demonstrates various project management operations including retrieving projects, creating, updating, and deleting projects. It also shows how to manage API keys for a specific project. Requires organization-scoped API keys for creation, update, and deletion operations. ```go import ( "context" langfuse "github.com/git-hulk/langfuse-go" "github.com/git-hulk/langfuse-go/pkg/projects" ) func main() { langfuse := langfuse.NewClient("YOUR_HOST", "YOUR_PUBLIC_KEY", "YOUR_PRIVATE_KEY") ctx := context.Background() // Get projects associated with your API key projects, err := langfuse.Projects().Get(ctx) // Create a new project (requires organization-scoped API key) createdProject, err := langfuse.Projects().Create(ctx, &projects.CreateProjectRequest{ Name: "my-new-project", Metadata: map[string]interface{}{ "team": "ai" }, Retention: 30, }) // Update a project (requires organization-scoped API key) updatedProject, err := langfuse.Projects().Update(ctx, "project-id", &projects.UpdateProjectRequest{ Name: "updated-project-name", Retention: 60, }) // Delete a project (requires organization-scoped API key) deleteResponse, err := langfuse.Projects().Delete(ctx, "project-id") // Manage API keys for a project (requires organization-scoped API key) apiKeys, err := langfuse.Projects().GetAPIKeys(ctx, "project-id") newAPIKey, err := langfuse.Projects().CreateAPIKey(ctx, "project-id", &projects.CreateAPIKeyRequest{ Note: &[]string{"API key for production"}[0], }) deleteAPIResponse, err := langfuse.Projects().DeleteAPIKey(ctx, "project-id", "api-key-id") } ``` -------------------------------- ### Build All Go Packages Source: https://github.com/git-hulk/langfuse-go/blob/master/CLAUDE.md Compiles all packages within the project. ```bash go build ./... ``` -------------------------------- ### List and Upsert LLM Connections Source: https://github.com/git-hulk/langfuse-go/blob/master/README.md Demonstrates listing existing LLM connections and creating or updating new ones. Supports specifying provider, adapter, keys, custom models, and headers. ```go import ( "context" langfuse "github.com/git-hulk/langfuse-go" "github.com/git-hulk/langfuse-go/pkg/llmconnections" ) func main() { langfuse := langfuse.NewClient("YOUR_HOST", "YOUR_PUBLIC_KEY", "YOUR_PRIVATE_KEY") ctx := context.Background() // List LLM connections connections, err := langfuse.LLMConnections().List(ctx, llmconnections.ListParams{ Page: 1, Limit: 10, }) // Create or update an LLM connection connection, err := langfuse.LLMConnections().Upsert(ctx, &llmconnections.UpsertLLMConnectionRequest{ Provider: "OpenAI", Adapter: llmconnections.AdapterOpenAI, SecretKey: "sk-your-openai-key", CustomModels: []string{"gpt-4", "gpt-3.5-turbo"}, WithDefaultModels: &[]bool{true}[0], ExtraHeaders: map[string]string{"Custom-Header": "value"}, }) } ``` -------------------------------- ### Run Standard Go Tests Source: https://github.com/git-hulk/langfuse-go/blob/master/CLAUDE.md Uses the standard Go test runner to execute tests across all packages. ```bash go test ./... ``` -------------------------------- ### Lint Code Source: https://github.com/git-hulk/langfuse-go/blob/master/README.md Run static analysis on the code using golangci-lint to identify potential issues. ```bash golangci-lint run # Lint (CI uses v1.64.7) ``` -------------------------------- ### Run All Tests Source: https://github.com/git-hulk/langfuse-go/blob/master/README.md Execute all tests in the project, including the race detector and running each test only once. ```bash make test # Run all tests with race detector (-race -count=1) ``` -------------------------------- ### Format Code with Goimports and Gofmt Source: https://github.com/git-hulk/langfuse-go/blob/master/CLAUDE.md Formats the code using goimports and gofmt, including local import ordering. ```bash make format ``` -------------------------------- ### Check API Health with Go Source: https://github.com/git-hulk/langfuse-go/blob/master/README.md Demonstrates how to check the health and version of the Langfuse API using the Go SDK. This is useful for monitoring the platform's status. ```go import ( "context" "fmt" langfuse "github.com/git-hulk/langfuse-go" ) func main() { langfuse := langfuse.NewClient("YOUR_HOST", "YOUR_PUBLIC_KEY", "YOUR_PRIVATE_KEY") ctx := context.Background() // Check API health and version health, err := langfuse.Health().Check(ctx) if err != nil { fmt.Printf("Health check failed: %v\n", err) return } fmt.Printf("Status: %s, Version: %s\n", health.Status, health.Version) } ``` -------------------------------- ### Test Specific Go Package Source: https://github.com/git-hulk/langfuse-go/blob/master/CLAUDE.md Runs tests only for the specified package. ```bash go test ./pkg/annotations/ ``` -------------------------------- ### Lint Code with Golangci-lint Source: https://github.com/git-hulk/langfuse-go/blob/master/CLAUDE.md Runs the linter to check for code quality and potential issues. The CI environment uses v1.64.7. ```bash golangci-lint run ``` -------------------------------- ### Query Metrics for Traces Source: https://github.com/git-hulk/langfuse-go/blob/master/README.md Fetches trace metrics, such as count, with specified dimensions and ordering. Includes decoding response data and handling potential errors. ```go import ( "context" "encoding/json" "fmt" "time" langfuse "github.com/git-hulk/langfuse-go" "github.com/git-hulk/langfuse-go/pkg/metrics" ) func main() { langfuse := langfuse.NewClient("YOUR_HOST", "YOUR_PUBLIC_KEY", "YOUR_PRIVATE_KEY") ctx := context.Background() metricsResponse, err := langfuse.Metrics().Get(ctx, &metrics.Query{ View: metrics.ViewTraces, Metrics: []metrics.Metric{ {Measure: metrics.MeasureCount, Aggregation: "count"}, }, Dimensions: []metrics.Dimension{ {Field: "name"}, }, FromTimestamp: time.Now().Add(-24 * time.Hour), ToTimestamp: time.Now(), OrderBy: []metrics.OrderBy{ {Field: "count_count", Direction: metrics.OrderDirectionDesc}, }, }) if err != nil { panic(err) } type TraceMetricRow struct { Name string `json:"name"` Count string `json:"count_count"` } rows, err := metrics.DecodeRows[TraceMetricRow](metricsResponse.Data) if err != nil { panic(err) } rawName, ok := metricsResponse.Data[0].Raw("name") if !ok { panic("name field not found") } var name string err = json.Unmarshal(rawName, &name) if err != nil { panic(err) } fmt.Println(name, rows[0].Name, rows[0].Count) } ``` -------------------------------- ### Format Code with Goimports Source: https://github.com/git-hulk/langfuse-go/blob/master/CLAUDE.md Applies goimports formatting to all Go files in the project, modifying them in place. ```bash goimports -w -local github.com/git-hulk/langfuse-go ./... ``` -------------------------------- ### Run All Tests with Race Detector Source: https://github.com/git-hulk/langfuse-go/blob/master/CLAUDE.md Executes all tests in the project, including the race detector and running each test only once. ```bash make test ``` -------------------------------- ### Verbose Test Output for Specific Package Source: https://github.com/git-hulk/langfuse-go/blob/master/CLAUDE.md Executes tests for a specific package with verbose output enabled. ```bash go test -v ./pkg/traces/ ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.