Class: LlmGateway::Proxy::Adapter

Inherits:
Object
  • Object
show all
Defined in:
lib/llm_gateway/proxy/adapter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Adapter

Returns a new instance of Adapter.



8
9
10
# File 'lib/llm_gateway/proxy/adapter.rb', line 8

def initialize(client)
  @client = client
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



6
7
8
# File 'lib/llm_gateway/proxy/adapter.rb', line 6

def client
  @client
end

Instance Method Details

#stream(message, tools: nil, system: nil, **options, &block) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/llm_gateway/proxy/adapter.rb', line 12

def stream(message, tools: nil, system: nil, **options, &block)
  target_adapter = LlmGateway.build_provider(client.target_config.merge(provider: client.target_provider))
  mapper_class = target_adapter.stream_mapper_class
  raise LlmGateway::Errors::MissingMapperForProvider, "No stream_mapper configured" unless mapper_class

  mapper = mapper_class.new(
    provider: LlmGateway::Client.provider_id_from_client(target_adapter.client),
    api: target_adapter.stream_api_name
  )

  client.stream(normalize_messages(message), tools: tools, system: normalize_system(system), **options) do |chunk|
    mapper.map(chunk, &block)
  end

  mapper.result
end