Class: LlmCostTracker::Providers::Azure::Parser

Inherits:
LlmCostTracker::Parsers::Base show all
Includes:
Openai::ResponseParser
Defined in:
lib/llm_cost_tracker/providers/azure/parser.rb

Constant Summary collapse

TRACKED_ENDPOINTS =
%w[
  chat/completions completions embeddings moderations responses
  audio/transcriptions audio/translations audio/speech
  images/generations images/edits images/variations
].freeze
PATH_PATTERN =
%r{\A/openai/(?:deployments/[^/]+|v1)/(?:#{TRACKED_ENDPOINTS.join('|')})\z}

Constants included from Openai::ServiceCharges

Openai::ServiceCharges::CHAT_COMPLETIONS_ANNOTATION_PROVIDER_FIELD, Openai::ServiceCharges::CHAT_COMPLETIONS_SEARCH_MODEL_PROVIDER_FIELD, Openai::ServiceCharges::RESPONSE_OUTPUT_RENAMES

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Openai::ResponseParser

#auto_enable_stream_usage?, combined_pricing_mode, event_from_response, #parse, #parse_stream

Methods included from Openai::ServiceCharges

billable?, build_line_item, chat_completions_search_model?, chat_completions_search_provider_field, chat_completions_used_web_search?, chat_completions_web_search_items, dimension_key_for, line_item_details, line_items_from_output, local_model_name, openai_stream_service_line_items, output_dimension, reasoning_model?, service_line_items_for, store_output_item, transcription_line_items, web_search_preview_used?

Methods inherited from LlmCostTracker::Parsers::Base

#auto_enable_stream_usage?, #parse, #parse_stream, #safe_json_parse, #streaming_request?

Methods included from LlmCostTracker::Parsers::UrlMatchers

#match_uri?, #parsed_uri, #path_matches?, #uri_matches?

Class Method Details

.match?(url) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
21
22
# File 'lib/llm_cost_tracker/providers/azure/parser.rb', line 18

def match?(url)
  uri_matches?(url) do |uri|
    Hosts.openai?(uri.host) && uri.path.to_s.match?(PATH_PATTERN)
  end
end

.provider_namesObject



24
25
26
# File 'lib/llm_cost_tracker/providers/azure/parser.rb', line 24

def provider_names
  %w[azure_openai]
end

Instance Method Details

#model_for(request_url, request_parsed) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/llm_cost_tracker/providers/azure/parser.rb', line 33

def model_for(request_url, request_parsed)
  body_model = super
  return body_model if body_model

  uri = parsed_uri(request_url)
  match = uri&.path&.match(%r{/openai/deployments/([^/]+)/})
  match && match[1]
end

#provider_for(_request_url) ⇒ Object



29
30
31
# File 'lib/llm_cost_tracker/providers/azure/parser.rb', line 29

def provider_for(_request_url)
  "azure_openai"
end