Skip to content

Commit

Permalink
Merge pull request #18 from AssemblyAI/fern/updatecustompolling
Browse files Browse the repository at this point in the history
  • Loading branch information
armandobelardo committed Mar 3, 2024
2 parents 8ba4e97 + 4f2e117 commit 02d6028
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 34 deletions.
10 changes: 2 additions & 8 deletions lib/assemblyai/transcripts/list_by_url_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
require "async"

module AssemblyAI

# :nodoc:
class TranscriptsClient
# Retrieve a list of transcripts you created, this is used for pagination to easily retrieve the next page of transcripts
Expand All @@ -19,9 +18,7 @@ class TranscriptsClient
# transcript_list = client.transcripts.list(limit: 1)
# client.transcripts.list_by_url(url: transcript_list.page_details.next_url)
def list_by_url(url: nil, request_options: nil)
if url.nil?
url = "/v2/transcript"
end
url = "/v2/transcript" if url.nil?
response = @request_client.conn.get(url) do |req|
req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
req.headers["Authorization"] = request_options.api_key unless request_options&.api_key.nil?
Expand All @@ -33,7 +30,6 @@ def list_by_url(url: nil, request_options: nil)

# :nodoc:
class AsyncTranscriptsClient

# Retrieve a list of transcripts you created
#
# @param url [String] The URL to retrieve the transcript list from
Expand All @@ -48,9 +44,7 @@ class AsyncTranscriptsClient
# end
def list_by_url(url: nil, request_options: nil)
Async do
if url.nil?
url = "/v2/transcript"
end
url = "/v2/transcript" if url.nil?
response = @request_client.conn.get(url) do |req|
req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
req.headers["Authorization"] = request_options.api_key unless request_options&.api_key.nil?
Expand Down
16 changes: 8 additions & 8 deletions lib/assemblyai/transcripts/polling_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ class TranscriptsClient
# @param request_options [RequestOptions]
# @param polling_options [Transcripts::PollingOptions] Configuration options for polling requests.
# @return [Transcripts::Transcript]
def transcribe(audio_url:, language_code: nil, punctuate: nil, format_text: nil, dual_channel: nil, webhook_url: nil,
webhook_auth_header_name: nil, webhook_auth_header_value: nil, auto_highlights: nil, audio_start_from: nil, audio_end_at: nil, word_boost: nil, boost_param: nil, filter_profanity: nil, redact_pii: nil, redact_pii_audio: nil, redact_pii_audio_quality: nil, redact_pii_policies: nil, redact_pii_sub: nil, speaker_labels: nil, speakers_expected: nil, content_safety: nil, content_safety_confidence: nil, iab_categories: nil, language_detection: nil, custom_spelling: nil, disfluencies: nil, sentiment_analysis: nil, auto_chapters: nil, entity_detection: nil, speech_threshold: nil, summarization: nil, summary_model: nil, summary_type: nil, custom_topics: nil, topics: nil, additional_properties: nil, request_options: nil, polling_options: Transcripts::PollingOptions.new)
transcript = submit(audio_url: audio_url, language_code: language_code, punctuate: punctuate, format_text: format_text, dual_channel: dual_channel, webhook_url: webhook_url,
webhook_auth_header_name: webhook_auth_header_name, webhook_auth_header_value: webhook_auth_header_value, auto_highlights: auto_highlights, audio_start_from: audio_start_from, audio_end_at: audio_end_at, word_boost: word_boost, boost_param: boost_param, filter_profanity: filter_profanity, redact_pii: redact_pii, redact_pii_audio: redact_pii_audio, redact_pii_audio_quality: redact_pii_audio_quality, redact_pii_policies: redact_pii_policies, redact_pii_sub: redact_pii_sub, speaker_labels: speaker_labels, speakers_expected: speakers_expected, content_safety: content_safety, content_safety_confidence: content_safety_confidence, iab_categories: iab_categories, language_detection: language_detection, custom_spelling: custom_spelling, disfluencies: disfluencies, sentiment_analysis: sentiment_analysis, auto_chapters: auto_chapters, entity_detection: entity_detection, speech_threshold: speech_threshold, summarization: summarization, summary_model: summary_model, summary_type: summary_type, custom_topics: custom_topics, topics: topics, additional_properties: additional_properties, request_options: request_options)
def transcribe(audio_url:, speech_model: nil, language_code: nil, punctuate: nil, format_text: nil, dual_channel: nil,
webhook_url: nil, webhook_auth_header_name: nil, webhook_auth_header_value: nil, auto_highlights: nil, audio_start_from: nil, audio_end_at: nil, word_boost: nil, boost_param: nil, filter_profanity: nil, redact_pii: nil, redact_pii_audio: nil, redact_pii_audio_quality: nil, redact_pii_policies: nil, redact_pii_sub: nil, speaker_labels: nil, speakers_expected: nil, content_safety: nil, content_safety_confidence: nil, iab_categories: nil, language_detection: nil, custom_spelling: nil, disfluencies: nil, sentiment_analysis: nil, auto_chapters: nil, entity_detection: nil, speech_threshold: nil, summarization: nil, summary_model: nil, summary_type: nil, custom_topics: nil, topics: nil, additional_properties: nil, request_options: nil, polling_options: Transcripts::PollingOptions.new)
transcript = submit(audio_url: audio_url, speech_model: speech_model, language_code: language_code, punctuate: punctuate, format_text: format_text, dual_channel: dual_channel,
webhook_url: webhook_url, webhook_auth_header_name: webhook_auth_header_name, webhook_auth_header_value: webhook_auth_header_value, auto_highlights: auto_highlights, audio_start_from: audio_start_from, audio_end_at: audio_end_at, word_boost: word_boost, boost_param: boost_param, filter_profanity: filter_profanity, redact_pii: redact_pii, redact_pii_audio: redact_pii_audio, redact_pii_audio_quality: redact_pii_audio_quality, redact_pii_policies: redact_pii_policies, redact_pii_sub: redact_pii_sub, speaker_labels: speaker_labels, speakers_expected: speakers_expected, content_safety: content_safety, content_safety_confidence: content_safety_confidence, iab_categories: iab_categories, language_detection: language_detection, custom_spelling: custom_spelling, disfluencies: disfluencies, sentiment_analysis: sentiment_analysis, auto_chapters: auto_chapters, entity_detection: entity_detection, speech_threshold: speech_threshold, summarization: summarization, summary_model: summary_model, summary_type: summary_type, custom_topics: custom_topics, topics: topics, additional_properties: additional_properties, request_options: request_options)
poll_transcript(transcript_id: transcript.id, polling_options: polling_options)
end

