Class: RubyLLM::MCP::Prompt
- Inherits:
-
Object
- Object
- RubyLLM::MCP::Prompt
- Defined in:
- lib/ruby_llm/mcp/prompt.rb
Defined Under Namespace
Classes: Argument
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#arguments ⇒ Object
readonly
Returns the value of attribute arguments.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #ask(chat, arguments: {}) ⇒ Object (also: #say)
- #complete(argument, value, context: nil) ⇒ Object
- #fetch(arguments = {}) ⇒ Object
- #include(chat, arguments: {}) ⇒ Object
-
#initialize(adapter, prompt) ⇒ Prompt
constructor
A new instance of Prompt.
- #to_h ⇒ Object (also: #to_json)
Constructor Details
#initialize(adapter, prompt) ⇒ Prompt
Returns a new instance of Prompt.
26 27 28 29 30 31 |
# File 'lib/ruby_llm/mcp/prompt.rb', line 26 def initialize(adapter, prompt) @adapter = adapter @name = prompt["name"] @description = prompt["description"] @arguments = parse_arguments(prompt["arguments"]) end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
24 25 26 |
# File 'lib/ruby_llm/mcp/prompt.rb', line 24 def adapter @adapter end |
#arguments ⇒ Object (readonly)
Returns the value of attribute arguments.
24 25 26 |
# File 'lib/ruby_llm/mcp/prompt.rb', line 24 def arguments @arguments end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
24 25 26 |
# File 'lib/ruby_llm/mcp/prompt.rb', line 24 def description @description end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
24 25 26 |
# File 'lib/ruby_llm/mcp/prompt.rb', line 24 def name @name end |
Instance Method Details
#ask(chat, arguments: {}) ⇒ Object Also known as: say
45 46 47 48 49 |
# File 'lib/ruby_llm/mcp/prompt.rb', line 45 def ask(chat, arguments: {}, &) include(chat, arguments: arguments) chat.complete(&) end |
#complete(argument, value, context: nil) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/ruby_llm/mcp/prompt.rb', line 53 def complete(argument, value, context: nil) if @adapter.capabilities.completion? result = @adapter.completion_prompt(name: @name, argument: argument, value: value, context: context) if result.error? return result.to_error end response = result.value["completion"] Completion.new(argument: argument, values: response["values"], total: response["total"], has_more: response["hasMore"]) else = "Completion is not available for this MCP server" raise Errors::Capabilities::CompletionNotAvailable.new(message: ) end end |
#fetch(arguments = {}) ⇒ Object
33 34 35 |
# File 'lib/ruby_llm/mcp/prompt.rb', line 33 def fetch(arguments = {}) (arguments) end |
#include(chat, arguments: {}) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/ruby_llm/mcp/prompt.rb', line 37 def include(chat, arguments: {}) validate_arguments!(arguments) = (arguments) .each { || chat.() } chat end |
#to_h ⇒ Object Also known as: to_json
70 71 72 73 74 75 76 |
# File 'lib/ruby_llm/mcp/prompt.rb', line 70 def to_h { name: @name, description: @description, arguments: @arguments.map(&:to_h) } end |