sarvam

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2026 License: MIT Imports: 26 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	MetricRequest         = "http.request"
	MetricRetry           = "http.retry"
	MetricFirstToken      = "chat.first_token"
	MetricFirstAudio      = "tts.first_audio"
	MetricFirstTranscript = "stt.first_transcript"
)
View Source
const (
	DefaultBaseURL = "https://api.sarvam.ai"

	DefaultTimeout        = 5 * time.Minute
	DefaultMaxRetries     = 3
	DefaultMaxConcurrency = 8
)
View Source
const Version = "0.3.0"

Variables

View Source
var (
	ErrMissingAPIKey      = errors.New("sarvam: missing API key (set SARVAM_API_KEY or use WithAPIKey)")
	ErrUnauthorized       = errors.New("sarvam: unauthorized")
	ErrInvalidRequest     = errors.New("sarvam: invalid request")
	ErrRateLimited        = errors.New("sarvam: rate limited")
	ErrQuotaExceeded      = errors.New("sarvam: credits exhausted")
	ErrServer             = errors.New("sarvam: server error")
	ErrTimeout            = errors.New("sarvam: request timed out")
	ErrMaxRetriesExceeded = errors.New("sarvam: all retries failed")
	ErrUnsupportedFormat  = models.ErrUnsupportedFormat
	ErrAudioTooLong       = errors.New("sarvam: audio is too long for this endpoint")
	ErrDecode             = errors.New("sarvam: could not decode the response")
	ErrStreamClosed       = errors.New("sarvam: stream is closed")
)

Functions

This section is empty.

Types

type APIError

type APIError struct {
	StatusCode int
	Code       string
	Message    string
	RequestID  string
	Raw        []byte
}

func (*APIError) Error

func (e *APIError) Error() string

func (*APIError) Kind

func (e *APIError) Kind() string

func (*APIError) Unwrap

func (e *APIError) Unwrap() error

type AudioTooLongError

type AudioTooLongError struct {
	Duration    time.Duration
	MaxDuration time.Duration
	Endpoint    string
}

func (*AudioTooLongError) Error

func (e *AudioTooLongError) Error() string

func (*AudioTooLongError) Unwrap

func (e *AudioTooLongError) Unwrap() error

type BatchService

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

func (*BatchService) Create

func (b *BatchService) Create(ctx context.Context, req *models.BatchRequest) (*models.Job, error)

func (*BatchService) Get

func (b *BatchService) Get(ctx context.Context, jobID string) (*models.Job, error)

func (*BatchService) Results

func (*BatchService) Wait

func (b *BatchService) Wait(ctx context.Context, jobID string, poll time.Duration) (*models.Job, error)

type ChatService added in v0.2.0

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

func (*ChatService) Create added in v0.2.0

func (*ChatService) Stream added in v0.2.0

type Client

type Client struct {
	Speech *SpeechService

	Transcription *TranscriptionService

	Batch *BatchService

	Chat *ChatService
	// contains filtered or unexported fields
}

func New

func New(opts ...Option) (*Client, error)

func NewFromEnv

func NewFromEnv(opts ...Option) (*Client, error)

func (*Client) BaseURL

func (c *Client) BaseURL() string

type FormatError

type FormatError struct {
	Format    models.Format
	Endpoint  string
	Supported []models.Format
}

func (*FormatError) Error

func (e *FormatError) Error() string

func (*FormatError) Unwrap

func (e *FormatError) Unwrap() error

type MaxRetriesError

type MaxRetriesError struct {
	Attempts int
	Err      error
}

func (*MaxRetriesError) Error

func (e *MaxRetriesError) Error() string

func (*MaxRetriesError) Unwrap

func (e *MaxRetriesError) Unwrap() []error

type Metric added in v0.3.0

type Metric struct {
	Name     string
	Endpoint string
	Duration time.Duration
	Status   int
	Attempt  int
	Err      error
}

type Option

type Option func(*config)

func WithAPIKey

func WithAPIKey(key string) Option

func WithBaseURL

func WithBaseURL(baseURL string) Option

func WithDefaultFormat

func WithDefaultFormat(f models.Format) Option

func WithHTTPClient

func WithHTTPClient(hc *http.Client) Option

func WithLogger

func WithLogger(l *slog.Logger) Option

func WithMaxConcurrency

func WithMaxConcurrency(n int) Option

func WithMaxRetries

func WithMaxRetries(n int) Option

