Documentation
¶
Index ¶
- Constants
- Variables
- type APIError
- type AudioTooLongError
- type BatchService
- func (b *BatchService) Create(ctx context.Context, req *models.BatchRequest) (*models.Job, error)
- func (b *BatchService) Get(ctx context.Context, jobID string) (*models.Job, error)
- func (b *BatchService) Results(ctx context.Context, job *models.Job) (map[string]*models.TranscriptionResult, error)
- func (b *BatchService) Wait(ctx context.Context, jobID string, poll time.Duration) (*models.Job, error)
- type ChatService
- type Client
- type FormatError
- type MaxRetriesError
- type Metric
- type Option
- func WithAPIKey(key string) Option
- func WithBaseURL(baseURL string) Option
- func WithDefaultFormat(f models.Format) Option
- func WithHTTPClient(hc *http.Client) Option
- func WithLogger(l *slog.Logger) Option
- func WithMaxConcurrency(n int) Option
- func WithMaxRetries(n int) Option
- func WithMetrics(fn func(Metric)) Option
- func WithRetryDelays(base, maxDelay time.Duration) Option
- func WithTimeout(d time.Duration) Option
- func WithUserAgent(ua string) Option
- type RateLimitError
- type SpeechDuplex
- func (d *SpeechDuplex) All() iter.Seq2[models.AudioChunk, error]
- func (d *SpeechDuplex) Chunk() models.AudioChunk
- func (d *SpeechDuplex) Close() error
- func (d *SpeechDuplex) CloseSend(ctx context.Context) error
- func (d *SpeechDuplex) Err() error
- func (d *SpeechDuplex) Flush(ctx context.Context) error
- func (d *SpeechDuplex) Format() models.Format
- func (d *SpeechDuplex) IsClosed() bool
- func (d *SpeechDuplex) Next() bool
- func (d *SpeechDuplex) Reset()
- func (d *SpeechDuplex) SendText(ctx context.Context, text string) error
- func (d *SpeechDuplex) SendToken(ctx context.Context, token string) error
- func (d *SpeechDuplex) SpokenText() string
- type SpeechService
- func (s *SpeechService) Create(ctx context.Context, req *models.SpeechRequest) (*models.Audio, error)
- func (s *SpeechService) Duplex(ctx context.Context, req *models.SpeechRequest) (*SpeechDuplex, error)
- func (s *SpeechService) Stream(ctx context.Context, req *models.SpeechRequest) (*SpeechStream, error)
- type SpeechStream
- type Stream
- type StreamError
- type TranscriptionService
- type TranscriptionStream
- func (s *TranscriptionStream) Close() error
- func (s *TranscriptionStream) CloseSend(ctx context.Context) error
- func (s *TranscriptionStream) Flush(ctx context.Context) error
- func (s *TranscriptionStream) Format() models.Format
- func (s *TranscriptionStream) Next(ctx context.Context) (models.TranscriptionEvent, error)
- func (s *TranscriptionStream) SendAudio(ctx context.Context, frame []byte) error
- func (s *TranscriptionStream) SpeechEnd(ctx context.Context) error
- func (s *TranscriptionStream) SpeechStart(ctx context.Context) error
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)") 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 AudioTooLongError ¶
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)
type ChatService ¶ added in v0.2.0
type ChatService struct {
// contains filtered or unexported fields
}
func (*ChatService) Create ¶ added in v0.2.0
func (c *ChatService) Create(ctx context.Context, req *models.ChatRequest) (*models.ChatResponse, error)
type Client ¶
type Client struct {
Speech *SpeechService
Transcription *TranscriptionService
Batch *BatchService
Chat *ChatService
// contains filtered or unexported fields
}
func NewFromEnv ¶
type FormatError ¶
func (*FormatError) Error ¶
func (e *FormatError) Error() string
func (*FormatError) Unwrap ¶
func (e *FormatError) Unwrap() error
type MaxRetriesError ¶
func (*MaxRetriesError) Error ¶
func (e *MaxRetriesError) Error() string
func (*MaxRetriesError) Unwrap ¶
func (e *MaxRetriesError) Unwrap() []error
type Option ¶
type Option func(*config)
func WithAPIKey ¶
func WithBaseURL ¶
func WithDefaultFormat ¶
func WithHTTPClient ¶
func WithLogger ¶
func WithMaxConcurrency ¶
func WithMaxRetries ¶
func WithMetrics ¶ added in v0.3.0
func WithRetryDelays ¶
func WithTimeout ¶
func WithUserAgent ¶
type RateLimitError ¶
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 (d *SpeechDuplex) All() iter.Seq2[models.AudioChunk, error]
func (*SpeechDuplex) Chunk ¶
func (d *SpeechDuplex) Chunk() models.AudioChunk
func (*SpeechDuplex) Close ¶
func (d *SpeechDuplex) Close() error
func (*SpeechDuplex) Err ¶
func (d *SpeechDuplex) Err() 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 (s *SpeechService) Create(ctx context.Context, req *models.SpeechRequest) (*models.Audio, error)
func (*SpeechService) Duplex ¶
func (s *SpeechService) Duplex(ctx context.Context, req *models.SpeechRequest) (*SpeechDuplex, error)
func (*SpeechService) Stream ¶
func (s *SpeechService) Stream(ctx context.Context, req *models.SpeechRequest) (*SpeechStream, error)
type SpeechStream ¶
type SpeechStream struct {
// contains filtered or unexported fields
}
func (*SpeechStream) All ¶
func (s *SpeechStream) All() iter.Seq2[models.AudioChunk, error]
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 }
type StreamError ¶
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 (t *TranscriptionService) Create(ctx context.Context, req *models.TranscriptionRequest) (*models.TranscriptionResult, error)
func (*TranscriptionService) Stream ¶
func (t *TranscriptionService) Stream(ctx context.Context, req *models.TranscriptionStreamRequest) (*TranscriptionStream, error)
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) Format ¶
func (s *TranscriptionStream) Format() models.Format
func (*TranscriptionStream) Next ¶
func (s *TranscriptionStream) Next(ctx context.Context) (models.TranscriptionEvent, error)
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
Source Files
¶
Click to show internal directories.
Click to hide internal directories.