ollama-ruby 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +48 -0
- data/README.md +2 -0
- data/Rakefile +5 -3
- data/bin/ollama_chat +75 -44
- data/lib/ollama/documents/cache/common.rb +17 -0
- data/lib/ollama/documents/{memory_cache.rb → cache/memory_cache.rb} +8 -10
- data/lib/ollama/documents/cache/redis_backed_memory_cache.rb +44 -0
- data/lib/ollama/documents/{redis_cache.rb → cache/redis_cache.rb} +9 -8
- data/lib/ollama/documents.rb +19 -16
- data/lib/ollama/utils/chooser.rb +3 -1
- data/lib/ollama/utils/colorize_texts.rb +21 -1
- data/lib/ollama/utils/fetcher.rb +8 -6
- data/lib/ollama/utils/file_argument.rb +25 -7
- data/lib/ollama/utils/tags.rb +1 -0
- data/lib/ollama/version.rb +1 -1
- data/ollama-ruby.gemspec +8 -7
- data/spec/assets/prompt.txt +1 -0
- data/spec/ollama/documents/memory_cache_spec.rb +16 -16
- data/spec/ollama/documents/redis_backed_memory_cache_spec.rb +95 -0
- data/spec/ollama/documents/redis_cache_spec.rb +15 -15
- data/spec/ollama/utils/fetcher_spec.rb +2 -1
- data/spec/ollama/utils/file_argument_spec.rb +17 -0
- data/spec/ollama/utils/tags_spec.rb +3 -3
- metadata +31 -8
data/lib/ollama/utils/fetcher.rb
CHANGED
@@ -2,6 +2,7 @@ require 'tempfile'
|
|
2
2
|
require 'tins/unit'
|
3
3
|
require 'infobar'
|
4
4
|
require 'mime-types'
|
5
|
+
require 'stringio'
|
5
6
|
|
6
7
|
class Ollama::Utils::Fetcher
|
7
8
|
module ContentType
|
@@ -10,13 +11,14 @@ class Ollama::Utils::Fetcher
|
|
10
11
|
|
11
12
|
class RetryWithoutStreaming < StandardError; end
|
12
13
|
|
13
|
-
def initialize
|
14
|
+
def initialize(debug: false)
|
15
|
+
@debug = debug
|
14
16
|
@started = false
|
15
17
|
@streaming = true
|
16
18
|
end
|
17
19
|
|
18
|
-
def self.get(url, &block)
|
19
|
-
new.get(url, &block)
|
20
|
+
def self.get(url, **options, &block)
|
21
|
+
new(**options).get(url, &block)
|
20
22
|
end
|
21
23
|
|
22
24
|
def get(url, &block)
|
@@ -46,11 +48,11 @@ class Ollama::Utils::Fetcher
|
|
46
48
|
@streaming = false
|
47
49
|
retry
|
48
50
|
rescue => e
|
49
|
-
STDERR.puts "Cannot get #{url.to_s.inspect} (#{e}): #{response&.status_line}"
|
50
|
-
|
51
|
+
STDERR.puts "Cannot get #{url.to_s.inspect} (#{e}): #{response&.status_line || 'n/a'}"
|
52
|
+
if @debug && !e.is_a?(RuntimeError)
|
51
53
|
STDERR.puts "#{e.backtrace * ?\n}"
|
52
54
|
end
|
53
|
-
yield
|
55
|
+
yield StringIO.new.extend(ContentType)
|
54
56
|
end
|
55
57
|
|
56
58
|
def headers
|
@@ -1,14 +1,32 @@
|
|
1
1
|
module Ollama::Utils::FileArgument
|
2
2
|
module_function
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
# Returns the contents of a file or string, or a default value if neither is provided.
|
5
|
+
#
|
6
|
+
# @param [String] path_or_content The path to a file or a string containing
|
7
|
+
# the content.
|
8
|
+
#
|
9
|
+
# @param [String] default The default value to return if no valid input is
|
10
|
+
# given. Defaults to nil.
|
11
|
+
#
|
12
|
+
# @return [String] The contents of the file, the string, or the default value.
|
13
|
+
#
|
14
|
+
# @example Get the contents of a file
|
15
|
+
# get_file_argument('path/to/file')
|
16
|
+
#
|
17
|
+
# @example Use a string as content
|
18
|
+
# get_file_argument('string content')
|
19
|
+
#
|
20
|
+
# @example Return a default value if no valid input is given
|
21
|
+
# get_file_argument(nil, default: 'default content')
|
22
|
+
def get_file_argument(path_or_content, default: nil)
|
23
|
+
if path_or_content.present? && path_or_content.size < 2 ** 15 &&
|
24
|
+
File.basename(path_or_content).size < 2 ** 8 &&
|
25
|
+
File.exist?(path_or_content)
|
8
26
|
then
|
9
|
-
File.read(
|
10
|
-
elsif
|
11
|
-
|
27
|
+
File.read(path_or_content)
|
28
|
+
elsif path_or_content.present?
|
29
|
+
path_or_content
|
12
30
|
else
|
13
31
|
default
|
14
32
|
end
|
data/lib/ollama/utils/tags.rb
CHANGED
data/lib/ollama/version.rb
CHANGED
data/ollama-ruby.gemspec
CHANGED
@@ -1,34 +1,35 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: ollama-ruby 0.
|
2
|
+
# stub: ollama-ruby 0.4.0 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "ollama-ruby".freeze
|
6
|
-
s.version = "0.
|
6
|
+
s.version = "0.4.0".freeze
|
7
7
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
9
9
|
s.require_paths = ["lib".freeze]
|
10
10
|
s.authors = ["Florian Frank".freeze]
|
11
|
-
s.date = "2024-09-
|
11
|
+
s.date = "2024-09-21"
|
12
12
|
s.description = "Library that allows interacting with the Ollama API".freeze
|
13
13
|
s.email = "flori@ping.de".freeze
|
14
14
|
s.executables = ["ollama_console".freeze, "ollama_chat".freeze, "ollama_update".freeze, "ollama_cli".freeze]
|
15
|
-
s.extra_rdoc_files = ["README.md".freeze, "lib/ollama.rb".freeze, "lib/ollama/client.rb".freeze, "lib/ollama/client/command.rb".freeze, "lib/ollama/client/doc.rb".freeze, "lib/ollama/commands/chat.rb".freeze, "lib/ollama/commands/copy.rb".freeze, "lib/ollama/commands/create.rb".freeze, "lib/ollama/commands/delete.rb".freeze, "lib/ollama/commands/embed.rb".freeze, "lib/ollama/commands/embeddings.rb".freeze, "lib/ollama/commands/generate.rb".freeze, "lib/ollama/commands/ps.rb".freeze, "lib/ollama/commands/pull.rb".freeze, "lib/ollama/commands/push.rb".freeze, "lib/ollama/commands/show.rb".freeze, "lib/ollama/commands/tags.rb".freeze, "lib/ollama/documents.rb".freeze, "lib/ollama/documents/memory_cache.rb".freeze, "lib/ollama/documents/redis_cache.rb".freeze, "lib/ollama/documents/splitters/character.rb".freeze, "lib/ollama/documents/splitters/semantic.rb".freeze, "lib/ollama/dto.rb".freeze, "lib/ollama/errors.rb".freeze, "lib/ollama/handlers.rb".freeze, "lib/ollama/handlers/collector.rb".freeze, "lib/ollama/handlers/concern.rb".freeze, "lib/ollama/handlers/dump_json.rb".freeze, "lib/ollama/handlers/dump_yaml.rb".freeze, "lib/ollama/handlers/markdown.rb".freeze, "lib/ollama/handlers/nop.rb".freeze, "lib/ollama/handlers/print.rb".freeze, "lib/ollama/handlers/progress.rb".freeze, "lib/ollama/handlers/say.rb".freeze, "lib/ollama/handlers/single.rb".freeze, "lib/ollama/image.rb".freeze, "lib/ollama/message.rb".freeze, "lib/ollama/options.rb".freeze, "lib/ollama/response.rb".freeze, "lib/ollama/tool.rb".freeze, "lib/ollama/tool/function.rb".freeze, "lib/ollama/tool/function/parameters.rb".freeze, "lib/ollama/tool/function/parameters/property.rb".freeze, "lib/ollama/utils/ansi_markdown.rb".freeze, "lib/ollama/utils/chooser.rb".freeze, "lib/ollama/utils/colorize_texts.rb".freeze, "lib/ollama/utils/fetcher.rb".freeze, "lib/ollama/utils/file_argument.rb".freeze, "lib/ollama/utils/math.rb".freeze, "lib/ollama/utils/tags.rb".freeze, "lib/ollama/utils/width.rb".freeze, "lib/ollama/version.rb".freeze]
|
16
|
-
s.files = [".envrc".freeze, "CHANGES.md".freeze, "Gemfile".freeze, "LICENSE".freeze, "README.md".freeze, "Rakefile".freeze, "bin/ollama_chat".freeze, "bin/ollama_cli".freeze, "bin/ollama_console".freeze, "bin/ollama_update".freeze, "config/redis.conf".freeze, "docker-compose.yml".freeze, "lib/ollama.rb".freeze, "lib/ollama/client.rb".freeze, "lib/ollama/client/command.rb".freeze, "lib/ollama/client/doc.rb".freeze, "lib/ollama/commands/chat.rb".freeze, "lib/ollama/commands/copy.rb".freeze, "lib/ollama/commands/create.rb".freeze, "lib/ollama/commands/delete.rb".freeze, "lib/ollama/commands/embed.rb".freeze, "lib/ollama/commands/embeddings.rb".freeze, "lib/ollama/commands/generate.rb".freeze, "lib/ollama/commands/ps.rb".freeze, "lib/ollama/commands/pull.rb".freeze, "lib/ollama/commands/push.rb".freeze, "lib/ollama/commands/show.rb".freeze, "lib/ollama/commands/tags.rb".freeze, "lib/ollama/documents.rb".freeze, "lib/ollama/documents/memory_cache.rb".freeze, "lib/ollama/documents/redis_cache.rb".freeze, "lib/ollama/documents/splitters/character.rb".freeze, "lib/ollama/documents/splitters/semantic.rb".freeze, "lib/ollama/dto.rb".freeze, "lib/ollama/errors.rb".freeze, "lib/ollama/handlers.rb".freeze, "lib/ollama/handlers/collector.rb".freeze, "lib/ollama/handlers/concern.rb".freeze, "lib/ollama/handlers/dump_json.rb".freeze, "lib/ollama/handlers/dump_yaml.rb".freeze, "lib/ollama/handlers/markdown.rb".freeze, "lib/ollama/handlers/nop.rb".freeze, "lib/ollama/handlers/print.rb".freeze, "lib/ollama/handlers/progress.rb".freeze, "lib/ollama/handlers/say.rb".freeze, "lib/ollama/handlers/single.rb".freeze, "lib/ollama/image.rb".freeze, "lib/ollama/message.rb".freeze, "lib/ollama/options.rb".freeze, "lib/ollama/response.rb".freeze, "lib/ollama/tool.rb".freeze, "lib/ollama/tool/function.rb".freeze, "lib/ollama/tool/function/parameters.rb".freeze, "lib/ollama/tool/function/parameters/property.rb".freeze, "lib/ollama/utils/ansi_markdown.rb".freeze, "lib/ollama/utils/chooser.rb".freeze, "lib/ollama/utils/colorize_texts.rb".freeze, "lib/ollama/utils/fetcher.rb".freeze, "lib/ollama/utils/file_argument.rb".freeze, "lib/ollama/utils/math.rb".freeze, "lib/ollama/utils/tags.rb".freeze, "lib/ollama/utils/width.rb".freeze, "lib/ollama/version.rb".freeze, "ollama-ruby.gemspec".freeze, "spec/assets/embeddings.json".freeze, "spec/assets/kitten.jpg".freeze, "spec/ollama/client/doc_spec.rb".freeze, "spec/ollama/client_spec.rb".freeze, "spec/ollama/commands/chat_spec.rb".freeze, "spec/ollama/commands/copy_spec.rb".freeze, "spec/ollama/commands/create_spec.rb".freeze, "spec/ollama/commands/delete_spec.rb".freeze, "spec/ollama/commands/embed_spec.rb".freeze, "spec/ollama/commands/embeddings_spec.rb".freeze, "spec/ollama/commands/generate_spec.rb".freeze, "spec/ollama/commands/ps_spec.rb".freeze, "spec/ollama/commands/pull_spec.rb".freeze, "spec/ollama/commands/push_spec.rb".freeze, "spec/ollama/commands/show_spec.rb".freeze, "spec/ollama/commands/tags_spec.rb".freeze, "spec/ollama/documents/memory_cache_spec.rb".freeze, "spec/ollama/documents/redis_cache_spec.rb".freeze, "spec/ollama/documents/splitters/character_spec.rb".freeze, "spec/ollama/documents/splitters/semantic_spec.rb".freeze, "spec/ollama/documents_spec.rb".freeze, "spec/ollama/handlers/collector_spec.rb".freeze, "spec/ollama/handlers/dump_json_spec.rb".freeze, "spec/ollama/handlers/dump_yaml_spec.rb".freeze, "spec/ollama/handlers/markdown_spec.rb".freeze, "spec/ollama/handlers/nop_spec.rb".freeze, "spec/ollama/handlers/print_spec.rb".freeze, "spec/ollama/handlers/progress_spec.rb".freeze, "spec/ollama/handlers/say_spec.rb".freeze, "spec/ollama/handlers/single_spec.rb".freeze, "spec/ollama/image_spec.rb".freeze, "spec/ollama/message_spec.rb".freeze, "spec/ollama/options_spec.rb".freeze, "spec/ollama/tool_spec.rb".freeze, "spec/ollama/utils/ansi_markdown_spec.rb".freeze, "spec/ollama/utils/fetcher_spec.rb".freeze, "spec/ollama/utils/tags_spec.rb".freeze, "spec/spec_helper.rb".freeze, "tmp/.keep".freeze]
|
15
|
+
s.extra_rdoc_files = ["README.md".freeze, "lib/ollama.rb".freeze, "lib/ollama/client.rb".freeze, "lib/ollama/client/command.rb".freeze, "lib/ollama/client/doc.rb".freeze, "lib/ollama/commands/chat.rb".freeze, "lib/ollama/commands/copy.rb".freeze, "lib/ollama/commands/create.rb".freeze, "lib/ollama/commands/delete.rb".freeze, "lib/ollama/commands/embed.rb".freeze, "lib/ollama/commands/embeddings.rb".freeze, "lib/ollama/commands/generate.rb".freeze, "lib/ollama/commands/ps.rb".freeze, "lib/ollama/commands/pull.rb".freeze, "lib/ollama/commands/push.rb".freeze, "lib/ollama/commands/show.rb".freeze, "lib/ollama/commands/tags.rb".freeze, "lib/ollama/documents.rb".freeze, "lib/ollama/documents/cache/common.rb".freeze, "lib/ollama/documents/cache/memory_cache.rb".freeze, "lib/ollama/documents/cache/redis_backed_memory_cache.rb".freeze, "lib/ollama/documents/cache/redis_cache.rb".freeze, "lib/ollama/documents/splitters/character.rb".freeze, "lib/ollama/documents/splitters/semantic.rb".freeze, "lib/ollama/dto.rb".freeze, "lib/ollama/errors.rb".freeze, "lib/ollama/handlers.rb".freeze, "lib/ollama/handlers/collector.rb".freeze, "lib/ollama/handlers/concern.rb".freeze, "lib/ollama/handlers/dump_json.rb".freeze, "lib/ollama/handlers/dump_yaml.rb".freeze, "lib/ollama/handlers/markdown.rb".freeze, "lib/ollama/handlers/nop.rb".freeze, "lib/ollama/handlers/print.rb".freeze, "lib/ollama/handlers/progress.rb".freeze, "lib/ollama/handlers/say.rb".freeze, "lib/ollama/handlers/single.rb".freeze, "lib/ollama/image.rb".freeze, "lib/ollama/message.rb".freeze, "lib/ollama/options.rb".freeze, "lib/ollama/response.rb".freeze, "lib/ollama/tool.rb".freeze, "lib/ollama/tool/function.rb".freeze, "lib/ollama/tool/function/parameters.rb".freeze, "lib/ollama/tool/function/parameters/property.rb".freeze, "lib/ollama/utils/ansi_markdown.rb".freeze, "lib/ollama/utils/chooser.rb".freeze, "lib/ollama/utils/colorize_texts.rb".freeze, "lib/ollama/utils/fetcher.rb".freeze, "lib/ollama/utils/file_argument.rb".freeze, "lib/ollama/utils/math.rb".freeze, "lib/ollama/utils/tags.rb".freeze, "lib/ollama/utils/width.rb".freeze, "lib/ollama/version.rb".freeze]
|
16
|
+
s.files = [".envrc".freeze, "CHANGES.md".freeze, "Gemfile".freeze, "LICENSE".freeze, "README.md".freeze, "Rakefile".freeze, "bin/ollama_chat".freeze, "bin/ollama_cli".freeze, "bin/ollama_console".freeze, "bin/ollama_update".freeze, "config/redis.conf".freeze, "docker-compose.yml".freeze, "lib/ollama.rb".freeze, "lib/ollama/client.rb".freeze, "lib/ollama/client/command.rb".freeze, "lib/ollama/client/doc.rb".freeze, "lib/ollama/commands/chat.rb".freeze, "lib/ollama/commands/copy.rb".freeze, "lib/ollama/commands/create.rb".freeze, "lib/ollama/commands/delete.rb".freeze, "lib/ollama/commands/embed.rb".freeze, "lib/ollama/commands/embeddings.rb".freeze, "lib/ollama/commands/generate.rb".freeze, "lib/ollama/commands/ps.rb".freeze, "lib/ollama/commands/pull.rb".freeze, "lib/ollama/commands/push.rb".freeze, "lib/ollama/commands/show.rb".freeze, "lib/ollama/commands/tags.rb".freeze, "lib/ollama/documents.rb".freeze, "lib/ollama/documents/cache/common.rb".freeze, "lib/ollama/documents/cache/memory_cache.rb".freeze, "lib/ollama/documents/cache/redis_backed_memory_cache.rb".freeze, "lib/ollama/documents/cache/redis_cache.rb".freeze, "lib/ollama/documents/splitters/character.rb".freeze, "lib/ollama/documents/splitters/semantic.rb".freeze, "lib/ollama/dto.rb".freeze, "lib/ollama/errors.rb".freeze, "lib/ollama/handlers.rb".freeze, "lib/ollama/handlers/collector.rb".freeze, "lib/ollama/handlers/concern.rb".freeze, "lib/ollama/handlers/dump_json.rb".freeze, "lib/ollama/handlers/dump_yaml.rb".freeze, "lib/ollama/handlers/markdown.rb".freeze, "lib/ollama/handlers/nop.rb".freeze, "lib/ollama/handlers/print.rb".freeze, "lib/ollama/handlers/progress.rb".freeze, "lib/ollama/handlers/say.rb".freeze, "lib/ollama/handlers/single.rb".freeze, "lib/ollama/image.rb".freeze, "lib/ollama/message.rb".freeze, "lib/ollama/options.rb".freeze, "lib/ollama/response.rb".freeze, "lib/ollama/tool.rb".freeze, "lib/ollama/tool/function.rb".freeze, "lib/ollama/tool/function/parameters.rb".freeze, "lib/ollama/tool/function/parameters/property.rb".freeze, "lib/ollama/utils/ansi_markdown.rb".freeze, "lib/ollama/utils/chooser.rb".freeze, "lib/ollama/utils/colorize_texts.rb".freeze, "lib/ollama/utils/fetcher.rb".freeze, "lib/ollama/utils/file_argument.rb".freeze, "lib/ollama/utils/math.rb".freeze, "lib/ollama/utils/tags.rb".freeze, "lib/ollama/utils/width.rb".freeze, "lib/ollama/version.rb".freeze, "ollama-ruby.gemspec".freeze, "spec/assets/embeddings.json".freeze, "spec/assets/kitten.jpg".freeze, "spec/assets/prompt.txt".freeze, "spec/ollama/client/doc_spec.rb".freeze, "spec/ollama/client_spec.rb".freeze, "spec/ollama/commands/chat_spec.rb".freeze, "spec/ollama/commands/copy_spec.rb".freeze, "spec/ollama/commands/create_spec.rb".freeze, "spec/ollama/commands/delete_spec.rb".freeze, "spec/ollama/commands/embed_spec.rb".freeze, "spec/ollama/commands/embeddings_spec.rb".freeze, "spec/ollama/commands/generate_spec.rb".freeze, "spec/ollama/commands/ps_spec.rb".freeze, "spec/ollama/commands/pull_spec.rb".freeze, "spec/ollama/commands/push_spec.rb".freeze, "spec/ollama/commands/show_spec.rb".freeze, "spec/ollama/commands/tags_spec.rb".freeze, "spec/ollama/documents/memory_cache_spec.rb".freeze, "spec/ollama/documents/redis_backed_memory_cache_spec.rb".freeze, "spec/ollama/documents/redis_cache_spec.rb".freeze, "spec/ollama/documents/splitters/character_spec.rb".freeze, "spec/ollama/documents/splitters/semantic_spec.rb".freeze, "spec/ollama/documents_spec.rb".freeze, "spec/ollama/handlers/collector_spec.rb".freeze, "spec/ollama/handlers/dump_json_spec.rb".freeze, "spec/ollama/handlers/dump_yaml_spec.rb".freeze, "spec/ollama/handlers/markdown_spec.rb".freeze, "spec/ollama/handlers/nop_spec.rb".freeze, "spec/ollama/handlers/print_spec.rb".freeze, "spec/ollama/handlers/progress_spec.rb".freeze, "spec/ollama/handlers/say_spec.rb".freeze, "spec/ollama/handlers/single_spec.rb".freeze, "spec/ollama/image_spec.rb".freeze, "spec/ollama/message_spec.rb".freeze, "spec/ollama/options_spec.rb".freeze, "spec/ollama/tool_spec.rb".freeze, "spec/ollama/utils/ansi_markdown_spec.rb".freeze, "spec/ollama/utils/fetcher_spec.rb".freeze, "spec/ollama/utils/file_argument_spec.rb".freeze, "spec/ollama/utils/tags_spec.rb".freeze, "spec/spec_helper.rb".freeze, "tmp/.keep".freeze]
|
17
17
|
s.homepage = "https://github.com/flori/ollama-ruby".freeze
|
18
18
|
s.licenses = ["MIT".freeze]
|
19
19
|
s.rdoc_options = ["--title".freeze, "Ollama-ruby - Interacting with the Ollama API".freeze, "--main".freeze, "README.md".freeze]
|
20
20
|
s.required_ruby_version = Gem::Requirement.new("~> 3.1".freeze)
|
21
21
|
s.rubygems_version = "3.5.18".freeze
|
22
22
|
s.summary = "Interacting with the Ollama API".freeze
|
23
|
-
s.test_files = ["spec/ollama/client/doc_spec.rb".freeze, "spec/ollama/client_spec.rb".freeze, "spec/ollama/commands/chat_spec.rb".freeze, "spec/ollama/commands/copy_spec.rb".freeze, "spec/ollama/commands/create_spec.rb".freeze, "spec/ollama/commands/delete_spec.rb".freeze, "spec/ollama/commands/embed_spec.rb".freeze, "spec/ollama/commands/embeddings_spec.rb".freeze, "spec/ollama/commands/generate_spec.rb".freeze, "spec/ollama/commands/ps_spec.rb".freeze, "spec/ollama/commands/pull_spec.rb".freeze, "spec/ollama/commands/push_spec.rb".freeze, "spec/ollama/commands/show_spec.rb".freeze, "spec/ollama/commands/tags_spec.rb".freeze, "spec/ollama/documents/memory_cache_spec.rb".freeze, "spec/ollama/documents/redis_cache_spec.rb".freeze, "spec/ollama/documents/splitters/character_spec.rb".freeze, "spec/ollama/documents/splitters/semantic_spec.rb".freeze, "spec/ollama/documents_spec.rb".freeze, "spec/ollama/handlers/collector_spec.rb".freeze, "spec/ollama/handlers/dump_json_spec.rb".freeze, "spec/ollama/handlers/dump_yaml_spec.rb".freeze, "spec/ollama/handlers/markdown_spec.rb".freeze, "spec/ollama/handlers/nop_spec.rb".freeze, "spec/ollama/handlers/print_spec.rb".freeze, "spec/ollama/handlers/progress_spec.rb".freeze, "spec/ollama/handlers/say_spec.rb".freeze, "spec/ollama/handlers/single_spec.rb".freeze, "spec/ollama/image_spec.rb".freeze, "spec/ollama/message_spec.rb".freeze, "spec/ollama/options_spec.rb".freeze, "spec/ollama/tool_spec.rb".freeze, "spec/ollama/utils/ansi_markdown_spec.rb".freeze, "spec/ollama/utils/fetcher_spec.rb".freeze, "spec/ollama/utils/tags_spec.rb".freeze, "spec/spec_helper.rb".freeze]
|
23
|
+
s.test_files = ["spec/ollama/client/doc_spec.rb".freeze, "spec/ollama/client_spec.rb".freeze, "spec/ollama/commands/chat_spec.rb".freeze, "spec/ollama/commands/copy_spec.rb".freeze, "spec/ollama/commands/create_spec.rb".freeze, "spec/ollama/commands/delete_spec.rb".freeze, "spec/ollama/commands/embed_spec.rb".freeze, "spec/ollama/commands/embeddings_spec.rb".freeze, "spec/ollama/commands/generate_spec.rb".freeze, "spec/ollama/commands/ps_spec.rb".freeze, "spec/ollama/commands/pull_spec.rb".freeze, "spec/ollama/commands/push_spec.rb".freeze, "spec/ollama/commands/show_spec.rb".freeze, "spec/ollama/commands/tags_spec.rb".freeze, "spec/ollama/documents/memory_cache_spec.rb".freeze, "spec/ollama/documents/redis_backed_memory_cache_spec.rb".freeze, "spec/ollama/documents/redis_cache_spec.rb".freeze, "spec/ollama/documents/splitters/character_spec.rb".freeze, "spec/ollama/documents/splitters/semantic_spec.rb".freeze, "spec/ollama/documents_spec.rb".freeze, "spec/ollama/handlers/collector_spec.rb".freeze, "spec/ollama/handlers/dump_json_spec.rb".freeze, "spec/ollama/handlers/dump_yaml_spec.rb".freeze, "spec/ollama/handlers/markdown_spec.rb".freeze, "spec/ollama/handlers/nop_spec.rb".freeze, "spec/ollama/handlers/print_spec.rb".freeze, "spec/ollama/handlers/progress_spec.rb".freeze, "spec/ollama/handlers/say_spec.rb".freeze, "spec/ollama/handlers/single_spec.rb".freeze, "spec/ollama/image_spec.rb".freeze, "spec/ollama/message_spec.rb".freeze, "spec/ollama/options_spec.rb".freeze, "spec/ollama/tool_spec.rb".freeze, "spec/ollama/utils/ansi_markdown_spec.rb".freeze, "spec/ollama/utils/fetcher_spec.rb".freeze, "spec/ollama/utils/file_argument_spec.rb".freeze, "spec/ollama/utils/tags_spec.rb".freeze, "spec/spec_helper.rb".freeze]
|
24
24
|
|
25
25
|
s.specification_version = 4
|
26
26
|
|
27
27
|
s.add_development_dependency(%q<gem_hadar>.freeze, ["~> 1.17.1".freeze])
|
28
28
|
s.add_development_dependency(%q<all_images>.freeze, ["~> 0.4".freeze])
|
29
29
|
s.add_development_dependency(%q<rspec>.freeze, ["~> 3.2".freeze])
|
30
|
-
s.add_development_dependency(%q<utils>.freeze, [">= 0".freeze])
|
31
30
|
s.add_development_dependency(%q<webmock>.freeze, [">= 0".freeze])
|
31
|
+
s.add_development_dependency(%q<debug>.freeze, [">= 0".freeze])
|
32
|
+
s.add_development_dependency(%q<simplecov>.freeze, [">= 0".freeze])
|
32
33
|
s.add_runtime_dependency(%q<excon>.freeze, ["~> 0.111".freeze])
|
33
34
|
s.add_runtime_dependency(%q<infobar>.freeze, ["~> 0.8".freeze])
|
34
35
|
s.add_runtime_dependency(%q<term-ansicolor>.freeze, ["~> 1.11".freeze])
|
@@ -0,0 +1 @@
|
|
1
|
+
You are a test prompt just used for testing.
|
@@ -1,63 +1,63 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
RSpec.describe Ollama::Documents::MemoryCache do
|
4
|
-
let :
|
4
|
+
let :cache do
|
5
5
|
described_class.new prefix: 'test-'
|
6
6
|
end
|
7
7
|
|
8
8
|
it 'can be instantiated' do
|
9
|
-
expect(
|
9
|
+
expect(cache).to be_a described_class
|
10
10
|
end
|
11
11
|
|
12
12
|
it 'can get/set a key' do
|
13
13
|
key, value = 'foo', { test: true }
|
14
14
|
expect {
|
15
|
-
|
15
|
+
cache[key] = value
|
16
16
|
}.to change {
|
17
|
-
|
17
|
+
cache[key]
|
18
18
|
}.from(nil).to(value)
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'can determine if key exists' do
|
22
22
|
key, value = 'foo', { test: true }
|
23
23
|
expect {
|
24
|
-
|
24
|
+
cache[key] = value
|
25
25
|
}.to change {
|
26
|
-
|
26
|
+
cache.key?(key)
|
27
27
|
}.from(false).to(true)
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'can delete' do
|
31
31
|
key, value = 'foo', { test: true }
|
32
|
-
|
32
|
+
cache[key] = value
|
33
33
|
expect {
|
34
|
-
|
34
|
+
cache.delete(key)
|
35
35
|
}.to change {
|
36
|
-
|
36
|
+
cache.key?(key)
|
37
37
|
}.from(true).to(false)
|
38
38
|
end
|
39
39
|
|
40
40
|
it 'returns size' do
|
41
41
|
key, value = 'foo', { test: true }
|
42
42
|
expect {
|
43
|
-
|
43
|
+
cache[key] = value
|
44
44
|
}.to change {
|
45
|
-
|
45
|
+
cache.size
|
46
46
|
}.from(0).to(1)
|
47
47
|
end
|
48
48
|
|
49
49
|
it 'can clear' do
|
50
50
|
key, value = 'foo', { test: true }
|
51
|
-
|
51
|
+
cache[key] = value
|
52
52
|
expect {
|
53
|
-
expect(
|
53
|
+
expect(cache.clear).to eq cache
|
54
54
|
}.to change {
|
55
|
-
|
55
|
+
cache.size
|
56
56
|
}.from(1).to(0)
|
57
57
|
end
|
58
58
|
|
59
59
|
it 'can iterate over keys under a prefix' do
|
60
|
-
|
61
|
-
expect(
|
60
|
+
cache['foo'] = 'bar'
|
61
|
+
expect(cache.to_a).to eq [ %w[ test-foo bar ] ]
|
62
62
|
end
|
63
63
|
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Ollama::Documents::RedisBackedMemoryCache do
|
4
|
+
it 'raises ArgumentError if url is missing' do
|
5
|
+
expect {
|
6
|
+
described_class.new prefix: 'test-', url: nil
|
7
|
+
}.to raise_error ArgumentError
|
8
|
+
end
|
9
|
+
|
10
|
+
context 'test redis interactions' do
|
11
|
+
let :cache do
|
12
|
+
described_class.new prefix: 'test-', url: 'something'
|
13
|
+
end
|
14
|
+
|
15
|
+
let :data do
|
16
|
+
cache.instance_eval { @data }
|
17
|
+
end
|
18
|
+
|
19
|
+
let :redis_cache do
|
20
|
+
cache.instance_eval { @redis_cache }
|
21
|
+
end
|
22
|
+
|
23
|
+
let :redis do
|
24
|
+
double('Redis')
|
25
|
+
end
|
26
|
+
|
27
|
+
before do
|
28
|
+
allow_any_instance_of(Ollama::Documents::RedisCache).to\
|
29
|
+
receive(:redis).and_return(redis)
|
30
|
+
allow(redis).to receive(:scan_each)
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'can be instantiated and initialized' do
|
34
|
+
cache = described_class.new prefix: 'test-', url: 'something'
|
35
|
+
expect(cache).to be_a described_class
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'has Redis client' do
|
39
|
+
expect(cache.redis).to eq redis
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'can get a key' do
|
43
|
+
key = 'foo'
|
44
|
+
expect(data).to receive(:[]).with('test-' + key).and_return 666
|
45
|
+
expect(cache[key]).to eq 666
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'can set a value for a key' do
|
49
|
+
key, value = 'foo', { test: true }
|
50
|
+
expect(data).to receive(:[]=).with('test-' + key, { test: true }).and_call_original
|
51
|
+
expect(redis).to receive(:set).with('test-' + key, JSON(value))
|
52
|
+
cache[key] = value
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'can determine if key exists' do
|
56
|
+
key = 'foo'
|
57
|
+
expect(data).to receive(:key?).with('test-' + key).and_return(false, true)
|
58
|
+
expect(cache.key?('foo')).to eq false
|
59
|
+
expect(cache.key?('foo')).to eq true
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'can delete' do
|
63
|
+
key = 'foo'
|
64
|
+
expect(data).to receive(:delete).with('test-' + key)
|
65
|
+
expect(redis).to receive(:del).with('test-' + key)
|
66
|
+
cache.delete(key)
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'returns size' do
|
70
|
+
allow(cache).to receive(:count).and_return 3
|
71
|
+
expect(cache.size).to eq 3
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'can clear' do
|
75
|
+
expect(redis).to receive(:scan_each).with(match: 'test-*').and_yield(
|
76
|
+
'test-foo'
|
77
|
+
)
|
78
|
+
expect(redis).to receive(:del).with('test-foo')
|
79
|
+
expect(cache.clear).to eq cache
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'can iterate over keys under a prefix' do
|
83
|
+
data['test-foo'] = 'bar'
|
84
|
+
expect(cache.to_a).to eq [ %w[ test-foo bar ] ]
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'can compute prefix with pre' do
|
88
|
+
expect(cache.pre('foo')).to eq 'test-foo'
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'can remove prefix with unpre' do
|
92
|
+
expect(cache.unpre('test-foo')).to eq 'foo'
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -2,8 +2,8 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
RSpec.describe Ollama::Documents::RedisCache do
|
4
4
|
it 'can be instantiated' do
|
5
|
-
|
6
|
-
expect(
|
5
|
+
cache = described_class.new prefix: 'test-', url: 'something'
|
6
|
+
expect(cache).to be_a described_class
|
7
7
|
end
|
8
8
|
|
9
9
|
it 'raises ArgumentError if url is missing' do
|
@@ -13,7 +13,7 @@ RSpec.describe Ollama::Documents::RedisCache do
|
|
13
13
|
end
|
14
14
|
|
15
15
|
context 'test redis interactions' do
|
16
|
-
let :
|
16
|
+
let :cache do
|
17
17
|
described_class.new prefix: 'test-', url: 'something'
|
18
18
|
end
|
19
19
|
|
@@ -26,32 +26,32 @@ RSpec.describe Ollama::Documents::RedisCache do
|
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'has Redis client' do
|
29
|
-
expect(
|
29
|
+
expect(cache.redis).to eq redis
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'can get a key' do
|
33
33
|
key = 'foo'
|
34
|
-
expect(redis).to receive(:get).with('test-' + key).and_return
|
35
|
-
|
34
|
+
expect(redis).to receive(:get).with('test-' + key).and_return '"some_json"'
|
35
|
+
expect(cache[key]).to eq 'some_json'
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'can set a value for a key' do
|
39
39
|
key, value = 'foo', { test: true }
|
40
40
|
expect(redis).to receive(:set).with('test-' + key, JSON(value))
|
41
|
-
|
41
|
+
cache[key] = value
|
42
42
|
end
|
43
43
|
|
44
44
|
it 'can determine if key exists' do
|
45
45
|
key = 'foo'
|
46
46
|
expect(redis).to receive(:exists?).with('test-' + key).and_return(false, true)
|
47
|
-
expect(
|
48
|
-
expect(
|
47
|
+
expect(cache.key?('foo')).to eq false
|
48
|
+
expect(cache.key?('foo')).to eq true
|
49
49
|
end
|
50
50
|
|
51
51
|
it 'can delete' do
|
52
52
|
key = 'foo'
|
53
53
|
expect(redis).to receive(:del).with('test-' + key)
|
54
|
-
|
54
|
+
cache.delete(key)
|
55
55
|
end
|
56
56
|
|
57
57
|
it 'returns size' do
|
@@ -59,7 +59,7 @@ RSpec.describe Ollama::Documents::RedisCache do
|
|
59
59
|
and_yield('test-foo').
|
60
60
|
and_yield('test-bar').
|
61
61
|
and_yield('test-baz')
|
62
|
-
expect(
|
62
|
+
expect(cache.size).to eq 3
|
63
63
|
end
|
64
64
|
|
65
65
|
it 'can clear' do
|
@@ -67,20 +67,20 @@ RSpec.describe Ollama::Documents::RedisCache do
|
|
67
67
|
'test-foo'
|
68
68
|
)
|
69
69
|
expect(redis).to receive(:del).with('test-foo')
|
70
|
-
expect(
|
70
|
+
expect(cache.clear).to eq cache
|
71
71
|
end
|
72
72
|
|
73
73
|
it 'can iterate over keys under a prefix' do
|
74
74
|
expect(redis).to receive(:scan_each).with(match: 'test-*')
|
75
|
-
|
75
|
+
cache.to_a
|
76
76
|
end
|
77
77
|
|
78
78
|
it 'can compute prefix with pre' do
|
79
|
-
expect(
|
79
|
+
expect(cache.pre('foo')).to eq 'test-foo'
|
80
80
|
end
|
81
81
|
|
82
82
|
it 'can remove prefix with unpre' do
|
83
|
-
expect(
|
83
|
+
expect(cache.unpre('test-foo')).to eq 'foo'
|
84
84
|
end
|
85
85
|
end
|
86
86
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Ollama::Utils::FileArgument do
|
4
|
+
it 'it can return content' do
|
5
|
+
expect(described_class.get_file_argument('foo')).to eq 'foo'
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'it can return content at path' do
|
9
|
+
expect(described_class.get_file_argument(asset('prompt.txt'))).to include\
|
10
|
+
'test prompt'
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'it can return default content' do
|
14
|
+
expect(described_class.get_file_argument('', default: 'foo')).to eq 'foo'
|
15
|
+
expect(described_class.get_file_argument(nil, default: 'foo')).to eq 'foo'
|
16
|
+
end
|
17
|
+
end
|
@@ -6,7 +6,7 @@ RSpec.describe Ollama::Utils::Tags do
|
|
6
6
|
end
|
7
7
|
|
8
8
|
it 'can contain unique tags and is sorted' do
|
9
|
-
tags = described_class.new([
|
9
|
+
tags = described_class.new(%w[ bar foo ])
|
10
10
|
expect(tags.to_a).to eq %w[ bar foo ]
|
11
11
|
end
|
12
12
|
|
@@ -14,11 +14,11 @@ RSpec.describe Ollama::Utils::Tags do
|
|
14
14
|
tags = described_class.new([ 'foo' ])
|
15
15
|
tags.add 'bar'
|
16
16
|
expect(tags.to_a).to eq %w[ bar foo ]
|
17
|
-
tags.merge [
|
17
|
+
tags.merge %w[ baz baz2 ]
|
18
18
|
expect(tags.to_a).to eq %w[ bar baz baz2 foo ]
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'can be output nicely' do
|
22
|
-
expect(described_class.new(%w[foo bar]).to_s).to eq '#bar #foo'
|
22
|
+
expect(described_class.new(%w[ foo bar ]).to_s).to eq '#bar #foo'
|
23
23
|
end
|
24
24
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ollama-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florian Frank
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-09-
|
11
|
+
date: 2024-09-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gem_hadar
|
@@ -53,7 +53,7 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.2'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: webmock
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
@@ -67,7 +67,21 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: debug
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
72
86
|
requirements:
|
73
87
|
- - ">="
|
@@ -317,8 +331,10 @@ extra_rdoc_files:
|
|
317
331
|
- lib/ollama/commands/show.rb
|
318
332
|
- lib/ollama/commands/tags.rb
|
319
333
|
- lib/ollama/documents.rb
|
320
|
-
- lib/ollama/documents/
|
321
|
-
- lib/ollama/documents/
|
334
|
+
- lib/ollama/documents/cache/common.rb
|
335
|
+
- lib/ollama/documents/cache/memory_cache.rb
|
336
|
+
- lib/ollama/documents/cache/redis_backed_memory_cache.rb
|
337
|
+
- lib/ollama/documents/cache/redis_cache.rb
|
322
338
|
- lib/ollama/documents/splitters/character.rb
|
323
339
|
- lib/ollama/documents/splitters/semantic.rb
|
324
340
|
- lib/ollama/dto.rb
|
@@ -381,8 +397,10 @@ files:
|
|
381
397
|
- lib/ollama/commands/show.rb
|
382
398
|
- lib/ollama/commands/tags.rb
|
383
399
|
- lib/ollama/documents.rb
|
384
|
-
- lib/ollama/documents/
|
385
|
-
- lib/ollama/documents/
|
400
|
+
- lib/ollama/documents/cache/common.rb
|
401
|
+
- lib/ollama/documents/cache/memory_cache.rb
|
402
|
+
- lib/ollama/documents/cache/redis_backed_memory_cache.rb
|
403
|
+
- lib/ollama/documents/cache/redis_cache.rb
|
386
404
|
- lib/ollama/documents/splitters/character.rb
|
387
405
|
- lib/ollama/documents/splitters/semantic.rb
|
388
406
|
- lib/ollama/dto.rb
|
@@ -418,6 +436,7 @@ files:
|
|
418
436
|
- ollama-ruby.gemspec
|
419
437
|
- spec/assets/embeddings.json
|
420
438
|
- spec/assets/kitten.jpg
|
439
|
+
- spec/assets/prompt.txt
|
421
440
|
- spec/ollama/client/doc_spec.rb
|
422
441
|
- spec/ollama/client_spec.rb
|
423
442
|
- spec/ollama/commands/chat_spec.rb
|
@@ -433,6 +452,7 @@ files:
|
|
433
452
|
- spec/ollama/commands/show_spec.rb
|
434
453
|
- spec/ollama/commands/tags_spec.rb
|
435
454
|
- spec/ollama/documents/memory_cache_spec.rb
|
455
|
+
- spec/ollama/documents/redis_backed_memory_cache_spec.rb
|
436
456
|
- spec/ollama/documents/redis_cache_spec.rb
|
437
457
|
- spec/ollama/documents/splitters/character_spec.rb
|
438
458
|
- spec/ollama/documents/splitters/semantic_spec.rb
|
@@ -452,6 +472,7 @@ files:
|
|
452
472
|
- spec/ollama/tool_spec.rb
|
453
473
|
- spec/ollama/utils/ansi_markdown_spec.rb
|
454
474
|
- spec/ollama/utils/fetcher_spec.rb
|
475
|
+
- spec/ollama/utils/file_argument_spec.rb
|
455
476
|
- spec/ollama/utils/tags_spec.rb
|
456
477
|
- spec/spec_helper.rb
|
457
478
|
- tmp/.keep
|
@@ -498,6 +519,7 @@ test_files:
|
|
498
519
|
- spec/ollama/commands/show_spec.rb
|
499
520
|
- spec/ollama/commands/tags_spec.rb
|
500
521
|
- spec/ollama/documents/memory_cache_spec.rb
|
522
|
+
- spec/ollama/documents/redis_backed_memory_cache_spec.rb
|
501
523
|
- spec/ollama/documents/redis_cache_spec.rb
|
502
524
|
- spec/ollama/documents/splitters/character_spec.rb
|
503
525
|
- spec/ollama/documents/splitters/semantic_spec.rb
|
@@ -517,5 +539,6 @@ test_files:
|
|
517
539
|
- spec/ollama/tool_spec.rb
|
518
540
|
- spec/ollama/utils/ansi_markdown_spec.rb
|
519
541
|
- spec/ollama/utils/fetcher_spec.rb
|
542
|
+
- spec/ollama/utils/file_argument_spec.rb
|
520
543
|
- spec/ollama/utils/tags_spec.rb
|
521
544
|
- spec/spec_helper.rb
|