rlhf

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package rlhf provides a client for AINative RLHF (Reinforcement Learning from Human Feedback) operations.

The RLHF client enables interaction feedback collection, correction submission, and analytics viewing for improving AI model performance through human feedback.

Features:

  • Interaction feedback submission with scores (0.0-1.0)
  • Correction submission with diff visualization
  • Automatic interaction capture from chat sessions
  • Batch feedback submission
  • Analytics viewing and export

Example usage:

import (
    "context"
    "github.com/AINative-studio/ainative-code/internal/client"
    "github.com/AINative-studio/ainative-code/internal/client/rlhf"
)

// Create HTTP client
apiClient := client.New(
    client.WithBaseURL("https://api.ainative.studio"),
    client.WithServicePath("rlhf", "/v1/rlhf"),
)

// Create RLHF client
rlhfClient := rlhf.New(
    rlhf.WithAPIClient(apiClient),
    rlhf.WithBaseURL("https://api.ainative.studio/v1/rlhf"),
)

// Submit interaction feedback
feedback := &rlhf.InteractionFeedback{
    Prompt: "What is the capital of France?",
    Response: "Paris is the capital of France.",
    Score: 0.95,
    Metadata: map[string]interface{}{
        "model": "claude-3-5-sonnet-20241022",
        "session_id": "session-123",
    },
}
result, err := rlhfClient.SubmitInteractionFeedback(context.Background(), feedback)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Analytics

type Analytics struct {
	// Model ID
	ModelID string `json:"model_id"`

	// Time range
	StartDate time.Time `json:"start_date"`
	EndDate   time.Time `json:"end_date"`

	// Metrics
	AverageFeedbackScore float64 `json:"average_feedback_score"`
	TotalInteractions    int     `json:"total_interactions"`
	TotalCorrections     int     `json:"total_corrections"`
	CorrectionRate       float64 `json:"correction_rate"` // Percentage

	// Distribution
	ScoreDistribution map[string]int `json:"score_distribution"` // Buckets: "0.0-0.2", "0.2-0.4", etc.

	// Top issues
	TopCorrectionReasons []ReasonCount `json:"top_correction_reasons,omitempty"`

	// Trending data
	TrendingData []TrendPoint `json:"trending_data,omitempty"`
}

Analytics represents RLHF analytics data.

type AnalyticsExportRequest

type AnalyticsExportRequest struct {
	Analytics *AnalyticsRequest `json:"analytics"`
	Format    ExportFormat      `json:"format"`
}

AnalyticsExportRequest represents a request to export analytics.

type AnalyticsRequest

type AnalyticsRequest struct {
	// ModelID to filter by (optional)
	ModelID string `json:"model_id,omitempty"`

	// Date range
	StartDate time.Time `json:"start_date"`
	EndDate   time.Time `json:"end_date"`

	// Granularity for trending data: "hour", "day", "week", "month"
	Granularity string `json:"granularity,omitempty"`
}

AnalyticsRequest represents a request for analytics data.

type BatchInteractionFeedback

type BatchInteractionFeedback struct {
	Interactions []*InteractionFeedback `json:"interactions"`
}

BatchInteractionFeedback represents multiple feedback submissions.

type BatchInteractionFeedbackResponse

type BatchInteractionFeedbackResponse struct {
	// Successful submissions
	Successful []string `json:"successful"`

	// Failed submissions with reasons
	Failed map[string]string `json:"failed,omitempty"`

	// TotalProcessed count
	TotalProcessed int `json:"total_processed"`

	// SuccessCount count
	SuccessCount int `json:"success_count"`

	// FailureCount count
	FailureCount int `json:"failure_count"`
}

BatchInteractionFeedbackResponse represents the response for batch submission.

type Change

type Change struct {
	// Type: "add", "remove", "modify"
	Type string `json:"type"`

	// Line number
	Line int `json:"line"`

	// Content of the change
	Content string `json:"content"`
}

Change represents a single change in a diff.

type Client

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

Client represents a client for RLHF operations.

func New

func New(opts ...Option) *Client

New creates a new RLHF client with the specified options.

func (*Client) ExportAnalytics

func (c *Client) ExportAnalytics(ctx context.Context, req *AnalyticsExportRequest) ([]byte, error)

ExportAnalytics exports analytics data in the specified format.

func (*Client) GetAnalytics

func (c *Client) GetAnalytics(ctx context.Context, req *AnalyticsRequest) (*Analytics, error)

GetAnalytics retrieves RLHF analytics for the specified parameters.

func (*Client) GetCorrection

func (c *Client) GetCorrection(ctx context.Context, correctionID string) (*CorrectionResponse, error)

GetCorrection retrieves a specific correction by ID.

func (*Client) GetInteraction

func (c *Client) GetInteraction(ctx context.Context, interactionID string) (*InteractionFeedback, error)

