Documentation
¶
Index ¶
- type CreateOption
- type Dataset
- func (d *Dataset) Append(records ...Record)
- func (d *Dataset) Delete(index int)
- func (d *Dataset) ID() string
- func (d *Dataset) Len() int
- func (d *Dataset) Name() string
- func (d *Dataset) Push(ctx context.Context) error
- func (d *Dataset) Record(idx int) (Record, bool)
- func (d *Dataset) Records() iter.Seq2[int, Record]
- func (d *Dataset) URL() string
- func (d *Dataset) Update(index int, update RecordUpdate)
- func (d *Dataset) Version() int
- type PullOption
- type Record
- type RecordUpdate
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CreateOption ¶
type CreateOption func(cfg *createConfig)
func WithCSVDelimiter ¶
func WithCSVDelimiter(delimiter rune) CreateOption
func WithCSVExpectedOutputColumns ¶
func WithCSVExpectedOutputColumns(cols []string) CreateOption
func WithCSVMetadataColumns ¶
func WithCSVMetadataColumns(cols []string) CreateOption
func WithDescription ¶
func WithDescription(description string) CreateOption
func WithProjectName ¶
func WithProjectName(projectName string) CreateOption
WithProjectName sets the project name for the dataset. This overrides the global project name configured via DD_LLM_OBS_ML_APP or tracer.WithLLMObsProjectName().
type Dataset ¶
type Dataset struct {
// contains filtered or unexported fields
}
Dataset represents a dataset for DataDog LLM Observability experiments.
func Create ¶
func Create(ctx context.Context, name string, records []Record, opts ...CreateOption) (*Dataset, error)
Create initializes a Dataset and pushes it to DataDog.
Example ¶
package main
import (
"context"
"log"
"github.com/DataDog/dd-trace-go/v2/ddtrace/tracer"
"github.com/DataDog/dd-trace-go/v2/llmobs/dataset"
)
func main() {
if err := tracer.Start(tracer.WithLLMObsEnabled(true)); err != nil {
log.Fatal(err)
}
defer tracer.Stop()
ctx := context.Background()
// First, create the dataset
ds, err := dataset.Create(
ctx,
"capitals-of-the-world",
[]dataset.Record{
{
Input: map[string]any{
"question": "What is the capital of China?",
},
ExpectedOutput: "Beijing",
Metadata: map[string]any{
"difficulty": "easy",
},
},
{
Input: map[string]any{
"question": "Which city serves as the capital of South Africa?",
},
ExpectedOutput: "Pretoria",
Metadata: map[string]any{
"difficulty": "medium",
},
},
},
dataset.WithDescription("Questions about world capitals"),
)
if err != nil {
log.Fatal(err)
}
// Finally, push the dataset to DataDog
if err := ds.Push(ctx); err != nil {
log.Fatal(err)
}
}
func CreateFromCSV ¶
func CreateFromCSV(ctx context.Context, name, csvPath string, inputCols []string, opts ...CreateOption) (*Dataset, error)
CreateFromCSV creates a new dataset from a CSV file.
Notes:
- CSV files must have a header row
- Maximum field size is 10MB
- All columns not specified in input_data_columns or expected_output_columns are automatically treated as metadata
- The dataset is automatically pushed to Datadog after creation
func (*Dataset) Append ¶
Append adds new records to the Dataset.
Example ¶
package main
import (
"context"
"log"
"github.com/DataDog/dd-trace-go/v2/ddtrace/tracer"
"github.com/DataDog/dd-trace-go/v2/llmobs/dataset"
)
func main() {
if err := tracer.Start(tracer.WithLLMObsEnabled(true)); err != nil {
log.Fatal(err)
}
defer tracer.Stop()
ctx := context.Background()
// First, create the dataset
ds, err := dataset.Create(
ctx,
"capitals-of-the-world",
[]dataset.Record{
{
Input: map[string]any{
"question": "What is the capital of China?",
},
ExpectedOutput: "Beijing",
Metadata: map[string]any{
"difficulty": "easy",
},
},
{
Input: map[string]any{
"question": "Which city serves as the capital of South Africa?",
},
ExpectedOutput: "Pretoria",
Metadata: map[string]any{
"difficulty": "medium",
},
},
},
dataset.WithDescription("Questions about world capitals"),
)
if err != nil {
log.Fatal(err)
}
// Add a new question
ds.Append(dataset.Record{
Input: map[string]any{
"question": "What is the capital of China?",
},
ExpectedOutput: "Beijing",
Metadata: map[string]any{
"difficulty": "easy",
},
})
// Finally, push the dataset to DataDog
if err := ds.Push(ctx); err != nil {
log.Fatal(err)
}
}
func (*Dataset) Push ¶
Push pushes the Dataset changes to DataDog. For large changes (>5MB), it uses bulk upload via CSV. For smaller changes, it uses batch update API.
func (*Dataset) Records ¶
Records returns an iterator with copies of the records in the Dataset. To modify the records, use the Append, Update or Delete methods.
Warning: Do not call any of the methods that modify the records while in the loop, or you will cause a deadlock.
func (*Dataset) Update ¶
func (d *Dataset) Update(index int, update RecordUpdate)
Update updates the item at the given index.
Example ¶
package main
import (
"context"
"log"
"github.com/DataDog/dd-trace-go/v2/ddtrace/tracer"
"github.com/DataDog/dd-trace-go/v2/llmobs/dataset"
)
func main() {
if err := tracer.Start(tracer.WithLLMObsEnabled(true)); err != nil {
log.Fatal(err)
}
defer tracer.Stop()
ctx := context.Background()
// First, create the dataset
ds, err := dataset.Create(
ctx,
"capitals-of-the-world",
[]dataset.Record{
{
Input: map[string]any{
"question": "What is the capital of China?",
},
ExpectedOutput: "Beijing",
Metadata: map[string]any{
"difficulty": "easy",
},
},
{
Input: map[string]any{
"question": "Which city serves as the capital of South Africa?",
},
ExpectedOutput: "Pretoria",
Metadata: map[string]any{
"difficulty": "medium",
},
},
},
dataset.WithDescription("Questions about world capitals"),
)
if err != nil {
log.Fatal(err)
}
// Update the difficulty of the first question
ds.Update(0, dataset.RecordUpdate{
Input: nil, // leave unchanged
ExpectedOutput: nil, // leave unchanged
Metadata: map[string]any{"difficulty": "medium"},
})
// Finally, push the dataset to DataDog
if err := ds.Push(ctx); err != nil {
log.Fatal(err)
}
}
type PullOption ¶
type PullOption func(cfg *pullConfig)
func WithPullProjectName ¶
func WithPullProjectName(projectName string) PullOption
WithPullProjectName sets the project name for pulling the dataset. This overrides the global project name configured via DD_LLM_OBS_ML_APP or tracer.WithLLMObsProjectName().
type Record ¶
type Record struct {
Input any
ExpectedOutput any
Metadata any
// contains filtered or unexported fields
}
Record represents a record in a Dataset.
type RecordUpdate ¶
RecordUpdate is used to represent partial record updates. Use nil to signal no modifications to a given field. Use empty values to signal deletion (e.g. empty strings or empty maps).