Class: LlmCostTracker::Providers::OpenaiCompatible::Parser
- Inherits:
-
LlmCostTracker::Parsers::Base
- Object
- LlmCostTracker::Parsers::Base
- LlmCostTracker::Providers::OpenaiCompatible::Parser
- Defined in:
- lib/llm_cost_tracker/providers/openai_compatible/parser.rb
Constant Summary collapse
- TRACKED_PATH_SUFFIXES =
%w[/chat/completions /completions /embeddings /responses].freeze
Constants included from LlmCostTracker::Providers::Openai::ServiceCharges
LlmCostTracker::Providers::Openai::ServiceCharges::CHAT_COMPLETIONS_ANNOTATION_PROVIDER_FIELD, LlmCostTracker::Providers::Openai::ServiceCharges::CHAT_COMPLETIONS_SEARCH_MODEL_PROVIDER_FIELD, LlmCostTracker::Providers::Openai::ServiceCharges::RESPONSE_OUTPUT_RENAMES
Class Method Summary collapse
Instance Method Summary collapse
Methods included from LlmCostTracker::Providers::Openai::ResponseParser
#auto_enable_stream_usage?, combined_pricing_mode, event_from_response, #parse, #parse_stream
Methods included from LlmCostTracker::Providers::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?, #model_for, #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
12 13 14 |
# File 'lib/llm_cost_tracker/providers/openai_compatible/parser.rb', line 12 def match?(url) match_uri?(url, path_suffixes: TRACKED_PATH_SUFFIXES) { |uri| provider_for_uri(uri) } end |
.provider_for_uri(uri) ⇒ Object
23 24 25 26 27 |
# File 'lib/llm_cost_tracker/providers/openai_compatible/parser.rb', line 23 def provider_for_uri(uri) return nil unless uri LlmCostTracker.configuration.openai_compatible_providers[uri.host.to_s.downcase]&.to_s end |
.provider_names ⇒ Object
16 17 18 19 20 21 |
# File 'lib/llm_cost_tracker/providers/openai_compatible/parser.rb', line 16 def provider_names custom = LlmCostTracker.configuration.openai_compatible_providers.each_value.map do |provider| provider.to_s.downcase end ["openai_compatible", *custom].uniq end |
Instance Method Details
#provider_for(request_url) ⇒ Object
30 31 32 |
# File 'lib/llm_cost_tracker/providers/openai_compatible/parser.rb', line 30 def provider_for(request_url) self.class.provider_for_uri(parsed_uri(request_url)) || "openai_compatible" end |