diff --git a/Gemfile b/Gemfile index 1ae6cf093..e3868cba7 100644 --- a/Gemfile +++ b/Gemfile @@ -191,10 +191,10 @@ gem 'reverse_markdown' gem 'iso-639' gem 'ruby-openai' -gem 'ai-agents', '>= 0.7.0' +gem 'ai-agents', '>= 0.8.0' # TODO: Move this gem as a dependency of ai-agents -gem 'ruby_llm', '>= 1.8.2' +gem 'ruby_llm', '>= 1.9.1' gem 'ruby_llm-schema' # OpenTelemetry for LLM observability diff --git a/Gemfile.lock b/Gemfile.lock index 0a669b606..38b74c39f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -126,8 +126,8 @@ GEM jbuilder (~> 2) rails (>= 4.2, < 7.2) selectize-rails (~> 0.6) - ai-agents (0.7.0) - ruby_llm (~> 1.8.2) + ai-agents (0.8.0) + ruby_llm (~> 1.9.1) annotaterb (4.20.0) activerecord (>= 6.0.0) activesupport (>= 6.0.0) @@ -297,7 +297,7 @@ GEM railties (>= 5.0.0) faker (3.2.0) i18n (>= 1.8.11, < 2) - faraday (2.13.1) + faraday (2.14.0) faraday-net_http (>= 2.0, < 3.5) json logger @@ -306,14 +306,14 @@ GEM faraday-mashify (1.0.0) faraday (~> 2.0) hashie - faraday-multipart (1.0.4) - multipart-post (~> 2) - faraday-net_http (3.4.0) - net-http (>= 0.5.0) + faraday-multipart (1.2.0) + multipart-post (~> 2.0) + faraday-net_http (3.4.2) + net-http (~> 0.5) faraday-net_http_persistent (2.1.0) faraday (~> 2.5) net-http-persistent (~> 4.0) - faraday-retry (2.2.1) + faraday-retry (2.4.0) faraday (~> 2.0) faraday_middleware-aws-sigv4 (1.0.1) aws-sigv4 (~> 1.0) @@ -463,7 +463,7 @@ GEM rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) - json (2.13.2) + json (2.18.0) json_refs (0.1.8) hana json_schemer (0.2.24) @@ -538,7 +538,7 @@ GEM net-imap net-pop net-smtp - marcel (1.0.4) + marcel (1.1.0) maxminddb (0.1.22) meta_request (0.8.3) rack-contrib (>= 1.1, < 3) @@ -556,12 +556,12 @@ GEM msgpack (1.8.0) multi_json (1.15.0) multi_xml (0.6.0) - multipart-post (2.3.0) + multipart-post (2.4.1) mutex_m (0.3.0) neighbor (0.2.3) activerecord (>= 5.2) - net-http (0.6.0) - uri + net-http (0.9.1) + uri (>= 0.11.1) net-http-persistent (4.0.2) connection_pool (~> 2.2) net-imap (0.4.20) @@ -822,7 +822,7 @@ GEM ruby2ruby (2.5.0) ruby_parser (~> 3.1) sexp_processor (~> 4.6) - ruby_llm (1.8.2) + ruby_llm (1.9.1) base64 event_stream_parser (~> 1) faraday (>= 1.10.0) @@ -966,7 +966,7 @@ GEM unicode-emoji (~> 4.0, >= 4.0.4) unicode-emoji (4.0.4) uniform_notifier (1.17.0) - uri (1.0.4) + uri (1.1.1) uri_template (0.7.0) valid_email2 (5.2.6) activemodel (>= 3.2) @@ -1001,7 +1001,7 @@ GEM working_hours (1.4.1) activesupport (>= 3.2) tzinfo - zeitwerk (2.6.17) + zeitwerk (2.7.4) PLATFORMS arm64-darwin-20 @@ -1021,7 +1021,7 @@ DEPENDENCIES administrate (>= 0.20.1) administrate-field-active_storage (>= 1.0.3) administrate-field-belongs_to_search (>= 0.9.0) - ai-agents (>= 0.7.0) + ai-agents (>= 0.8.0) annotaterb attr_extras audited (~> 5.4, >= 5.4.1) @@ -1123,7 +1123,7 @@ DEPENDENCIES rubocop-rails rubocop-rspec ruby-openai - ruby_llm (>= 1.8.2) + ruby_llm (>= 1.9.1) ruby_llm-schema scout_apm scss_lint diff --git a/enterprise/app/services/messages/audio_transcription_service.rb b/enterprise/app/services/messages/audio_transcription_service.rb index 1676dd862..95d33445f 100644 --- a/enterprise/app/services/messages/audio_transcription_service.rb +++ b/enterprise/app/services/messages/audio_transcription_service.rb @@ -1,4 +1,4 @@ -class Messages::AudioTranscriptionService< Llm::LegacyBaseOpenAiService +class Messages::AudioTranscriptionService include Integrations::LlmInstrumentation WHISPER_MODEL = 'whisper-1'.freeze @@ -6,7 +6,7 @@ class Messages::AudioTranscriptionService< Llm::LegacyBaseOpenAiService attr_reader :attachment, :message, :account def initialize(attachment) - super() + Llm::Config.initialize! @attachment = attachment @message = attachment.message @account = message.account @@ -50,23 +50,18 @@ class Messages::AudioTranscriptionService< Llm::LegacyBaseOpenAiService temp_file_path = fetch_audio_file - transcribed_text = nil - - File.open(temp_file_path, 'rb') do |file| - response = @client.audio.transcribe( - parameters: { - model: 'whisper-1', - file: file, - temperature: 0.4 - } - ) - transcribed_text = response['text'] + transcription = instrument_audio_transcription(instrumentation_params(temp_file_path)) do + RubyLLM.transcribe(temp_file_path, model: WHISPER_MODEL) end FileUtils.rm_f(temp_file_path) - update_transcription(transcribed_text) - transcribed_text + update_transcription(transcription.text) + transcription.text + rescue RubyLLM::Error => e + FileUtils.rm_f(temp_file_path) if temp_file_path + Rails.logger.error "Audio transcription error: #{e.message}" + raise end def instrumentation_params(file_path) @@ -74,6 +69,7 @@ class Messages::AudioTranscriptionService< Llm::LegacyBaseOpenAiService span_name: 'llm.messages.audio_transcription', model: WHISPER_MODEL, account_id: account&.id, + conversation_id: message.conversation&.display_id, feature_name: 'audio_transcription', file_path: file_path }