Class: MockServer::LLM::Completion

Inherits:
Object
  • Object
show all
Defined in:
lib/mockserver/llm.rb

Overview

Completion

Instance Method Summary collapse

Constructor Details

#initializeCompletion

Returns a new instance of Completion.



243
244
245
246
247
248
249
250
251
252
# File 'lib/mockserver/llm.rb', line 243

def initialize
  @text = nil
  @tool_calls = nil
  @stop_reason = nil
  @usage = nil
  @streaming = nil
  @streaming_physics = nil
  @output_schema = nil
  @model = nil
end

Instance Method Details

#streamingself

Enable streaming. Mirror of completion.streaming().

Returns:

  • (self)


294
295
296
# File 'lib/mockserver/llm.rb', line 294

def streaming
  with_streaming(true)
end

#to_hHash

Returns:

  • (Hash)


319
320
321
322
323
324
325
326
327
328
329
330
# File 'lib/mockserver/llm.rb', line 319

def to_h
  LLM.omit_nil(
    'text' => @text,
    'toolCalls' => LLM.wire(@tool_calls),
    'stopReason' => @stop_reason,
    'usage' => LLM.wire(@usage),
    'streaming' => @streaming,
    'streamingPhysics' => LLM.wire(@streaming_physics),
    'outputSchema' => @output_schema,
    'model' => @model
  )
end

#with_model(model) ⇒ self

Returns:

  • (self)


313
314
315
316
# File 'lib/mockserver/llm.rb', line 313

def with_model(model)
  @model = model
  self
end

#with_output_schema(output_schema) ⇒ self

Accepts a JSON string (matching Java) or any value (serialised to JSON).

Returns:

  • (self)


307
308
309
310
# File 'lib/mockserver/llm.rb', line 307

def with_output_schema(output_schema)
  @output_schema = output_schema.is_a?(String) ? output_schema : JSON.generate(output_schema)
  self
end

#with_stop_reason(stop_reason) ⇒ self

Returns:

  • (self)


275
276
277
278
# File 'lib/mockserver/llm.rb', line 275

def with_stop_reason(stop_reason)
  @stop_reason = stop_reason
  self
end

#with_streaming(streaming = true) ⇒ self

Returns:

  • (self)


287
288
289
290
# File 'lib/mockserver/llm.rb', line 287

def with_streaming(streaming = true)
  @streaming = streaming
  self
end

#with_streaming_physics(physics) ⇒ self

Note: does NOT touch streaming (matching the Java/Python builder).

Returns:

  • (self)


300
301
302
303
# File 'lib/mockserver/llm.rb', line 300

def with_streaming_physics(physics)
  @streaming_physics = physics
  self
end

#with_text(text) ⇒ self

Returns:

  • (self)


255
256
257
258
# File 'lib/mockserver/llm.rb', line 255

def with_text(text)
  @text = text
  self
end

#with_tool_call(tool_call) ⇒ self

Returns:

  • (self)


261
262
263
264
265
# File 'lib/mockserver/llm.rb', line 261

def with_tool_call(tool_call)
  @tool_calls ||= []
  @tool_calls << tool_call
  self
end

#with_tool_calls(*tool_calls) ⇒ self

Returns:

  • (self)


268
269
270
271
272
# File 'lib/mockserver/llm.rb', line 268

def with_tool_calls(*tool_calls)
  flattened = tool_calls.length == 1 && tool_calls.first.is_a?(Array) ? tool_calls.first : tool_calls
  @tool_calls = flattened.dup
  self
end

#with_usage(usage) ⇒ self

Returns:

  • (self)


281
282
283
284
# File 'lib/mockserver/llm.rb', line 281

def with_usage(usage)
  @usage = usage
  self
end