Class: Roseflow::OpenRouter::Model

Inherits:
Object
  • Object
show all
Defined in:
lib/roseflow/open_router/model.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, provider) ⇒ Model

Returns a new instance of Model.



18
19
20
21
22
# File 'lib/roseflow/open_router/model.rb', line 18

def initialize(model, provider)
  @model_ = model
  @provider_ = provider
  assign_attributes
end

Instance Attribute Details

#context_lengthObject (readonly)

Returns the value of attribute context_length.



16
17
18
# File 'lib/roseflow/open_router/model.rb', line 16

def context_length
  @context_length
end

#idObject (readonly)

Returns the value of attribute id.



16
17
18
# File 'lib/roseflow/open_router/model.rb', line 16

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



16
17
18
# File 'lib/roseflow/open_router/model.rb', line 16

def name
  @name
end

Instance Method Details

#call(operation, options) {|chunk| ... } ⇒ Faraday::Response

Calls the model.

Parameters:

  • operation (Symbol)

    Operation to perform

  • options (Hash)

    Options to use

Yields:

  • (chunk)

    Chunk of data if stream is enabled

Returns:

  • (Faraday::Response)

    raw API response if no block is given



45
46
47
48
# File 'lib/roseflow/open_router/model.rb', line 45

def call(operation, options, &block)
  operation = OperationHandler.new(operation, options.merge({ model: name })).call
  client.post(operation, &block)
end

#chat(messages, options = {}) {|chunk| ... } ⇒ OpenAI::ChatResponse

Convenience method for chat completions.

Parameters:

  • messages (Array<String>)

    Messages to use

  • options (Hash) (defaults to: {})

    Options to use

Yields:

  • (chunk)

    Chunk of data if stream is enabled

Returns:

  • (OpenAI::ChatResponse)

    the chat response object if no block is given



34
35
36
37
# File 'lib/roseflow/open_router/model.rb', line 34

def chat(messages, options = {}, &block)
  response = call(:completion, options.merge({ messages: messages, model: name }), &block)
  ChatResponse.new(response) unless block_given?
end

#max_tokensObject



24
25
26
# File 'lib/roseflow/open_router/model.rb', line 24

def max_tokens
  @context_length
end