Class: Legion::LLM::Pipeline::Request

Inherits:
Data
  • Object
show all
Defined in:
lib/legion/llm/pipeline/request.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#agentObject (readonly)

Returns the value of attribute agent

Returns:

  • (Object)

    the current value of agent



6
7
8
# File 'lib/legion/llm/pipeline/request.rb', line 6

def agent
  @agent
end

#billingObject (readonly)

Returns the value of attribute billing

Returns:

  • (Object)

    the current value of billing



6
7
8
# File 'lib/legion/llm/pipeline/request.rb', line 6

def billing
  @billing
end

#cacheObject (readonly)

Returns the value of attribute cache

Returns:

  • (Object)

    the current value of cache



6
7
8
# File 'lib/legion/llm/pipeline/request.rb', line 6

def cache
  @cache
end

#callerObject (readonly)

Returns the value of attribute caller

Returns:

  • (Object)

    the current value of caller



6
7
8
# File 'lib/legion/llm/pipeline/request.rb', line 6

def caller
  @caller
end

#classificationObject (readonly)

Returns the value of attribute classification

Returns:

  • (Object)

    the current value of classification



6
7
8
# File 'lib/legion/llm/pipeline/request.rb', line 6

def classification
  @classification
end

#context_strategyObject (readonly)

Returns the value of attribute context_strategy

Returns:

  • (Object)

    the current value of context_strategy



6
7
8
# File 'lib/legion/llm/pipeline/request.rb', line 6

def context_strategy
  @context_strategy
end

#conversation_idObject (readonly)

Returns the value of attribute conversation_id

Returns:

  • (Object)

    the current value of conversation_id



6
7
8
# File 'lib/legion/llm/pipeline/request.rb', line 6

def conversation_id
  @conversation_id
end

#enrichmentsObject (readonly)

Returns the value of attribute enrichments

Returns:

  • (Object)

    the current value of enrichments



6
7
8
# File 'lib/legion/llm/pipeline/request.rb', line 6

def enrichments
  @enrichments
end

#extraObject (readonly)

Returns the value of attribute extra

Returns:

  • (Object)

    the current value of extra



6
7
8
# File 'lib/legion/llm/pipeline/request.rb', line 6

def extra
  @extra
end

#forkObject (readonly)

Returns the value of attribute fork

Returns:

  • (Object)

    the current value of fork



6
7
8
# File 'lib/legion/llm/pipeline/request.rb', line 6

def fork
  @fork
end

#generationObject (readonly)

Returns the value of attribute generation

Returns:

  • (Object)

    the current value of generation



6
7
8
# File 'lib/legion/llm/pipeline/request.rb', line 6

def generation
  @generation
end

#hooksObject (readonly)

Returns the value of attribute hooks

Returns:

  • (Object)

    the current value of hooks



6
7
8
# File 'lib/legion/llm/pipeline/request.rb', line 6

def hooks
  @hooks
end

#idObject (readonly)

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



6
7
8
# File 'lib/legion/llm/pipeline/request.rb', line 6

def id
  @id
end

#idempotency_keyObject (readonly)

Returns the value of attribute idempotency_key

Returns:

  • (Object)

    the current value of idempotency_key



6
7
8
# File 'lib/legion/llm/pipeline/request.rb', line 6

def idempotency_key
  @idempotency_key
end

#messagesObject (readonly)

Returns the value of attribute messages

Returns:

  • (Object)

    the current value of messages



6
7
8
# File 'lib/legion/llm/pipeline/request.rb', line 6

def messages
  @messages
end

#metadataObject (readonly)

Returns the value of attribute metadata

Returns:

  • (Object)

    the current value of metadata



6
7
8
# File 'lib/legion/llm/pipeline/request.rb', line 6

def 
  @metadata
end

#modalityObject (readonly)

Returns the value of attribute modality

Returns:

  • (Object)

    the current value of modality



6
7
8
# File 'lib/legion/llm/pipeline/request.rb', line 6

