Class: SmartPrompt::WorkerContext
- Inherits:
-
Object
- Object
- SmartPrompt::WorkerContext
show all
- Defined in:
- lib/smart_prompt/worker.rb
Instance Method Summary
collapse
-
#call_worker(worker_name, params = {}) ⇒ Object
-
#call_worker_by_stream(worker_name, params = {}, proc) ⇒ Object
-
#engine ⇒ Object
Expose the engine so workers can reach a configured adapter directly (e.g. ‘engine.llms`) for methods Conversation doesn’t delegate, such as generate_video / synthesize_to_file / transcribe_audio.
-
#initialize(conversation, params, engine, proc = nil) ⇒ WorkerContext
constructor
A new instance of WorkerContext.
-
#method_missing(method, *args, &block) ⇒ Object
-
#params ⇒ Object
-
#proc ⇒ Object
-
#respond_to_missing?(method, include_private = false) ⇒ Boolean
Constructor Details
#initialize(conversation, params, engine, proc = nil) ⇒ WorkerContext
Returns a new instance of WorkerContext.
55
56
57
58
59
60
|
# File 'lib/smart_prompt/worker.rb', line 55
def initialize(conversation, params, engine, proc = nil)
@conversation = conversation
@params = params
@engine = engine
@proc = proc
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/smart_prompt/worker.rb', line 62
def method_missing(method, *args, &block)
if @conversation.respond_to?(method)
if method == :send_msg
if @proc == nil
@conversation.send_msg(params)
else
@conversation.send_msg_by_stream(params, &@proc)
end
elsif method == :sys_msg
@conversation.sys_msg(*args)
elsif method == :prompt
@conversation.prompt(*args, with_history: params[:with_history])
else
@conversation.send(method, *args, &block)
end
else
super
end
end
|
Instance Method Details
#call_worker(worker_name, params = {}) ⇒ Object
101
102
103
104
|
# File 'lib/smart_prompt/worker.rb', line 101
def call_worker(worker_name, params = {})
worker = Worker.new(worker_name, @engine)
worker.execute(params)
end
|
#call_worker_by_stream(worker_name, params = {}, proc) ⇒ Object
106
107
108
109
|
# File 'lib/smart_prompt/worker.rb', line 106
def call_worker_by_stream(worker_name, params = {}, proc)
worker = Worker.new(worker_name, @engine)
worker.execute_by_stream(params, proc)
end
|
#engine ⇒ Object
Expose the engine so workers can reach a configured adapter directly (e.g. ‘engine.llms`) for methods Conversation doesn’t delegate, such as generate_video / synthesize_to_file / transcribe_audio.
97
98
99
|
# File 'lib/smart_prompt/worker.rb', line 97
def engine
@engine
end
|
#params ⇒ Object
86
87
88
|
# File 'lib/smart_prompt/worker.rb', line 86
def params
@params
end
|
#proc ⇒ Object
90
91
92
|
# File 'lib/smart_prompt/worker.rb', line 90
def proc
@proc
end
|
#respond_to_missing?(method, include_private = false) ⇒ Boolean
82
83
84
|
# File 'lib/smart_prompt/worker.rb', line 82
def respond_to_missing?(method, include_private = false)
@conversation.respond_to?(method) || super
end
|