GetInteraction retrieves a specific interaction by ID.

func (*Client) ListInteractions

func (c *Client) ListInteractions(ctx context.Context, modelID, sessionID string, limit, offset int) ([]*InteractionFeedback, error)

ListInteractions lists interactions with optional filtering.

func (*Client) SubmitBatchInteractionFeedback

func (c *Client) SubmitBatchInteractionFeedback(ctx context.Context, batch *BatchInteractionFeedback) (*BatchInteractionFeedbackResponse, error)

SubmitBatchInteractionFeedback submits feedback for multiple interactions.

func (*Client) SubmitCorrection

func (c *Client) SubmitCorrection(ctx context.Context, correction *Correction) (*CorrectionResponse, error)

SubmitCorrection submits a correction for an AI response.

func (*Client) SubmitInteractionFeedback

func (c *Client) SubmitInteractionFeedback(ctx context.Context, feedback *InteractionFeedback) (*InteractionFeedbackResponse, error)

SubmitInteractionFeedback submits feedback for a single AI interaction.

type Correction

type Correction struct {
	// InteractionID is the ID of the interaction being corrected
	InteractionID string `json:"interaction_id"`

	// CorrectedResponse is the improved response
	CorrectedResponse string `json:"corrected_response"`

	// Reason explains why the correction was needed
	Reason string `json:"reason,omitempty"`

	// Notes provides additional context
	Notes string `json:"notes,omitempty"`

	// Tags for categorization
	Tags []string `json:"tags,omitempty"`
}

Correction represents a correction to an AI response.

type CorrectionResponse

type CorrectionResponse struct {
	// CorrectionID is the unique identifier
	CorrectionID string `json:"correction_id"`

	// InteractionID links to the original interaction
	InteractionID string `json:"interaction_id"`

	// Status indicates success/failure
	Status string `json:"status"`

	// Message provides additional information
	Message string `json:"message,omitempty"`

	// Diff shows the changes made
	Diff *DiffResult `json:"diff,omitempty"`

	// CreatedAt is when the correction was recorded
	CreatedAt time.Time `json:"created_at"`
}

CorrectionResponse represents the API response for correction submission.

type DiffResult

type DiffResult struct {
	// Original response
	Original string `json:"original"`

	// Corrected response
	Corrected string `json:"corrected"`

	// Changes is a list of change operations
	Changes []*Change `json:"changes"`

	// SimilarityScore (0.0 to 1.0)
	SimilarityScore float64 `json:"similarity_score"`
}

DiffResult represents the diff between original and corrected responses.

type ExportFormat

type ExportFormat string

ExportFormat specifies the export format.

const (
	// ExportFormatCSV exports to CSV
	ExportFormatCSV ExportFormat = "csv"

	// ExportFormatJSON exports to JSON
	ExportFormatJSON ExportFormat = "json"

	// ExportFormatExcel exports to Excel
	ExportFormatExcel ExportFormat = "excel"
)

type InteractionFeedback

type InteractionFeedback struct {
	// Prompt is the user's input/question
	Prompt string `json:"prompt"`

	// Response is the AI's response
	Response string `json:"response"`

	// Score is the feedback score (0.0 to 1.0)
	Score float64 `json:"score"`

	// Metadata contains additional context
	Metadata map[string]interface{} `json:"metadata,omitempty"`

	// SessionID links the interaction to a chat session
	SessionID string `json:"session_id,omitempty"`

	// ModelID identifies the model used
	ModelID string `json:"model_id,omitempty"`

	// Timestamp of the interaction
	Timestamp time.Time `json:"timestamp,omitempty"`
}

InteractionFeedback represents feedback for an AI interaction.

type InteractionFeedbackResponse

type InteractionFeedbackResponse struct {
	// InteractionID is the unique identifier for this interaction
	InteractionID string `json:"interaction_id"`

	// Status indicates success/failure
	Status string `json:"status"`

	// Message provides additional information
	Message string `json:"message,omitempty"`

	// CreatedAt is when the feedback was recorded
	CreatedAt time.Time `json:"created_at"`
}

InteractionFeedbackResponse represents the API response for feedback submission.

type Option

type Option func(*Client)

Option is a functional option for configuring the Client.

func WithAPIClient

func WithAPIClient(apiClient *client.Client) Option

WithAPIClient sets the underlying HTTP API client.

func WithBaseURL

func WithBaseURL(baseURL string) Option

WithBaseURL sets the RLHF base URL.

type ReasonCount

type ReasonCount struct {
	Reason string `json:"reason"`
	Count  int    `json:"count"`
}

ReasonCount represents a correction reason and its frequency.

type TrendPoint

type TrendPoint struct {
	Date  time.Time `json:"date"`
	Score float64   `json:"score"`
	Count int       `json:"count"`
}

TrendPoint represents a data point in a trend.

Jump to

Keyboard shortcuts

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