Module: RubyLLM::Pollinations::Provider::Streaming
- Included in:
- Pollinations
- Defined in:
- lib/ruby_llm/pollinations/provider/streaming.rb
Class Method Summary collapse
Class Method Details
.build_chunk(data) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ruby_llm/pollinations/provider/streaming.rb', line 13 def build_chunk(data) usage = data['usage'] || {} cached_tokens = usage.dig('prompt_tokens_details', 'cached_tokens') delta = data.dig('choices', 0, 'delta') || {} content_source = delta['content'] || data.dig('choices', 0, 'message', 'content') content, thinking_from_blocks = Chat.extract_content_and_thinking(content_source) RubyLLM::Chunk.new( role: :assistant, model_id: data['model'], content: content, thinking: RubyLLM::Thinking.build( text: thinking_from_blocks || delta['reasoning_content'] || delta['reasoning'] ), tool_calls: Tools.parse_tool_calls(delta['tool_calls'], parse_arguments: false), input_tokens: usage['prompt_tokens'], output_tokens: usage['completion_tokens'], cached_tokens: cached_tokens, cache_creation_tokens: 0, thinking_tokens: usage.dig('completion_tokens_details', 'reasoning_tokens') ) end |
.parse_streaming_error(data) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/ruby_llm/pollinations/provider/streaming.rb', line 36 def parse_streaming_error(data) error_data = JSON.parse(data) return unless error_data['error'] error = error_data['error'] code = error['code'] || error['type'] case code when 'RATE_LIMIT', 'rate_limit_exceeded', 'insufficient_quota' [429, error['message']] when 'INTERNAL_ERROR', 'server_error' [500, error['message']] when 'UNAUTHORIZED' [401, error['message']] when 'PAYMENT_REQUIRED' [402, error['message']] else [400, error['message']] end end |
.stream_url ⇒ Object
9 10 11 |
# File 'lib/ruby_llm/pollinations/provider/streaming.rb', line 9 def stream_url completion_url end |