Class: LlmCostTracker::Parsers::Azure
- Includes:
- OpenaiUsage
- Defined in:
- lib/llm_cost_tracker/parsers/azure.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 OpenaiServiceCharges
OpenaiServiceCharges::CHAT_COMPLETIONS_ANNOTATION_PROVIDER_FIELD, OpenaiServiceCharges::CHAT_COMPLETIONS_SEARCH_MODEL_PROVIDER_FIELD, OpenaiServiceCharges::RESPONSE_OUTPUT_COMPONENTS
Class Method Summary collapse
Instance Method Summary collapse
Methods included from OpenaiUsage
#auto_enable_stream_usage?, combined_pricing_mode, #parse, #parse_stream, regional_processing?
Methods included from OpenaiServiceCharges
billable?, build_line_item, chat_completions_search_model?, chat_completions_search_provider_field, chat_completions_used_web_search?, chat_completions_web_search_items, component_key_for, line_item_details, line_items_from_output, openai_stream_service_line_items, reasoning_model?, service_line_items_for, store_output_item, web_search_preview_used?
Methods inherited from Base
#auto_enable_stream_usage?, #parse, #parse_stream, #safe_json_parse, #streaming_request?
Methods included from UrlMatchers
#match_uri?, #parsed_uri, #path_matches?, #uri_matches?
Class Method Details
.match?(url) ⇒ Boolean
21 22 23 24 25 |
# File 'lib/llm_cost_tracker/parsers/azure.rb', line 21 def match?(url) uri_matches?(url) do |uri| LlmCostTracker::Providers::Azure::Hosts.openai?(uri.host) && uri.path.to_s.match?(PATH_PATTERN) end end |
.provider_names ⇒ Object
27 28 29 |
# File 'lib/llm_cost_tracker/parsers/azure.rb', line 27 def provider_names %w[azure_openai] end |
Instance Method Details
#model_for(request_url, request_parsed) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/llm_cost_tracker/parsers/azure.rb', line 36 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
32 33 34 |
# File 'lib/llm_cost_tracker/parsers/azure.rb', line 32 def provider_for(_request_url) "azure_openai" end |