@@ -7,21 +7,28 @@ class Gemini
77 module Transcription
88 DEFAULT_PROMPT = 'Transcribe the provided audio and respond with only the transcript text.'
99
10- def transcribe ( audio_file , model :, language :, params : { } , **options )
10+ # rubocop:disable Lint/UnusedMethodArgument, Metrics/ParameterLists
11+ def transcribe ( audio_file , model :, language :, params : { } , prompt : nil , temperature : nil ,
12+ response_format : nil , timestamp_granularities : nil , speaker_names : nil ,
13+ speaker_references : nil , chunking_strategy : nil , response_mime_type : 'text/plain' ,
14+ max_output_tokens : nil , safety_settings : nil )
1115 attachment = Attachment . new ( audio_file )
12- payload = render_transcription_payload ( attachment , language :, params :, **options )
16+ payload = render_transcription_payload ( attachment , language :, params :, prompt :, temperature :,
17+ response_mime_type :, max_output_tokens :, safety_settings :)
1318 response = @connection . post ( transcription_url ( model ) , payload )
1419 parse_transcription_response ( response , model :)
1520 end
21+ # rubocop:enable Lint/UnusedMethodArgument, Metrics/ParameterLists
1622
1723 private
1824
1925 def transcription_url ( model )
2026 "models/#{ model } :generateContent"
2127 end
2228
23- def render_transcription_payload ( attachment , language :, params : { } , **options )
24- prompt = build_prompt ( options [ :prompt ] , language )
29+ def render_transcription_payload ( attachment , language :, params : { } , prompt : nil , temperature : nil , # rubocop:disable Metrics/ParameterLists
30+ response_mime_type : 'text/plain' , max_output_tokens : nil , safety_settings : nil )
31+ prompt = build_prompt ( prompt , language )
2532 audio_part = format_audio_part ( attachment )
2633
2734 raise UnsupportedAttachmentError , attachment . mime_type unless attachment . audio?
@@ -38,20 +45,19 @@ def render_transcription_payload(attachment, language:, params: {}, **options)
3845 ]
3946 }
4047
41- generation_config = build_generation_config ( options )
48+ generation_config = build_generation_config ( response_mime_type : , temperature : , max_output_tokens : )
4249 payload [ :generationConfig ] = generation_config unless generation_config . empty?
43- payload [ :safetySettings ] = options [ : safety_settings] if options [ : safety_settings]
50+ payload [ :safetySettings ] = safety_settings if safety_settings
4451
4552 Utils . deep_merge ( payload , params )
4653 end
4754
48- def build_generation_config ( options )
55+ def build_generation_config ( response_mime_type : , temperature : , max_output_tokens : )
4956 config = { }
50- response_mime_type = options . fetch ( :response_mime_type , 'text/plain' )
5157
5258 config [ :responseMimeType ] = response_mime_type if response_mime_type
53- config [ :temperature ] = options [ : temperature] if options . key? ( : temperature)
54- config [ :maxOutputTokens ] = options [ : max_output_tokens] if options [ : max_output_tokens]
59+ config [ :temperature ] = temperature if temperature
60+ config [ :maxOutputTokens ] = max_output_tokens if max_output_tokens
5561
5662 config
5763 end
0 commit comments