Class: LlmCostTracker::Parsers::OpenaiCompatible
- Includes:
- OpenaiUsage
- Defined in:
- lib/llm_cost_tracker/parsers/openai_compatible.rb
Constant Summary collapse
- TRACKED_PATH_SUFFIXES =
%w[/chat/completions /completions /embeddings /responses].freeze
Constants included from OpenaiServiceCharges
LlmCostTracker::Parsers::OpenaiServiceCharges::CHAT_COMPLETIONS_ANNOTATION_PROVIDER_FIELD, LlmCostTracker::Parsers::OpenaiServiceCharges::CHAT_COMPLETIONS_SEARCH_MODEL_PROVIDER_FIELD, LlmCostTracker::Parsers::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?, #model_for, #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
14 15 16 |
# File 'lib/llm_cost_tracker/parsers/openai_compatible.rb', line 14 def match?(url) match_uri?(url, path_suffixes: TRACKED_PATH_SUFFIXES) { |uri| provider_for_uri(uri) } end |
.provider_for(request_url) ⇒ Object
33 34 35 |
# File 'lib/llm_cost_tracker/parsers/openai_compatible.rb', line 33 def provider_for(request_url) provider_for_uri(parsed_uri(request_url)) || "openai_compatible" end |
.provider_names ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/llm_cost_tracker/parsers/openai_compatible.rb', line 18 def provider_names providers = LlmCostTracker.configuration.openai_compatible_providers cached = @provider_names return cached if cached && @provider_names_providers.equal?(providers) names = [ "openai_compatible", *providers.each_value.map { |provider| provider.to_s.downcase } ].uniq.freeze return names unless providers.frozen? @provider_names_providers = providers @provider_names = names end |
Instance Method Details
#provider_for(request_url) ⇒ Object
46 47 48 |
# File 'lib/llm_cost_tracker/parsers/openai_compatible.rb', line 46 def provider_for(request_url) self.class.provider_for(request_url) end |