def modality
  @modality
end

#predictionsObject (readonly)

Returns the value of attribute predictions

Returns:

  • (Object)

    the current value of predictions



6
7
8
# File 'lib/legion/llm/pipeline/request.rb', line 6

def predictions
  @predictions
end

#priorityObject (readonly)

Returns the value of attribute priority

Returns:

  • (Object)

    the current value of priority



6
7
8
# File 'lib/legion/llm/pipeline/request.rb', line 6

def priority
  @priority
end

#response_formatObject (readonly)

Returns the value of attribute response_format

Returns:

  • (Object)

    the current value of response_format



6
7
8
# File 'lib/legion/llm/pipeline/request.rb', line 6

def response_format
  @response_format
end

#routingObject (readonly)

Returns the value of attribute routing

Returns:

  • (Object)

    the current value of routing



6
7
8
# File 'lib/legion/llm/pipeline/request.rb', line 6

def routing
  @routing
end

#schema_versionObject (readonly)

Returns the value of attribute schema_version

Returns:

  • (Object)

    the current value of schema_version



6
7
8
# File 'lib/legion/llm/pipeline/request.rb', line 6

def schema_version
  @schema_version
end

#stopObject (readonly)

Returns the value of attribute stop

Returns:

  • (Object)

    the current value of stop



6
7
8
# File 'lib/legion/llm/pipeline/request.rb', line 6

def stop
  @stop
end

#streamObject (readonly)

Returns the value of attribute stream

Returns:

  • (Object)

    the current value of stream



6
7
8
# File 'lib/legion/llm/pipeline/request.rb', line 6

def stream
  @stream
end

#systemObject (readonly)

Returns the value of attribute system

Returns:

  • (Object)

    the current value of system



6
7
8
# File 'lib/legion/llm/pipeline/request.rb', line 6

def system
  @system
end

#testObject (readonly)

Returns the value of attribute test

Returns:

  • (Object)

    the current value of test



6
7
8
# File 'lib/legion/llm/pipeline/request.rb', line 6

def test
  @test
end

#thinkingObject (readonly)

Returns the value of attribute thinking

Returns:

  • (Object)

    the current value of thinking



6
7
8
# File 'lib/legion/llm/pipeline/request.rb', line 6

def thinking
  @thinking
end

#tokensObject (readonly)

Returns the value of attribute tokens

Returns:

  • (Object)

    the current value of tokens



6
7
8
# File 'lib/legion/llm/pipeline/request.rb', line 6

def tokens
  @tokens
end

#tool_choiceObject (readonly)

Returns the value of attribute tool_choice

Returns:

  • (Object)

    the current value of tool_choice



6
7
8
# File 'lib/legion/llm/pipeline/request.rb', line 6

def tool_choice
  @tool_choice
end

#toolsObject (readonly)

Returns the value of attribute tools

Returns:

  • (Object)

    the current value of tools



6
7
8
# File 'lib/legion/llm/pipeline/request.rb', line 6

def tools
  @tools
end

#tracingObject (readonly)

Returns the value of attribute tracing

Returns:

  • (Object)

    the current value of tracing



6
7
8
# File 'lib/legion/llm/pipeline/request.rb', line 6

def tracing
  @tracing
end

#ttlObject (readonly)

Returns the value of attribute ttl

Returns:

  • (Object)

    the current value of ttl



6
7
8
# File 'lib/legion/llm/pipeline/request.rb', line 6

def ttl
  @ttl
end

Class Method Details

.build(**kwargs) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/legion/llm/pipeline/request.rb', line 16

