Module: Artificial
- Defined in:
- lib/artificial.rb,
lib/artificial/prompt.rb,
lib/artificial/version.rb,
lib/artificial/parsers/xml_parser.rb,
lib/artificial/parsers/json_parser.rb,
lib/artificial/parsers/yaml_parser.rb,
lib/artificial/parsers/string_parser.rb,
lib/artificial/validators/role_validator.rb,
lib/artificial/validators/message_validator.rb
Defined Under Namespace
Modules: Parsers, Validators Classes: Error, Prompt
Constant Summary collapse
- VERSION =
'0.0.1'
Class Method Summary collapse
- .auto_parse(input) ⇒ Object
-
.create_prompt(input = nil, **options) ⇒ Object
Factory method for creating prompts.
-
.parse(input, format: :auto) ⇒ Object
Parse input using appropriate parser.
-
.validate_messages(messages) ⇒ Object
Validate messages.
-
.validate_role(system_prompt) ⇒ Object
Validate role.
Class Method Details
.auto_parse(input) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/artificial.rb', line 52 def self.auto_parse(input) return Parsers::StringParser.new(input).parse unless input.is_a?(String) # Try to detect format from string content input_trimmed = input.strip if input_trimmed.start_with?('<') && input_trimmed.end_with?('>') Parsers::XMLParser.new(input).parse elsif input_trimmed.start_with?('{') && input_trimmed.end_with?('}') Parsers::JSONParser.new(input).parse elsif input_trimmed.include?(':') && (input_trimmed.include?('-') || input_trimmed.include?('|') || input_trimmed.include?("\n")) Parsers::YAMLParser.new(input).parse else Parsers::StringParser.new(input).parse end end |
.create_prompt(input = nil, **options) ⇒ Object
Factory method for creating prompts
20 21 22 |
# File 'lib/artificial.rb', line 20 def self.create_prompt(input = nil, **) Prompt.new(input, **) end |
.parse(input, format: :auto) ⇒ Object
Parse input using appropriate parser
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/artificial.rb', line 25 def self.parse(input, format: :auto) case format when :auto auto_parse(input) when :string Parsers::StringParser.new(input).parse when :xml Parsers::XMLParser.new(input).parse when :yaml Parsers::YAMLParser.new(input).parse when :json Parsers::JSONParser.new(input).parse else raise ArgumentError, "Unknown format: #{format}" end end |
.validate_messages(messages) ⇒ Object
Validate messages
43 44 45 |
# File 'lib/artificial.rb', line 43 def self.() Validators::MessageValidator.new().validate end |
.validate_role(system_prompt) ⇒ Object
Validate role
48 49 50 |
# File 'lib/artificial.rb', line 48 def self.validate_role(system_prompt) Validators::RoleValidator.new(system_prompt).validate end |