Class: AISpec::Core::Providers::Mock

Inherits:
Base
  • Object
show all
Defined in:
lib/aispec/core/providers/mock.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#model, #options

Instance Method Summary collapse

Methods inherited from Base

get, register

Constructor Details

#initialize(model: "mock-model", canned_response: nil, canned_latency_ms: 120.0, canned_cost: 0.001, canned_tools: [], **options) ⇒ Mock

Returns a new instance of Mock.



9
10
11
12
13
14
15
# File 'lib/aispec/core/providers/mock.rb', line 9

def initialize(model: "mock-model", canned_response: nil, canned_latency_ms: 120.0, canned_cost: 0.001, canned_tools: [], **options)
  super(model: model, **options)
  @canned_response = canned_response
  @canned_latency_ms = canned_latency_ms
  @canned_cost = canned_cost
  @canned_tools = canned_tools
end

Instance Attribute Details

#canned_costObject

Returns the value of attribute canned_cost.



7
8
9
# File 'lib/aispec/core/providers/mock.rb', line 7

def canned_cost
  @canned_cost
end

#canned_latency_msObject

Returns the value of attribute canned_latency_ms.



7
8
9
# File 'lib/aispec/core/providers/mock.rb', line 7

def canned_latency_ms
  @canned_latency_ms
end

#canned_responseObject

Returns the value of attribute canned_response.



7
8
9
# File 'lib/aispec/core/providers/mock.rb', line 7

def canned_response
  @canned_response
end

#canned_toolsObject

Returns the value of attribute canned_tools.



7
8
9
# File 'lib/aispec/core/providers/mock.rb', line 7

def canned_tools
  @canned_tools
end

Instance Method Details

#generate(prompt, **params) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/aispec/core/providers/mock.rb', line 17

def generate(prompt, **params)
  output = @canned_response || params[:canned_response] || default_mock_output(prompt)
  latency = params[:latency_ms] || @canned_latency_ms
  cost = params[:cost] || @canned_cost
  tools = params[:tools_called] || @canned_tools
  tokens = (output.to_s.split.length * 1.3).to_i

  build_response(
    output: output,
    latency_ms: latency,
    tokens: tokens,
    cost: cost,
    tools_called: tools,
    raw: { mock: true }
  )
end