def self.build(**kwargs)
  new(
    id:               kwargs[:id] || "req_#{SecureRandom.hex(12)}",
    conversation_id:  kwargs[:conversation_id],
    idempotency_key:  kwargs[:idempotency_key],
    schema_version:   kwargs.fetch(:schema_version, '1.0.0'),
    system:           kwargs[:system],
    messages:         kwargs.fetch(:messages, []),
    tools:            kwargs.key?(:tools) ? kwargs[:tools] : nil,
    tool_choice:      kwargs.fetch(:tool_choice, { mode: :auto }),
    routing:          kwargs.fetch(:routing, { provider: nil, model: nil }),
    tokens:           kwargs.fetch(:tokens, { max: 4096 }),
    stop:             kwargs.fetch(:stop, { sequences: [] }),
    generation:       kwargs.fetch(:generation, {}),
    thinking:         kwargs[:thinking],
    response_format:  kwargs.fetch(:response_format, { type: :text }),
    stream:           kwargs.fetch(:stream, false),
    fork:             kwargs[:fork],
    context_strategy: kwargs.fetch(:context_strategy, :auto),
    cache:            kwargs.fetch(:cache, { strategy: :default, cacheable: true }),
    priority:         kwargs.fetch(:priority, :normal),
    ttl:              kwargs[:ttl],
    extra:            kwargs.fetch(:extra, {}),
    metadata:         kwargs.fetch(:metadata, {}),
    enrichments:      kwargs.fetch(:enrichments, {}),
    predictions:      kwargs.fetch(:predictions, {}),
    tracing:          kwargs[:tracing],
    classification:   kwargs[:classification],
    caller:           kwargs[:caller],
    agent:            kwargs[:agent],
    billing:          kwargs[:billing],
    test:             kwargs[:test],
    modality:         kwargs[:modality],
    hooks:            kwargs[:hooks]
  )
end

.from_chat_args(**kwargs) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/legion/llm/pipeline/request.rb', line 53

def self.from_chat_args(**kwargs)
  request_id = kwargs[:request_id] || kwargs[:id]
  messages = []
  if kwargs[:messages]
    messages = kwargs[:messages]
  elsif kwargs[:message]
    msg = kwargs[:message]
    messages = msg.is_a?(Array) ? msg : [{ role: :user, content: msg }]
  end

  routing = {
    provider: kwargs[:provider],
    model:    kwargs[:model]
  }

  extra = kwargs.except(
    :message, :messages, :model, :provider, :system,
    :tools, :tool_choice, :stream, :caller, :classification, :billing,
    :agent, :test, :tracing, :priority, :conversation_id,
    :request_id, :id, :generation, :thinking, :response_format,
    :context_strategy, :cache, :fork, :tokens, :stop,
    :modality, :hooks, :idempotency_key, :ttl, :metadata,
    :enrichments, :predictions
  )

  build_args = {
    messages:         messages,
    system:           kwargs[:system],
    routing:          routing,
    tools:            kwargs.key?(:tools) ? kwargs[:tools] : nil,
    tool_choice:      kwargs[:tool_choice] || { mode: :auto },
    stream:           kwargs.fetch(:stream, false),
    generation:       kwargs[:generation] || {},
    thinking:         kwargs[:thinking],
    response_format:  kwargs[:response_format] || { type: :text },
    context_strategy: kwargs.fetch(:context_strategy, :auto),
    cache:            kwargs[:cache] || { strategy: :default, cacheable: true },
    fork:             kwargs[:fork],
    tokens:           kwargs[:tokens] || { max: 4096 },
    stop:             kwargs[:stop] || { sequences: [] },
    modality:         kwargs[:modality],
    hooks:            kwargs[:hooks],
    caller:           kwargs[:caller],
    classification:   kwargs[:classification],
    billing:          kwargs[:billing],
    agent:            kwargs[:agent],
    test:             kwargs[:test],
    tracing:          kwargs[:tracing],
    priority:         kwargs.fetch(:priority, :normal),
    conversation_id:  kwargs[:conversation_id],
    idempotency_key:  kwargs[:idempotency_key],
    ttl:              kwargs[:ttl],
    metadata:         kwargs[:metadata] || {},
    enrichments:      kwargs[:enrichments] || {},
    predictions:      kwargs[:predictions] || {},
    extra:            extra
  }
  build_args[:id] = request_id if request_id
  build(**build_args)
end