Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/assemblyai/files/types/uploaded_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ def initialize(upload_url:, additional_properties: nil)
# @return [AssemblyAI::Files::UploadedFile]
def self.from_json(json_object:)
struct = JSON.parse(json_object, object_class: OpenStruct)
upload_url = struct["upload_url"]
parsed_json = JSON.parse(json_object)
upload_url = parsed_json["upload_url"]
new(upload_url: upload_url, additional_properties: struct)
end

Expand Down
144 changes: 120 additions & 24 deletions lib/assemblyai/lemur/client.rb

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions lib/assemblyai/lemur/types/lemur_action_items_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ def initialize(response:, request_id:, usage:, additional_properties: nil)
def self.from_json(json_object:)
struct = JSON.parse(json_object, object_class: OpenStruct)
parsed_json = JSON.parse(json_object)
response = struct["response"]
request_id = struct["request_id"]
response = parsed_json["response"]
request_id = parsed_json["request_id"]
if parsed_json["usage"].nil?
usage = nil
else
Expand Down
10 changes: 5 additions & 5 deletions lib/assemblyai/lemur/types/lemur_base_params.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,17 @@ def initialize(transcript_ids: OMIT, input_text: OMIT, context: OMIT, final_mode
def self.from_json(json_object:)
struct = JSON.parse(json_object, object_class: OpenStruct)
parsed_json = JSON.parse(json_object)
transcript_ids = struct["transcript_ids"]
input_text = struct["input_text"]
transcript_ids = parsed_json["transcript_ids"]
input_text = parsed_json["input_text"]
if parsed_json["context"].nil?
context = nil
else
context = parsed_json["context"].to_json
context = AssemblyAI::Lemur::LemurBaseParamsContext.from_json(json_object: context)
end
final_model = struct["final_model"]
max_output_size = struct["max_output_size"]
temperature = struct["temperature"]
final_model = parsed_json["final_model"]
max_output_size = parsed_json["max_output_size"]
temperature = parsed_json["temperature"]
new(
transcript_ids: transcript_ids,
input_text: input_text,
Expand Down
4 changes: 2 additions & 2 deletions lib/assemblyai/lemur/types/lemur_base_params_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ def self.from_json(json_object:)
struct = JSON.parse(json_object, object_class: OpenStruct)
begin
struct.is_a?(String) != false || raise("Passed value for field struct is not the expected type, validation failed.")
return json_object unless json_object.nil?
return struct unless struct.nil?

return nil
rescue StandardError
# noop
end
begin
struct.is_a?(Hash) != false || raise("Passed value for field struct is not the expected type, validation failed.")
return json_object unless json_object.nil?
return struct unless struct.nil?

return nil
rescue StandardError
Expand Down
2 changes: 1 addition & 1 deletion lib/assemblyai/lemur/types/lemur_base_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def initialize(request_id:, usage:, additional_properties: nil)
def self.from_json(json_object:)
struct = JSON.parse(json_object, object_class: OpenStruct)
parsed_json = JSON.parse(json_object)
request_id = struct["request_id"]
request_id = parsed_json["request_id"]
if parsed_json["usage"].nil?
usage = nil
else
Expand Down
3 changes: 0 additions & 3 deletions lib/assemblyai/lemur/types/lemur_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ class LemurModel
ANTHROPIC_CLAUDE3_HAIKU = "anthropic/claude-3-haiku"
ANTHROPIC_CLAUDE3_SONNET = "anthropic/claude-3-sonnet"
ANTHROPIC_CLAUDE2_1 = "anthropic/claude-2-1"
ANTHROPIC_CLAUDE2 = "anthropic/claude-2"
ANTHROPIC_CLAUDE2_0 = "anthropic/claude-2"
DEFAULT = "default"
ANTHROPIC_CLAUDE_INSTANT1_2 = "anthropic/claude-instant-1-2"
BASIC = "basic"
ASSEMBLYAI_MISTRAL7B = "assemblyai/mistral-7b"
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/assemblyai/lemur/types/lemur_question.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ def initialize(question:, context: OMIT, answer_format: OMIT, answer_options: OM
def self.from_json(json_object:)
struct = JSON.parse(json_object, object_class: OpenStruct)
parsed_json = JSON.parse(json_object)
question = struct["question"]
question = parsed_json["question"]
if parsed_json["context"].nil?
context = nil
else
context = parsed_json["context"].to_json
context = AssemblyAI::Lemur::LemurQuestionContext.from_json(json_object: context)
end
answer_format = struct["answer_format"]
answer_options = struct["answer_options"]
answer_format = parsed_json["answer_format"]
answer_options = parsed_json["answer_options"]
new(
question: question,
context: context,
Expand Down
5 changes: 3 additions & 2 deletions lib/assemblyai/lemur/types/lemur_question_answer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ def initialize(question:, answer:, additional_properties: nil)
# @return [AssemblyAI::Lemur::LemurQuestionAnswer]
def self.from_json(json_object:)
struct = JSON.parse(json_object, object_class: OpenStruct)
question = struct["question"]
answer = struct["answer"]
parsed_json = JSON.parse(json_object)
question = parsed_json["question"]
answer = parsed_json["answer"]
new(
question: question,
answer: answer,
Expand Down
8 changes: 4 additions & 4 deletions lib/assemblyai/lemur/types/lemur_question_answer_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ def initialize(response:, request_id:, usage:, additional_properties: nil)
def self.from_json(json_object:)
struct = JSON.parse(json_object, object_class: OpenStruct)
parsed_json = JSON.parse(json_object)
response = parsed_json["response"]&.map do |v|
v = v.to_json
AssemblyAI::Lemur::LemurQuestionAnswer.from_json(json_object: v)
response = parsed_json["response"]&.map do |item|
item = item.to_json
AssemblyAI::Lemur::LemurQuestionAnswer.from_json(json_object: item)
end
request_id = struct["request_id"]
request_id = parsed_json["request_id"]
if parsed_json["usage"].nil?
usage = nil
else
Expand Down
4 changes: 2 additions & 2 deletions lib/assemblyai/lemur/types/lemur_question_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ def self.from_json(json_object:)
struct = JSON.parse(json_object, object_class: OpenStruct)
begin
struct.is_a?(String) != false || raise("Passed value for field struct is not the expected type, validation failed.")
return json_object unless json_object.nil?
return struct unless struct.nil?

return nil
rescue StandardError
# noop
end
begin
struct.is_a?(Hash) != false || raise("Passed value for field struct is not the expected type, validation failed.")
return json_object unless json_object.nil?
return struct unless struct.nil?

return nil
rescue StandardError
Expand Down
6 changes: 2 additions & 4 deletions lib/assemblyai/lemur/types/lemur_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,15 @@ def self.from_json(json_object:)
struct = JSON.parse(json_object, object_class: OpenStruct)
begin
AssemblyAI::Lemur::LemurStringResponse.validate_raw(obj: struct)
return AssemblyAI::Lemur::LemurStringResponse.from_json(json_object: json_object) unless json_object.nil?
return AssemblyAI::Lemur::LemurStringResponse.from_json(json_object: struct) unless struct.nil?

return nil
rescue StandardError
# noop
end
begin
AssemblyAI::Lemur::LemurQuestionAnswerResponse.validate_raw(obj: struct)
unless json_object.nil?
return AssemblyAI::Lemur::LemurQuestionAnswerResponse.from_json(json_object: json_object)
end
return AssemblyAI::Lemur::LemurQuestionAnswerResponse.from_json(json_object: struct) unless struct.nil?

return nil
rescue StandardError
Expand Down
4 changes: 2 additions & 2 deletions lib/assemblyai/lemur/types/lemur_string_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ def initialize(response:, request_id:, usage:, additional_properties: nil)
def self.from_json(json_object:)
struct = JSON.parse(json_object, object_class: OpenStruct)
parsed_json = JSON.parse(json_object)
response = struct["response"]
request_id = struct["request_id"]
response = parsed_json["response"]
request_id = parsed_json["request_id"]
if parsed_json["usage"].nil?
usage = nil
else
Expand Down
4 changes: 2 additions & 2 deletions lib/assemblyai/lemur/types/lemur_summary_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ def initialize(response:, request_id:, usage:, additional_properties: nil)
def self.from_json(json_object:)
struct = JSON.parse(json_object, object_class: OpenStruct)
parsed_json = JSON.parse(json_object)
response = struct["response"]
request_id = struct["request_id"]
response = parsed_json["response"]
request_id = parsed_json["request_id"]
if parsed_json["usage"].nil?
usage = nil
else
Expand Down
4 changes: 2 additions & 2 deletions lib/assemblyai/lemur/types/lemur_task_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ def initialize(response:, request_id:, usage:, additional_properties: nil)
def self.from_json(json_object:)
struct = JSON.parse(json_object, object_class: OpenStruct)
parsed_json = JSON.parse(json_object)
response = struct["response"]
request_id = struct["request_id"]
response = parsed_json["response"]
request_id = parsed_json["request_id"]
if parsed_json["usage"].nil?
usage = nil
else
Expand Down
5 changes: 3 additions & 2 deletions lib/assemblyai/lemur/types/lemur_usage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ def initialize(input_tokens:, output_tokens:, additional_properties: nil)
# @return [AssemblyAI::Lemur::LemurUsage]
def self.from_json(json_object:)
struct = JSON.parse(json_object, object_class: OpenStruct)
input_tokens = struct["input_tokens"]
output_tokens = struct["output_tokens"]
parsed_json = JSON.parse(json_object)
input_tokens = parsed_json["input_tokens"]
output_tokens = parsed_json["output_tokens"]
new(
input_tokens: input_tokens,
output_tokens: output_tokens,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ def initialize(request_id:, request_id_to_purge:, deleted:, additional_propertie
# @return [AssemblyAI::Lemur::PurgeLemurRequestDataResponse]
def self.from_json(json_object:)
struct = JSON.parse(json_object, object_class: OpenStruct)
request_id = struct["request_id"]
request_id_to_purge = struct["request_id_to_purge"]
deleted = struct["deleted"]
parsed_json = JSON.parse(json_object)
request_id = parsed_json["request_id"]
request_id_to_purge = parsed_json["request_id_to_purge"]
deleted = parsed_json["deleted"]
new(
request_id: request_id,
request_id_to_purge: request_id_to_purge,
Expand Down
22 changes: 18 additions & 4 deletions lib/assemblyai/realtime/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,23 @@ def initialize(request_client:)
# @return [AssemblyAI::Realtime::RealtimeTemporaryTokenResponse]
# @example
# api = AssemblyAI::Client.new(
# environment: AssemblyAI::Environment::DEFAULT,
# base_url: "https://api.example.com",
# environment: AssemblyAI::Environment::DEFAULT,
# api_key: "YOUR_API_KEY"
# )
# api.realtime.create_temporary_token(expires_in: 480)
def create_temporary_token(expires_in:, request_options: nil)
response = @request_client.conn.post 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?
req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
req.headers = {
**(req.headers || {}),
**@request_client.get_headers,
**(request_options&.additional_headers || {})
}.compact
unless request_options.nil? || request_options&.additional_query_parameters.nil?
req.params = { **(request_options&.additional_query_parameters || {}) }.compact
end
req.body = { **(request_options&.additional_body_parameters || {}), expires_in: expires_in }.compact
req.url "#{@request_client.get_url(request_options: request_options)}/v2/realtime/token"
end
Expand All @@ -56,8 +63,8 @@ def initialize(request_client:)
# @return [AssemblyAI::Realtime::RealtimeTemporaryTokenResponse]
# @example
# api = AssemblyAI::Client.new(
# environment: AssemblyAI::Environment::DEFAULT,
# base_url: "https://api.example.com",
# environment: AssemblyAI::Environment::DEFAULT,
# api_key: "YOUR_API_KEY"
# )
# api.realtime.create_temporary_token(expires_in: 480)
Expand All @@ -66,7 +73,14 @@ def create_temporary_token(expires_in:, request_options: nil)
response = @request_client.conn.post 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?
req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
req.headers = {
**(req.headers || {}),
**@request_client.get_headers,
**(request_options&.additional_headers || {})
}.compact
unless request_options.nil? || request_options&.additional_query_parameters.nil?
req.params = { **(request_options&.additional_query_parameters || {}) }.compact
end
req.body = { **(request_options&.additional_body_parameters || {}), expires_in: expires_in }.compact
req.url "#{@request_client.get_url(request_options: request_options)}/v2/realtime/token"
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def initialize(end_utterance_silence_threshold:, additional_properties: nil)
# @return [AssemblyAI::Realtime::ConfigureEndUtteranceSilenceThreshold]
def self.from_json(json_object:)
struct = JSON.parse(json_object, object_class: OpenStruct)
end_utterance_silence_threshold = struct["end_utterance_silence_threshold"]
parsed_json = JSON.parse(json_object)
end_utterance_silence_threshold = parsed_json["end_utterance_silence_threshold"]
new(end_utterance_silence_threshold: end_utterance_silence_threshold, additional_properties: struct)
end

Expand Down
20 changes: 10 additions & 10 deletions lib/assemblyai/realtime/types/final_transcript.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,16 @@ def initialize(message_type:, punctuated:, text_formatted:, audio_start:, audio_
def self.from_json(json_object:)
struct = JSON.parse(json_object, object_class: OpenStruct)
parsed_json = JSON.parse(json_object)
message_type = struct["message_type"]
punctuated = struct["punctuated"]
text_formatted = struct["text_formatted"]
audio_start = struct["audio_start"]
audio_end = struct["audio_end"]
confidence = struct["confidence"]
text = struct["text"]
words = parsed_json["words"]&.map do |v|
v = v.to_json
AssemblyAI::Realtime::Word.from_json(json_object: v)
message_type = parsed_json["message_type"]
punctuated = parsed_json["punctuated"]
text_formatted = parsed_json["text_formatted"]
audio_start = parsed_json["audio_start"]
audio_end = parsed_json["audio_end"]
confidence = parsed_json["confidence"]
text = parsed_json["text"]
words = parsed_json["words"]&.map do |item|
item = item.to_json
AssemblyAI::Realtime::Word.from_json(json_object: item)
end
created = (DateTime.parse(parsed_json["created"]) unless parsed_json["created"].nil?)
new(
Expand Down
3 changes: 2 additions & 1 deletion lib/assemblyai/realtime/types/force_end_utterance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ def initialize(force_end_utterance:, additional_properties: nil)
# @return [AssemblyAI::Realtime::ForceEndUtterance]
def self.from_json(json_object:)
struct = JSON.parse(json_object, object_class: OpenStruct)
force_end_utterance = struct["force_end_utterance"]
parsed_json = JSON.parse(json_object)
force_end_utterance = parsed_json["force_end_utterance"]
new(force_end_utterance: force_end_utterance, additional_properties: struct)
end

Expand Down
16 changes: 8 additions & 8 deletions lib/assemblyai/realtime/types/partial_transcript.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ def initialize(message_type:, audio_start:, audio_end:, confidence:, text:, word
def self.from_json(json_object:)
struct = JSON.parse(json_object, object_class: OpenStruct)
parsed_json = JSON.parse(json_object)
message_type = struct["message_type"]
audio_start = struct["audio_start"]
audio_end = struct["audio_end"]
confidence = struct["confidence"]
text = struct["text"]
words = parsed_json["words"]&.map do |v|
v = v.to_json
AssemblyAI::Realtime::Word.from_json(json_object: v)
message_type = parsed_json["message_type"]
audio_start = parsed_json["audio_start"]
audio_end = parsed_json["audio_end"]
confidence = parsed_json["confidence"]
text = parsed_json["text"]
words = parsed_json["words"]&.map do |item|
item = item.to_json
AssemblyAI::Realtime::Word.from_json(json_object: item)
end
created = (DateTime.parse(parsed_json["created"]) unless parsed_json["created"].nil?)
new(
Expand Down
3 changes: 2 additions & 1 deletion lib/assemblyai/realtime/types/realtime_base_message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ def initialize(message_type:, additional_properties: nil)
# @return [AssemblyAI::Realtime::RealtimeBaseMessage]
def self.from_json(json_object:)
struct = JSON.parse(json_object, object_class: OpenStruct)
message_type = struct["message_type"]
parsed_json = JSON.parse(json_object)
message_type = parsed_json["message_type"]
new(message_type: message_type, additional_properties: struct)
end

Expand Down
14 changes: 7 additions & 7 deletions lib/assemblyai/realtime/types/realtime_base_transcript.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ def initialize(audio_start:, audio_end:, confidence:, text:, words:, created:, a
def self.from_json(json_object:)
struct = JSON.parse(json_object, object_class: OpenStruct)
parsed_json = JSON.parse(json_object)
audio_start = struct["audio_start"]
audio_end = struct["audio_end"]
confidence = struct["confidence"]
text = struct["text"]
words = parsed_json["words"]&.map do |v|
v = v.to_json
AssemblyAI::Realtime::Word.from_json(json_object: v)
audio_start = parsed_json["audio_start"]
audio_end = parsed_json["audio_end"]
confidence = parsed_json["confidence"]
text = parsed_json["text"]
words = parsed_json["words"]&.map do |item|
item = item.to_json
AssemblyAI::Realtime::Word.from_json(json_object: item)
end
created = (DateTime.parse(parsed_json["created"]) unless parsed_json["created"].nil?)
new(
Expand Down
3 changes: 2 additions & 1 deletion lib/assemblyai/realtime/types/realtime_error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ def initialize(error:, additional_properties: nil)
# @return [AssemblyAI::Realtime::RealtimeError]
def self.from_json(json_object:)
struct = JSON.parse(json_object, object_class: OpenStruct)
error = struct["error"]
parsed_json = JSON.parse(json_object)
error = parsed_json["error"]
new(error: error, additional_properties: struct)
end

Expand Down
Loading
Loading