Documentation
ΒΆ
Overview ΒΆ
Package sarvam provides a Go client for the Sarvam AI API.
Index ΒΆ
- func Ptr[T any](v T) *T
- func SetAPIKey(apiKey string)
- type AudioCodec
- type ChatCompletionChoice
- type ChatCompletionModel
- type ChatCompletionParams
- type ChatCompletionResponse
- type Client
- func (c *Client) ChatCompletion(messages []Message, model ChatCompletionModel, req *ChatCompletionParams) (*ChatCompletionResponse, error)
- func (c *Client) IdentifyLanguage(input string) (*LanguageIdentificationResponse, error)
- func (c *Client) SetBaseURL(baseURL string)
- func (c *Client) SpeechToText(speech io.Reader, params SpeechToTextParams) (*SpeechToTextResponse, error)
- func (c *Client) SpeechToTextTranslate(speech io.Reader, params SpeechToTextTranslateParams) (*SpeechToTextTranslateResponse, error)
- func (c *Client) TextToSpeech(text string, targetLanguage Language, params TextToSpeechParams) (*TextToSpeechResponse, error)
- func (c *Client) Translate(input string, sourceLanguageCode, targetLanguageCode Language, ...) (*TranslationResponse, error)
- func (c *Client) Transliterate(input string, sourceLanguage Language, targetLanguage Language, ...) (*TransliterationResponse, error)
- type DiarizedEntry
- type DiarizedTranscript
- type ErrInputTooLong
- type HTTPError
- type Language
- type LanguageIdentificationResponse
- type Message
- type MessageRole
- type NumeralsFormat
- type OutputScript
- type ReasoningEffort
- type Script
- type Speaker
- type SpeakerGender
- type SpeechSampleRate
- type SpeechToTextModel
- type SpeechToTextParams
- type SpeechToTextResponse
- type SpeechToTextTranslateModel
- type SpeechToTextTranslateParams
- type SpeechToTextTranslateResponse
- type SpokenFormNumeralsLanguage
- type TextToSpeechModel
- type TextToSpeechParams
- type TextToSpeechResponse
- type Timestamps
- type TranslateParams
- type TranslationMode
- type TranslationModel
- type TranslationResponse
- type TransliterateParams
- type TransliterationResponse
- type Usage
Constants ΒΆ
This section is empty.
Variables ΒΆ
This section is empty.
Functions ΒΆ
Types ΒΆ
type AudioCodec ΒΆ added in v0.0.2
type AudioCodec string
var ( AudioCodecWav AudioCodec = "wav" AudioCodecXWav AudioCodec = "x-wav" AudioCodecWave AudioCodec = "wave" AudioCodecMp3 AudioCodec = "mp3" AudioCodecMpeg AudioCodec = "mpeg" AudioCodecMpeg3 AudioCodec = "mpeg3" AudioCodecXMp3 AudioCodec = "x-mp3" AudioCodecXMpeg3 AudioCodec = "x-mpeg-3" AudioCodecAac AudioCodec = "aac" AudioCodecXAac AudioCodec = "x-aac" AudioCodecAiff AudioCodec = "aiff" AudioCodecXAiff AudioCodec = "x-aiff" AudioCodecOgg AudioCodec = "ogg" AudioCodecOpus AudioCodec = "opus" AudioCodecFlac AudioCodec = "flac" AudioCodecXFlac AudioCodec = "x-flac" AudioCodecMp4 AudioCodec = "mp4" AudioCodecXM4a AudioCodec = "x-m4a" AudioCodecAmr AudioCodec = "amr" AudioCodecXMsWma AudioCodec = "x-ms-wma" AudioCodecWebm AudioCodec = "webm" AudioCodecPcmS16le AudioCodec = "pcm_s16le" AudioCodecPcmL16 AudioCodec = "pcm_l16" AudioCodecPcmRaw AudioCodec = "pcm_raw" )
type ChatCompletionChoice ΒΆ
type ChatCompletionChoice struct {
FinishReason string `json:"finish_reason"`
Index int `json:"index"`
Message Message `json:"message"`
}
ChatCompletionChoice represents a single completion choice.
type ChatCompletionModel ΒΆ
type ChatCompletionModel string
ChatCompletionModel specifies the model to use for chat completions.
var ( ChatCompletionModelBulbulV2 ChatCompletionModel = "bulbul:v2" ChatCompletionModelSarvamM ChatCompletionModel = "sarvam-m" )
type ChatCompletionParams ΒΆ added in v0.0.2
type ChatCompletionParams struct {
Temperature *float64
TopP *float64
ReasoningEffort *ReasoningEffort
MaxTokens *int
Stream *bool
Stop []string // string or []string. TODO: Find a way to make this more type safe.
N *int
Seed *int64
FrequencyPenalty *float64
PresencePenalty *float64
WikiGrounding *bool
}
ChatCompletionParams represents the parameters for chat completions.
type ChatCompletionResponse ΒΆ
type ChatCompletionResponse struct {
ID string `json:"id"`
Choices []ChatCompletionChoice `json:"choices"`
Created int64 `json:"created"`
Model string `json:"model"`
Object string `json:"object"`
Usage *Usage `json:"usage"`
}
ChatCompletionResponse represents the response from the chat completions API.
func ChatCompletion ΒΆ added in v0.0.2
func ChatCompletion(messages []Message, model ChatCompletionModel, req *ChatCompletionParams) (*ChatCompletionResponse, error)
ChatCompletion is a package-level function that uses the default client
func (*ChatCompletionResponse) GetChoiceContent ΒΆ
func (r *ChatCompletionResponse) GetChoiceContent(index int) string
GetChoiceContent returns the content of a specific choice by index.
func (*ChatCompletionResponse) GetFirstChoiceContent ΒΆ
func (r *ChatCompletionResponse) GetFirstChoiceContent() string
GetFirstChoiceContent returns the content of the first choice from the response.
type Client ΒΆ
type Client struct {
// contains filtered or unexported fields
}
Client represents a Sarvam AI API client.
func GetDefaultClient ΒΆ added in v0.0.2
func GetDefaultClient() *Client
GetDefaultClient returns the default client instance
func (*Client) ChatCompletion ΒΆ
func (c *Client) ChatCompletion(messages []Message, model ChatCompletionModel, req *ChatCompletionParams) (*ChatCompletionResponse, error)
ChatCompletion creates a chat completion using the Sarvam AI API.
func (*Client) IdentifyLanguage ΒΆ
func (c *Client) IdentifyLanguage(input string) (*LanguageIdentificationResponse, error)
IdentifyLanguage identifies the language (e.g., en-IN, hi-IN) and script (e.g., Latin, Devanagari) of the input text, supporting multiple languages.
func (*Client) SetBaseURL ΒΆ
SetBaseURL allows customization of the API endpoint URL.
func (*Client) SpeechToText ΒΆ
func (c *Client) SpeechToText(speech io.Reader, params SpeechToTextParams) (*SpeechToTextResponse, error)
SpeechToText converts speech from an audio file to text.
func (*Client) SpeechToTextTranslate ΒΆ
func (c *Client) SpeechToTextTranslate(speech io.Reader, params SpeechToTextTranslateParams) (*SpeechToTextTranslateResponse, error)
SpeechToTextTranslate automatically detects the input language, transcribes the speech, and translates the text to English.
func (*Client) TextToSpeech ΒΆ
func (c *Client) TextToSpeech(text string, targetLanguage Language, params TextToSpeechParams) (*TextToSpeechResponse, error)
TextToSpeech converts text to speech in the specified language.
func (*Client) Translate ΒΆ
func (c *Client) Translate(input string, sourceLanguageCode, targetLanguageCode Language, params *TranslateParams) (*TranslationResponse, error)
TranslateWithParams converts text from one language to another with custom parameters.
func (*Client) Transliterate ΒΆ
func (c *Client) Transliterate(input string, sourceLanguage Language, targetLanguage Language, params *TransliterateParams) (*TransliterationResponse, error)
Transliterate converts text from one script to another while preserving the original pronunciation.
type DiarizedEntry ΒΆ
type DiarizedEntry struct {
Transcript string `json:"transcript"`
StartTimeSeconds float64 `json:"start_time_seconds"`
EndTimeSeconds float64 `json:"end_time_seconds"`
SpeakerID string `json:"speaker_id"`
}
DiarizedEntry represents a single speaker's transcript segment.
type DiarizedTranscript ΒΆ
type DiarizedTranscript struct {
Entries []DiarizedEntry `json:"entries"`
}
DiarizedTranscript represents the complete diarized transcript.
type ErrInputTooLong ΒΆ
ErrInputTooLong is returned when the input length is greater than or equal to 1000 characters.
func (*ErrInputTooLong) Error ΒΆ
func (e *ErrInputTooLong) Error() string
type Language ΒΆ
type Language string
Language represents a supported language code.
const ( LanguageAssamese Language = "as-IN" LanguageBengali Language = "bn-IN" LanguageBodo Language = "brx-IN" LanguageDogri Language = "doi-IN" LanguageEnglish Language = "en-IN" LanguageGujarati Language = "gu-IN" LanguageHindi Language = "hi-IN" LanguageKannada Language = "kn-IN" LanguageKashmiri Language = "ks-IN" LanguageKonkani Language = "kok-IN" LanguageMaithili Language = "mai-IN" LanguageMalayalam Language = "ml-IN" LanguageManipuri Language = "mni-IN" LanguageMarathi Language = "mr-IN" LanguageNepali Language = "ne-IN" LanguageOdia Language = "od-IN" LanguagePunjabi Language = "pa-IN" LanguageSanskrit Language = "sa-IN" LanguageSantali Language = "sat-IN" LanguageSindhi Language = "sd-IN" LanguageTamil Language = "ta-IN" LanguageTelugu Language = "te-IN" LanguageUrdu Language = "ur-IN" )
const LanguageAuto Language = "auto"
type LanguageIdentificationResponse ΒΆ added in v0.0.2
LanguageIdentification represents the result of language identification.
func IdentifyLanguage ΒΆ added in v0.0.2
func IdentifyLanguage(input string) (*LanguageIdentificationResponse, error)
IdentifyLanguage is a package-level function that uses the default client
type Message ΒΆ
Message represents a message in the chat conversation.
func NewAssistantMessage ΒΆ added in v0.0.2
func NewMessage ΒΆ added in v0.0.2
func NewMessage(role MessageRole, content string) Message
func NewSystemMessage ΒΆ added in v0.0.2
func NewUserMessage ΒΆ added in v0.0.2
type MessageRole ΒΆ added in v0.0.2
type MessageRole string
const ( MessageRoleSystem MessageRole = "system" MessageRoleUser MessageRole = "user" MessageRoleAssistant MessageRole = "assistant" )
type NumeralsFormat ΒΆ
type NumeralsFormat string
NumeralsFormat specifies the format for numerals in the translation.
const ( // NumeralsFormatInternational represents international numeral format. NumeralsFormatInternational NumeralsFormat = "international" // NumeralsFormatNative represents native numeral format. NumeralsFormatNative NumeralsFormat = "native" )
type OutputScript ΒΆ
type OutputScript string
OutputScript controls the transliteration style applied to the output text.
const ( // OutputScriptRoman represents Roman script output. OutputScriptRoman OutputScript = "roman" // OutputScriptFullyNative represents fully native script output. OutputScriptFullyNative OutputScript = "fully-native" // OutputScriptSpokenFormInNative represents spoken form in native script output. OutputScriptSpokenFormInNative OutputScript = "spoken-form-in-native" )
type ReasoningEffort ΒΆ
type ReasoningEffort string
ReasoningEffort represents the reasoning effort level for chat completions.
const ( ReasoningEffortLow ReasoningEffort = "low" ReasoningEffortMedium ReasoningEffort = "medium" ReasoningEffortHigh ReasoningEffort = "high" )
type Script ΒΆ
type Script string
Script represents a writing script.
const ( ScriptLatin Script = "Latn" ScriptDevanagari Script = "Deva" ScriptBengali Script = "Beng" ScriptGujarati Script = "Gujr" ScriptKannada Script = "Knda" ScriptMalayalam Script = "Mlym" ScriptOdia Script = "Orya" ScriptGurmukhi Script = "Guru" ScriptTamil Script = "Taml" ScriptTelugu Script = "Telu" )
type Speaker ΒΆ
type Speaker string
Speaker represents a voice/speaker for text-to-speech conversion.
type SpeakerGender ΒΆ
type SpeakerGender string
SpeakerGender represents the gender of the speaker for better translations.
const ( SpeakerGenderMale SpeakerGender = "Male" SpeakerGenderFemale SpeakerGender = "Female" )
type SpeechSampleRate ΒΆ
type SpeechSampleRate int
SpeechSampleRate represents the audio sample rate for text-to-speech output.
var ( SpeechSampleRate8000 SpeechSampleRate = 8000 SpeechSampleRate16000 SpeechSampleRate = 16000 SpeechSampleRate22050 SpeechSampleRate = 22050 SpeechSampleRate24000 SpeechSampleRate = 24000 )
type SpeechToTextModel ΒΆ
type SpeechToTextModel string
SpeechToTextModel specifies the model to use for speech-to-text conversion.
var ( SpeechToTextModelSaarikaV1 SpeechToTextModel = "saarika:v1" SpeechToTextModelSaarikaV2 SpeechToTextModel = "saarika:v2" SpeechToTextModelSaarikaV2dot5 SpeechToTextModel = "saarika:v2.5" SpeechToTextModelSaarikaFlash SpeechToTextModel = "saarika:flash" )
type SpeechToTextParams ΒΆ
type SpeechToTextParams struct {
Model *SpeechToTextModel // Optional: Model to use (default: saarika:v2.5)
Language *Language // Optional: Language code for the input audio
WithTimestamps *bool // Optional: Whether to include timestamps in response
}
SpeechToTextParams contains parameters for speech-to-text conversion.
type SpeechToTextResponse ΒΆ added in v0.0.2
type SpeechToTextResponse struct {
RequestId string `json:"request_id"`
Transcript string `json:"transcript"`
Timestamps *Timestamps `json:"timestamps,omitempty"`
DiarizedTranscript *DiarizedTranscript `json:"diarized_transcript,omitempty"`
Language Language `json:"language_code"`
}
SpeechToTextResponse represents the result of a speech-to-text operation.
func SpeechToText ΒΆ
func SpeechToText(speech io.Reader, params SpeechToTextParams) (*SpeechToTextResponse, error)
SpeechToText is a package-level function that uses the default client
func (*SpeechToTextResponse) String ΒΆ added in v0.0.2
func (s *SpeechToTextResponse) String() string
String returns the transcribed text.
type SpeechToTextTranslateModel ΒΆ
type SpeechToTextTranslateModel string
SpeechToTextTranslateModel specifies the model to use for speech-to-text with translation.
var ( SpeechToTextTranslateModelSaarasV1 SpeechToTextTranslateModel = "saaras:v1" SpeechToTextTranslateModelSaarasV2 SpeechToTextTranslateModel = "saaras:v2" SpeechToTextTranslateModelSaarasV2dot5 SpeechToTextTranslateModel = "saaras:v2.5" SpeechToTextTranslateModelSaarasFlash SpeechToTextTranslateModel = "saaras:flash" )
type SpeechToTextTranslateParams ΒΆ
type SpeechToTextTranslateParams struct {
Prompt *string // Optional: Conversation context to boost model accuracy
Model *SpeechToTextTranslateModel // Optional: Model to use for speech-to-text conversion
AudioCodec *AudioCodec // Optional: Audio codec to use for speech-to-text conversion
}
SpeechToTextTranslateParams contains parameters for speech-to-text-translate conversion.
type SpeechToTextTranslateResponse ΒΆ added in v0.0.2
type SpeechToTextTranslateResponse struct {
RequestId string
Transcript string
Language Language
DiarizedTranscript *DiarizedTranscript
}
SpeechToTextTranslateResponse represents the result of a speech-to-text-translate operation.
func SpeechToTextTranslate ΒΆ
func SpeechToTextTranslate(speech io.Reader, params SpeechToTextTranslateParams) (*SpeechToTextTranslateResponse, error)
SpeechToTextTranslate is a package-level function that uses the default client
func (*SpeechToTextTranslateResponse) String ΒΆ added in v0.0.2
func (s *SpeechToTextTranslateResponse) String() string
String returns the transcribed and translated text.
type SpokenFormNumeralsLanguage ΒΆ added in v0.0.2
type SpokenFormNumeralsLanguage string
SpokenFormNumeralsLanguage specifies the language for spoken form numerals.
const ( // SpokenFormNumeralsLanguageEnglish represents English numerals in spoken form. SpokenFormNumeralsLanguageEnglish SpokenFormNumeralsLanguage = "english" // SpokenFormNumeralsLanguageNative represents native language numerals in spoken form. SpokenFormNumeralsLanguageNative SpokenFormNumeralsLanguage = "native" )
type TextToSpeechModel ΒΆ
type TextToSpeechModel string
TextToSpeechModel specifies the model to use for text-to-speech conversion.
var (
TextToSpeechModelBulbulV2 TextToSpeechModel = "bulbul:v2"
)
type TextToSpeechParams ΒΆ
type TextToSpeechParams struct {
Speaker *Speaker
Pitch *float64
Pace *float64
Loudness *float64
SpeechSampleRate *SpeechSampleRate
EnablePreprocessing *bool
Model *TextToSpeechModel
}
TextToSpeechParams contains all parameters for text-to-speech conversion.
type TextToSpeechResponse ΒΆ added in v0.0.2
TextToSpeechResponse represents the result of a text-to-speech operation.
func TextToSpeech ΒΆ
func TextToSpeech(text string, targetLanguage Language, params TextToSpeechParams) (*TextToSpeechResponse, error)
TextToSpeech is a package-level function that uses the default client
func (*TextToSpeechResponse) Bytes ΒΆ added in v0.0.2
func (t *TextToSpeechResponse) Bytes() ([]byte, error)
func (*TextToSpeechResponse) Save ΒΆ added in v0.0.2
func (t *TextToSpeechResponse) Save(filename string) error
Save saves the text-to-speech data as a WAV file.
type Timestamps ΒΆ
type Timestamps struct {
Words []string `json:"words"`
StartTimeSeconds []float64 `json:"start_time_seconds"`
EndTimeSeconds []float64 `json:"end_time_seconds"`
}
Timestamps represents word-level timing information for speech-to-text results.
type TranslateParams ΒΆ
type TranslateParams struct {
SpeakerGender *SpeakerGender
Mode *TranslationMode
Model *TranslationModel
EnablePreprocessing *bool
OutputScript *OutputScript
NumeralsFormat *NumeralsFormat
}
TranslateParams contains all optional parameters for translation.
type TranslationMode ΒΆ
type TranslationMode string
TranslationMode specifies the tone or style of the translation.
const ( // TranslationModeFormal represents formal translation style. TranslationModeFormal TranslationMode = "formal" // TranslationModeModernColloquial represents modern colloquial translation style. TranslationModeModernColloquial TranslationMode = "modern-colloquial" // TranslationModeClassicColloquial represents classic colloquial translation style. TranslationModeClassicColloquial TranslationMode = "classic-colloquial" // TranslationModeCodeMixed represents code-mixed translation style. TranslationModeCodeMixed TranslationMode = "code-mixed" )
type TranslationModel ΒΆ
type TranslationModel string
TranslationModel specifies the translation model to use.
var ( TranslationModelMayuraV1 TranslationModel = "mayura:v1" TranslationModelSarvamTranslate TranslationModel = "sarvam-translate:v1" )
type TranslationResponse ΒΆ added in v0.0.2
TranslationResponse represents the result of a translation operation.
func Translate ΒΆ added in v0.0.2
func Translate(input string, sourceLanguageCode, targetLanguageCode Language, params *TranslateParams) (*TranslationResponse, error)
Translate is a package-level function that uses the default client
func (*TranslationResponse) String ΒΆ added in v0.0.2
func (t *TranslationResponse) String() string
String returns the translated text.
type TransliterateParams ΒΆ added in v0.0.2
type TransliterateParams struct {
NumeralsFormat *NumeralsFormat
SpokenFormNumeralsLanguage *SpokenFormNumeralsLanguage
SpokenForm *bool
}
TransliterateParams contains all optional parameters for transliteration.
type TransliterationResponse ΒΆ added in v0.0.2
type TransliterationResponse struct {
RequestId string
TransliteratedText string
SourceLanguage Language
}
TransliterationResponse represents the result of a transliteration operation.
func Transliterate ΒΆ added in v0.0.2
func Transliterate(input string, sourceLanguage Language, targetLanguage Language) (*TransliterationResponse, error)
Transliterate is a package-level function that uses the default client
func (*TransliterationResponse) String ΒΆ added in v0.0.2
func (t *TransliterationResponse) String() string
String returns the transliterated text.
Source Files
ΒΆ
Directories
ΒΆ
| Path | Synopsis |
|---|---|
|
examples
|
|
|
chatcompletions
command
|
|
|
languageidentification
command
|
|
|
speechtotext
command
|
|
|
speechtotexttranslate
command
|
|
|
text
command
|
|
|
texttospeech
command
|
|
|
transliteratetext
command
|