Expand Down Expand Up @@ -144,11 +144,11 @@ class AsyncTranscriptsClient
# @param request_options [RequestOptions]
# @param polling_options [Transcripts::PollingOptions] Configuration options for polling requests.
# @return [Transcripts::Transcript]
def transcribe(audio_url:, language_code: nil, punctuate: nil, format_text: nil, dual_channel: nil, webhook_url: nil,
webhook_auth_header_name: nil, webhook_auth_header_value: nil, auto_highlights: nil, audio_start_from: nil, audio_end_at: nil, word_boost: nil, boost_param: nil, filter_profanity: nil, redact_pii: nil, redact_pii_audio: nil, redact_pii_audio_quality: nil, redact_pii_policies: nil, redact_pii_sub: nil, speaker_labels: nil, speakers_expected: nil, content_safety: nil, content_safety_confidence: nil, iab_categories: nil, language_detection: nil, custom_spelling: nil, disfluencies: nil, sentiment_analysis: nil, auto_chapters: nil, entity_detection: nil, speech_threshold: nil, summarization: nil, summary_model: nil, summary_type: nil, custom_topics: nil, topics: nil, additional_properties: nil, request_options: nil, polling_options: Transcripts::PollingOptions.new)
def transcribe(audio_url:, speech_model: nil, language_code: nil, punctuate: nil, format_text: nil, dual_channel: nil,
webhook_url: nil, webhook_auth_header_name: nil, webhook_auth_header_value: nil, auto_highlights: nil, audio_start_from: nil, audio_end_at: nil, word_boost: nil, boost_param: nil, filter_profanity: nil, redact_pii: nil, redact_pii_audio: nil, redact_pii_audio_quality: nil, redact_pii_policies: nil, redact_pii_sub: nil, speaker_labels: nil, speakers_expected: nil, content_safety: nil, content_safety_confidence: nil, iab_categories: nil, language_detection: nil, custom_spelling: nil, disfluencies: nil, sentiment_analysis: nil, auto_chapters: nil, entity_detection: nil, speech_threshold: nil, summarization: nil, summary_model: nil, summary_type: nil, custom_topics: nil, topics: nil, additional_properties: nil, request_options: nil, polling_options: Transcripts::PollingOptions.new)
Async do
transcript = submit(audio_url: audio_url, language_code: language_code, punctuate: punctuate, format_text: format_text, dual_channel: dual_channel, webhook_url: webhook_url,
webhook_auth_header_name: webhook_auth_header_name, webhook_auth_header_value: webhook_auth_header_value, auto_highlights: auto_highlights, audio_start_from: audio_start_from, audio_end_at: audio_end_at, word_boost: word_boost, boost_param: boost_param, filter_profanity: filter_profanity, redact_pii: redact_pii, redact_pii_audio: redact_pii_audio, redact_pii_audio_quality: redact_pii_audio_quality, redact_pii_policies: redact_pii_policies, redact_pii_sub: redact_pii_sub, speaker_labels: speaker_labels, speakers_expected: speakers_expected, content_safety: content_safety, content_safety_confidence: content_safety_confidence, iab_categories: iab_categories, language_detection: language_detection, custom_spelling: custom_spelling, disfluencies: disfluencies, sentiment_analysis: sentiment_analysis, auto_chapters: auto_chapters, entity_detection: entity_detection, speech_threshold: speech_threshold, summarization: summarization, summary_model: summary_model, summary_type: summary_type, custom_topics: custom_topics, topics: topics, additional_properties: additional_properties, request_options: request_options).wait
transcript = submit(audio_url: audio_url, speech_model: speech_model, language_code: language_code, punctuate: punctuate, format_text: format_text, dual_channel: dual_channel,
webhook_url: webhook_url, webhook_auth_header_name: webhook_auth_header_name, webhook_auth_header_value: webhook_auth_header_value, auto_highlights: auto_highlights, audio_start_from: audio_start_from, audio_end_at: audio_end_at, word_boost: word_boost, boost_param: boost_param, filter_profanity: filter_profanity, redact_pii: redact_pii, redact_pii_audio: redact_pii_audio, redact_pii_audio_quality: redact_pii_audio_quality, redact_pii_policies: redact_pii_policies, redact_pii_sub: redact_pii_sub, speaker_labels: speaker_labels, speakers_expected: speakers_expected, content_safety: content_safety, content_safety_confidence: content_safety_confidence, iab_categories: iab_categories, language_detection: language_detection, custom_spelling: custom_spelling, disfluencies: disfluencies, sentiment_analysis: sentiment_analysis, auto_chapters: auto_chapters, entity_detection: entity_detection, speech_threshold: speech_threshold, summarization: summarization, summary_model: summary_model, summary_type: summary_type, custom_topics: custom_topics, topics: topics, additional_properties: additional_properties, request_options: request_options).wait
poll_transcript(transcript_id: transcript.id, polling_options: polling_options).wait
end
end
Expand Down
29 changes: 14 additions & 15 deletions lib/assemblyai/transcripts/types/polling_options.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
# frozen_string_literal: true

