Class: LLM::Function::Sequential::Task
- Inherits:
-
Task
- Object
- Task
- LLM::Function::Sequential::Task
show all
- Defined in:
- lib/llm/function/sequential/task.rb
Overview
The Task class wraps a single
direct function call behind the same task-like interface
used by spawned concurrency modes.
Instance Attribute Summary
Attributes inherited from Task
#finished_at, #function, #span, #started_at, #tracer
Instance Method Summary
collapse
Methods inherited from Task
#initialize, #intercepted?
Instance Method Details
#spawn ⇒ nil
11
12
13
14
15
16
17
18
19
|
# File 'lib/llm/function/sequential/task.rb', line 11
def spawn
@span = @tracer&.on_tool_start(
id: @function.id,
name: @function.name,
arguments: @function.arguments,
model: @function.model
)
nil
end
|
#alive? ⇒ Boolean
23
24
25
|
# File 'lib/llm/function/sequential/task.rb', line 23
def alive?
false
end
|
#interrupt! ⇒ nil
Also known as:
cancel!
29
30
31
32
33
|
# File 'lib/llm/function/sequential/task.rb', line 29
def interrupt!
@cancelled = true
function.interrupt!
nil
end
|
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/llm/function/sequential/task.rb', line 38
def wait
return @intercepted if intercepted?
result = LLM::Object.new(unbox: nil)
if @cancelled and !@result
@started_at = Process.clock_gettime(Process::CLOCK_MONOTONIC)
@finished_at = Process.clock_gettime(Process::CLOCK_MONOTONIC)
@result = result
@result.unbox = LLM::Interrupt.new
else
@result = (@result || begin
@started_at = Process.clock_gettime(Process::CLOCK_MONOTONIC)
begin
result.unbox = function.call
rescue LLM::Interrupt => ex
result.unbox = ex
ensure
@finished_at = Process.clock_gettime(Process::CLOCK_MONOTONIC)
end
result
end)
end
@result.unbox
end
|