module Ollama::Utils::FileArgument
def get_file_argument(path_or_content, default: nil)
- Example: Return a default value if no valid input is given -
Example: Use a string as content -
Example: Get the contents of a file -
Returns:
-
(String)
- The contents of the file, the string, or the default value.
Parameters:
-
default
(String
) -- The default value to return if no valid input is -
path_or_content
(String
) -- The path to a file or a string containing
def get_file_argument(path_or_content, default: nil) if path_or_content.present? && path_or_content.size < 2 ** 15 && File.basename(path_or_content).size < 2 ** 8 && File.exist?(path_or_content) then File.read(path_or_content) elsif path_or_content.present? path_or_content else default end end