module AssemblyAI
class Transcripts
# Configuration options for polling requests.
class PollingOptions
attr_reader :interval, :timeout

# @param interval [Integer] The amount of time to wait between polling requests, in milliseconds. Defaults to 3000.
# @param timeout [Integer] The maximum amount of time to wait for the transcript to be ready, in milliseconds. Defaults to -1, which means poll forever.
# @return [Transcripts::PollingOptions]
def initialize(interval: 3000, timeout: -1)
# @type [Integer] The amount of time to wait between polling requests, in milliseconds.
@interval = interval
# @type [Integer] The maximum amount of time to wait for the transcript to be ready, in milliseconds.
@timeout = timeout
end
class Transcripts
# Configuration options for polling requests.
class PollingOptions
attr_reader :interval, :timeout

# @param interval [Integer] The amount of time to wait between polling requests, in milliseconds. Defaults to 3000.
# @param timeout [Integer] The maximum amount of time to wait for the transcript to be ready, in milliseconds. Defaults to -1, which means poll forever.
# @return [Transcripts::PollingOptions]
def initialize(interval: 3000, timeout: -1)
# @type [Integer] The amount of time to wait between polling requests, in milliseconds.
@interval = interval
# @type [Integer] The maximum amount of time to wait for the transcript to be ready, in milliseconds.
@timeout = timeout
end
end
end
end
10 changes: 7 additions & 3 deletions test/test_assemblyai.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_pagination

while transcript_list.page_details.next_url
transcript_list = client.transcripts.list_by_url(url: transcript_list.page_details.next_url)

count = 0
client.transcripts.list.transcripts.each do |transcript|
assert !transcript.id.nil?
Expand Down Expand Up @@ -63,8 +63,12 @@ def test_lemur
client = AssemblyAI::Client.new(api_key: "YOUR API KEY")
assert !client.lemur.summary(transcript_ids: ["369849ed-b5a1-4add-9dde-ac936d3e7b99"]).response.nil?

assert !client.lemur.question_answer(transcript_ids: ["369849ed-b5a1-4add-9dde-ac936d3e7b99"], questions: [{question: "What are they discussing?", answer_format: "text"}]).response.nil?
assert !client.lemur.question_answer(transcript_ids: ["369849ed-b5a1-4add-9dde-ac936d3e7b99"],
questions: [{
question: "What are they discussing?", answer_format: "text"
}]).response.nil?

assert !client.lemur.task(transcript_ids: ["369849ed-b5a1-4add-9dde-ac936d3e7b99"], prompt: "Write a haiku about this conversation").response.nil?
assert !client.lemur.task(transcript_ids: ["369849ed-b5a1-4add-9dde-ac936d3e7b99"],
prompt: "Write a haiku about this conversation").response.nil?
end
end

0 comments on commit 02d6028

Please sign in to comment.