Documentation
ΒΆ
Overview ΒΆ
Package sarvam provides a Go client for the Sarvam AI API.
Index ΒΆ
- func Bool(b bool) *bool
- func Float64(f float64) *float64
- func Int(i int) *int
- func String(s string) *string
- type ChatCompletionChoice
- type ChatCompletionModel
- type ChatCompletionRequest
- type ChatCompletionResponse
- type Client
- func (c *Client) ChatCompletion(req *ChatCompletionRequest) (*ChatCompletionResponse, error)
- func (c *Client) ChatCompletionWithOptions(messages []Message, model ChatCompletionModel, options map[string]interface{}) (*ChatCompletionResponse, error)
- func (c *Client) IdentifyLanguage(input string) (*LanguageIdentification, error)
- func (c *Client) SetBaseURL(baseURL string)
- func (c *Client) SimpleChatCompletion(messages []Message, model ChatCompletionModel) (*ChatCompletionResponse, error)
- func (c *Client) SpeechToText(params SpeechToTextParams) (*SpeechToText, error)
- func (c *Client) SpeechToTextTranslate(params SpeechToTextTranslateParams) (*SpeechToTextTranslate, error)
- func (c *Client) TextToSpeech(params TextToSpeechParams) (*TextToSpeech, error)
- func (c *Client) Translate(input string, sourceLanguageCode, targetLanguageCode Language) (*Translation, error)
- func (c *Client) TranslateWithOptions(params *TranslateParams) (*Translation, error)
- func (c *Client) Transliterate(input string, sourceLanguage Language, targetLanguage Language) (*Transliteration, error)
- type DiarizedEntry
- type DiarizedTranscript
- type ErrInputTooLong
- type HTTPError
- type Language
- type LanguageIdentification
- type Message
- type NumeralsFormat
- type OutputScript
- type ReasoningEffort
- type Script
- type Speaker
- type SpeakerGender
- type SpeechSampleRate
- type SpeechToText
- type SpeechToTextModel
- type SpeechToTextParams
- type SpeechToTextTranslate
- type SpeechToTextTranslateModel
- type SpeechToTextTranslateParams
- type TextToSpeech
- type TextToSpeechModel
- type TextToSpeechParams
- type Timestamps
- type TranslateParams
- type Translation
- type TranslationMode
- type TranslationModel
- type Transliteration
- type Usage
Constants ΒΆ
This section is empty.
Variables ΒΆ
This section is empty.
Functions ΒΆ
Types ΒΆ
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 ChatCompletionRequest ΒΆ
type ChatCompletionRequest struct { Messages []Message `json:"messages"` Model ChatCompletionModel `json:"model"` Temperature *float64 `json:"temperature,omitempty"` TopP *float64 `json:"top_p,omitempty"` ReasoningEffort *ReasoningEffort `json:"reasoning_effort,omitempty"` MaxTokens *int `json:"max_tokens,omitempty"` Stream *bool `json:"stream,omitempty"` Stop interface{} `json:"stop,omitempty"` // string or []string N *int `json:"n,omitempty"` Seed *int64 `json:"seed,omitempty"` FrequencyPenalty *float64 `json:"frequency_penalty,omitempty"` PresencePenalty *float64 `json:"presence_penalty,omitempty"` WikiGrounding *bool `json:"wiki_grounding,omitempty"` }
ChatCompletionRequest represents the request payload 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 (*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 (*Client) ChatCompletion ΒΆ
func (c *Client) ChatCompletion(req *ChatCompletionRequest) (*ChatCompletionResponse, error)
ChatCompletion creates a chat completion using the Sarvam AI API.
func (*Client) ChatCompletionWithOptions ΒΆ
func (c *Client) ChatCompletionWithOptions(messages []Message, model ChatCompletionModel, options map[string]interface{}) (*ChatCompletionResponse, error)
ChatCompletionWithOptions creates a chat completion with custom options.
func (*Client) IdentifyLanguage ΒΆ
func (c *Client) IdentifyLanguage(input string) (*LanguageIdentification, 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) SimpleChatCompletion ΒΆ
func (c *Client) SimpleChatCompletion(messages []Message, model ChatCompletionModel) (*ChatCompletionResponse, error)
SimpleChatCompletion is a convenience function for simple chat completions.
func (*Client) SpeechToText ΒΆ
func (c *Client) SpeechToText(params SpeechToTextParams) (*SpeechToText, error)
SpeechToText converts speech from an audio file to text.
func (*Client) SpeechToTextTranslate ΒΆ
func (c *Client) SpeechToTextTranslate(params SpeechToTextTranslateParams) (*SpeechToTextTranslate, error)
SpeechToTextTranslate automatically detects the input language, transcribes the speech, and translates the text to English.
func (*Client) TextToSpeech ΒΆ
func (c *Client) TextToSpeech(params TextToSpeechParams) (*TextToSpeech, error)
TextToSpeech converts text to speech in the specified language.
func (*Client) Translate ΒΆ
func (c *Client) Translate(input string, sourceLanguageCode, targetLanguageCode Language) (*Translation, error)
Translate converts text from one language to another while preserving its meaning. This is the simple version that uses default options.
func (*Client) TranslateWithOptions ΒΆ
func (c *Client) TranslateWithOptions(params *TranslateParams) (*Translation, error)
TranslateWithOptions converts text from one language to another with custom options.
func (*Client) Transliterate ΒΆ
func (c *Client) Transliterate(input string, sourceLanguage Language, targetLanguage Language) (*Transliteration, 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 LanguageIdentification ΒΆ
LanguageIdentification represents the result of language identification.
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 SpeechToText ΒΆ
type SpeechToText struct { RequestId string `json:"request_id"` Transcript string `json:"transcript"` Timestamps *Timestamps `json:"timestamps,omitempty"` DiarizedTranscript *DiarizedTranscript `json:"diarized_transcript,omitempty"` LanguageCode Language `json:"language_code"` }
SpeechToText represents the result of a speech-to-text operation.
func (*SpeechToText) String ΒΆ
func (s *SpeechToText) String() string
String returns the transcribed text.
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 { FilePath string // Required: Path to the audio file Model *SpeechToTextModel // Optional: Model to use (default: saarika:v2.5) LanguageCode *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 SpeechToTextTranslate ΒΆ
type SpeechToTextTranslate struct { RequestId string `json:"request_id"` Transcript string `json:"transcript"` LanguageCode Language `json:"language_code"` DiarizedTranscript *DiarizedTranscript `json:"diarized_transcript,omitempty"` }
SpeechToTextTranslate represents the result of a speech-to-text-translate operation.
func (*SpeechToTextTranslate) String ΒΆ
func (s *SpeechToTextTranslate) String() string
String returns the transcribed and translated 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 { FilePath string // Required: Path to the audio file Prompt *string // Optional: Conversation context to boost model accuracy Model *SpeechToTextTranslateModel // Optional: Model to use for speech-to-text conversion }
SpeechToTextTranslateParams contains parameters for speech-to-text-translate conversion.
type TextToSpeech ΒΆ
TextToSpeech represents the result of a text-to-speech operation.
func (*TextToSpeech) Save ΒΆ
func (t *TextToSpeech) Save(filename string) error
Save saves the text-to-speech data as a WAV file.
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 { Text string TargetLanguage Language Speaker *Speaker Pitch *float64 Pace *float64 Loudness *float64 SpeechSampleRate *SpeechSampleRate EnablePreprocessing *bool Model *TextToSpeechModel }
TextToSpeechParams contains all parameters for text-to-speech conversion.
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 { Input string SourceLanguage Language TargetLanguage Language SpeakerGender *SpeakerGender Mode *TranslationMode Model *TranslationModel EnablePreprocessing *bool OutputScript *OutputScript NumeralsFormat *NumeralsFormat }
TranslateParams contains all optional parameters for translation.
type Translation ΒΆ
Translation represents the result of a translation operation.
func (*Translation) String ΒΆ
func (t *Translation) String() string
String returns the translated text.
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 Transliteration ΒΆ
Transliteration represents the result of a transliteration operation.
func (*Transliteration) String ΒΆ
func (t *Transliteration) String() string
String returns the transliterated text.
Source Files
ΒΆ
Directories
ΒΆ
Path | Synopsis |
---|---|
examples
|
|
chatcompletions
command
|
|
speechtotext
command
|
|
text
command
|
|
texttospeech
command
|