Method: Langchain::Prompt::Loading::ClassMethods#load_from_path

Defined in:
lib/langchain/prompt/loading.rb

#load_from_path(file_path:) ⇒ Object

Load prompt from file.

Parameters:

  • file_path (String, Pathname)

    The path of the file to read the configuration data from.

Returns:

  • (Object)

    The loaded prompt loaded.

Raises:

  • (ArgumentError)

    If the file type of the specified file path is not supported.


28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/langchain/prompt/loading.rb', line 28

def load_from_path(file_path:)
  file_path = file_path.is_a?(String) ? Pathname.new(file_path) : file_path

  case file_path.extname
  when ".json"
    config = JSON.parse(File.read(file_path))
  when ".yaml", ".yml"
    config = YAML.safe_load_file(file_path)
  else
    raise ArgumentError, "Got unsupported file type #{file_path.extname}"
  end

  load_from_config(config)
end