func WithMetrics added in v0.3.0

func WithMetrics(fn func(Metric)) Option

func WithRetryDelays

func WithRetryDelays(base, maxDelay time.Duration) Option

func WithTimeout

func WithTimeout(d time.Duration) Option

func WithUserAgent

func WithUserAgent(ua string) Option

type RateLimitError

type RateLimitError struct {
	*APIError
	RetryAfter time.Duration
}

func (*RateLimitError) Error

func (e *RateLimitError) Error() string

func (*RateLimitError) Unwrap

func (e *RateLimitError) Unwrap() error

type SpeechDuplex

type SpeechDuplex struct {
	OnSentence func(string)
	// contains filtered or unexported fields
}

func (*SpeechDuplex) All

func (*SpeechDuplex) Chunk

func (d *SpeechDuplex) Chunk() models.AudioChunk

func (*SpeechDuplex) Close

func (d *SpeechDuplex) Close() error

func (*SpeechDuplex) CloseSend

func (d *SpeechDuplex) CloseSend(ctx context.Context) error

func (*SpeechDuplex) Err

func (d *SpeechDuplex) Err() error

func (*SpeechDuplex) Flush

func (d *SpeechDuplex) Flush(ctx context.Context) error

func (*SpeechDuplex) Format

func (d *SpeechDuplex) Format() models.Format

func (*SpeechDuplex) IsClosed added in v0.3.0

func (d *SpeechDuplex) IsClosed() bool

IsClosed reports whether the connection has ended and must be replaced.

func (*SpeechDuplex) Next

func (d *SpeechDuplex) Next() bool

func (*SpeechDuplex) Reset added in v0.3.0

func (d *SpeechDuplex) Reset()

func (*SpeechDuplex) SendText

func (d *SpeechDuplex) SendText(ctx context.Context, text string) error

func (*SpeechDuplex) SendToken added in v0.3.0

func (d *SpeechDuplex) SendToken(ctx context.Context, token string) error

func (*SpeechDuplex) SpokenText added in v0.3.0

func (d *SpeechDuplex) SpokenText() string

type SpeechService

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

func (*SpeechService) Create

func (*SpeechService) Duplex

func (*SpeechService) Stream

type SpeechStream

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

func (*SpeechStream) All

func (*SpeechStream) Chunk

func (s *SpeechStream) Chunk() models.AudioChunk

func (*SpeechStream) Close

func (s *SpeechStream) Close() error

func (*SpeechStream) Err

func (s *SpeechStream) Err() error

func (*SpeechStream) Format

func (s *SpeechStream) Format() models.Format

func (*SpeechStream) Next

func (s *SpeechStream) Next() bool

type Stream added in v0.2.0

type Stream[T any] struct {
	// contains filtered or unexported fields
}

func (*Stream[T]) All added in v0.2.0

func (s *Stream[T]) All() iter.Seq2[T, error]

func (*Stream[T]) Chunk added in v0.2.0

func (s *Stream[T]) Chunk() T

func (*Stream[T]) Close added in v0.2.0

func (s *Stream[T]) Close() error

func (*Stream[T]) Err added in v0.2.0

func (s *Stream[T]) Err() error

func (*Stream[T]) Next added in v0.2.0

func (s *Stream[T]) Next() bool

type StreamError

type StreamError struct {
	ChunkIndex int
	Underlying error
}

func (*StreamError) Error

func (e *StreamError) Error() string

func (*StreamError) Unwrap

func (e *StreamError) Unwrap() error

type TranscriptionService

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

func (*TranscriptionService) Create

func (*TranscriptionService) Stream

type TranscriptionStream

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

func (*TranscriptionStream) Close

func (s *TranscriptionStream) Close() error

func (*TranscriptionStream) CloseSend

func (s *TranscriptionStream) CloseSend(ctx context.Context) error

func (*TranscriptionStream) Flush

func (s *TranscriptionStream) Flush(ctx context.Context) error

func (*TranscriptionStream) Format

func (s *TranscriptionStream) Format() models.Format

func (*TranscriptionStream) Next

func (*TranscriptionStream) SendAudio

func (s *TranscriptionStream) SendAudio(ctx context.Context, frame []byte) error

func (*TranscriptionStream) SpeechEnd

func (s *TranscriptionStream) SpeechEnd(ctx context.Context) error

func (*TranscriptionStream) SpeechStart

func (s *TranscriptionStream) SpeechStart(ctx context.Context) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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