Skip to content

Commit a410d0a

Browse files
authored
feat: Replace ML.GENERATE_TEXT with AI.GENERATE for audio transcription (#2151)
* change to ai.generate * convert the input data type * remove default value setting
1 parent 7600001 commit a410d0a

File tree

2 files changed

+925
-52
lines changed

2 files changed

+925
-52
lines changed

bigframes/operations/blob.py

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -804,35 +804,29 @@ def audio_transcribe(
804804
raise ValueError("Must specify the engine, supported value is 'bigquery'.")
805805

806806
import bigframes.bigquery as bbq
807-
import bigframes.ml.llm as llm
808807
import bigframes.pandas as bpd
809808

810809
# col name doesn't matter here. Rename to avoid column name conflicts
811810
audio_series = bigframes.series.Series(self._block)
812811

813812
prompt_text = "**Task:** Transcribe the provided audio. **Instructions:** - Your response must contain only the verbatim transcription of the audio. - Do not include any introductory text, summaries, or conversational filler in your response. The output should begin directly with the first word of the audio."
814813

815-
llm_model = llm.GeminiTextGenerator(
816-
model_name=model_name,
817-
session=self._block.session,
818-
connection_name=connection,
819-
)
814+
# Convert the audio series to the runtime representation required by the model.
815+
audio_runtime = audio_series.blob._get_runtime("R", with_metadata=True)
820816

821-
# transcribe audio using ML.GENERATE_TEXT
822-
transcribed_results = llm_model.predict(
823-
X=audio_series,
824-
prompt=[prompt_text, audio_series],
825-
temperature=0.0,
817+
transcribed_results = bbq.ai.generate(
818+
prompt=(prompt_text, audio_runtime),
819+
connection_id=connection,
820+
endpoint=model_name,
821+
model_params={"generationConfig": {"temperature": 0.0}},
826822
)
827823

828-
transcribed_content_series = cast(
829-
bpd.Series, transcribed_results["ml_generate_text_llm_result"]
830-
).rename("transcribed_content")
824+
transcribed_content_series = transcribed_results.struct.field("result").rename(
825+
"transcribed_content"
826+
)
831827

832828
if verbose:
833-
transcribed_status_series = cast(
834-
bpd.Series, transcribed_results["ml_generate_text_status"]
835-
)
829+
transcribed_status_series = transcribed_results.struct.field("status")
836830
results_df = bpd.DataFrame(
837831
{
838832
"status": transcribed_status_series,

0 commit comments

Comments
 (0)