Class: SmartPrompt::WorkerContext
- Inherits:
-
Object
- Object
- SmartPrompt::WorkerContext
show all
- Defined in:
- lib/smart_prompt/worker.rb
Instance Method Summary
collapse
Constructor Details
#initialize(conversation, params, engine, proc = nil) ⇒ WorkerContext
Returns a new instance of WorkerContext.
37
38
39
40
41
42
|
# File 'lib/smart_prompt/worker.rb', line 37
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/smart_prompt/worker.rb', line 44
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, params)
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
76
77
78
79
|
# File 'lib/smart_prompt/worker.rb', line 76
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
81
82
83
84
|
# File 'lib/smart_prompt/worker.rb', line 81
def call_worker_by_stream(worker_name, params = {}, proc)
worker = Worker.new(worker_name, @engine)
worker.execute_by_stream(params, proc)
end
|
#params ⇒ Object
68
69
70
|
# File 'lib/smart_prompt/worker.rb', line 68
def params
@params
end
|
#proc ⇒ Object
72
73
74
|
# File 'lib/smart_prompt/worker.rb', line 72
def proc
@proc
end
|
#respond_to_missing?(method, include_private = false) ⇒ Boolean
64
65
66
|
# File 'lib/smart_prompt/worker.rb', line 64
def respond_to_missing?(method, include_private = false)
@conversation.respond_to?(method) || super
end
|