foobara-ollama-api 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a7432f72bdbe66ce8ed9adb5d22a69a74e47346c10bf0a2cb56de459d547ae19
4
- data.tar.gz: 3d632f7b7360eaf2ffe25f5dd1089ac82964cccc28c1afbc95ee7c89f3b71b7a
3
+ metadata.gz: 45199e4e73bda800594bae3a39b3f7bc81b06d86cc90ddc40e39981533900ced
4
+ data.tar.gz: 33d0789f0dc41abf5de8ed0e686a4be772bd003077432c66a35a0c219e2ae86d
5
5
  SHA512:
6
- metadata.gz: 76838ec17ebc03802784e983a817be7dcdf891b6187ac467891a274da15a131a73f516faf385f5f7a2db66acbdc03d37cf875b4e163bd666d4daa3995cc0219f
7
- data.tar.gz: eb422d4336d8b89fdc4fde88ef29c25329fa3f8bb072869ca855d95db625cd56411fc1aa133d33020c378758d7dd2a09c027eb86fde104e8791f2a8c57f0a5f2
6
+ metadata.gz: d174d2f705b82c05332eba7f4288ffeb8fa8117eeb03193b262b7382f60d41f7059eaa40d7c7f6c6cf18b77efe98be68fcf7eb9fb26a9d1db42574ee007e45df
7
+ data.tar.gz: 6d464afc7ae0587a0fc51f20a7673136fcbaeabb1166acdd37098328d6e0f01ba94bcefd55ea495a20778affd11e471d32629d636e6a11e7336ba2a83c10c138
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## [0.0.3] - 2025-02-27
2
+
3
+ - Increase timeout to 10 minutes
4
+
5
+ ## [0.0.2] - 2025-02-25
6
+
7
+ - Add a ModelEnum as :model
8
+
1
9
  ## [0.0.1] - 2025-02-08
2
10
 
3
11
  - Initial release
data/README.md CHANGED
@@ -11,15 +11,32 @@ your .gemspec file. Or even just `gem install foobara-ollama-api` if just playin
11
11
 
12
12
  An example usage:
13
13
 
14
- ```ruby
14
+ ```irb
15
15
  irb(main):001> require "foobara/ollama_api"
16
16
  => true
17
- irb(main):002> chat_completion = Foobara::OllamaApi::GenerateChatCompletion.run!(
18
- model: "llama3:8b",
19
- messages: [{ role: "user", content: "What is the PH of honey?" }]
20
- )
21
- irb(main):003> puts chat_completion.message.content
22
- => The pH of honey is 3.2 to 4.5 (slightly acidic.)
17
+ irb(main):002* chat_completion = Foobara::Ai::OllamaApi::GenerateChatCompletion.run!(
18
+ irb(main):003* model: "llama3:8b",
19
+ irb(main):004* messages: [{ role: "user", content: "What is the PH of honey?" }]
20
+ irb(main):005> )
21
+ => #<Foobara::Ai::OllamaApi::ChatCompletion:0x00007fae1e61a868...
22
+ irb(main):006> puts chat_completion.message.content
23
+ A sweet question!
24
+
25
+ The pH of honey can vary depending on several factors, such as the type of flowers that the bees collect nectar from, the region where the honey is produced, and the processing methods used.
26
+
27
+ Generally, the pH of honey ranges from slightly acidic to neutral. Here are some approximate pH values for different types of honey:
28
+
29
+ * Clover honey: pH 3.2-4.5
30
+ * Orange blossom honey: pH 3.5-4.8
31
+ * Tupelo honey: pH 4.0-5.0
32
+ * Manuka honey: pH 4.5-5.5
33
+ * Wildflower honey: pH 3.5-5.0
34
+
35
+ On average, the pH of honey is around 4.2 to 4.5, which is slightly acidic to neutral. This is because honey contains small amounts of acids, such as gluconic acid and lactic acid, which are produced during fermentation by the bees.
36
+
37
+ It's worth noting that some types of honey, like Manuka honey, have a higher pH due to the presence of methylglyoxal (MGO), a compound that contributes to their unique properties.
38
+ => nil
39
+ irb(main):007>
23
40
  ```
24
41
 
25
42
  ## Contributing
@@ -4,4 +4,6 @@ require "uri"
4
4
  require "foobara/all"
5
5
  require "foobara/http_api_command"
6
6
 
7
+ require_relative "../../src/foobara/ai/ollama_api"
8
+
7
9
  Foobara::Util.require_directory "#{__dir__}/../../src"
@@ -2,7 +2,9 @@ module Foobara
2
2
  module Ai
3
3
  module OllamaApi
4
4
  class BaseCommand < Foobara::Command
5
- include Concerns::Url
5
+ include HttpApiCommand
6
+
7
+ base_url { "#{ENV["OLLAMA_API_URL"] || "http://localhost:11434"}/api" }
6
8
  end
7
9
  end
8
10
  end
@@ -1,17 +1,19 @@
1
- require_relative "base_post_command"
1
+ require_relative "base_command"
2
2
 
3
3
  module Foobara
4
4
  module Ai
5
5
  module OllamaApi
6
- class GenerateChatCompletion < BasePostCommand
6
+ class GenerateChatCompletion < BaseCommand
7
7
  inputs do
8
- model :string, :required # TODO: make a model type
9
- messages [Message], :required
8
+ model :model, :required
9
+ messages [Types::Message], :required
10
10
  end
11
11
 
12
- result ChatCompletion
12
+ result Types::ChatCompletion
13
13
 
14
- path "chat"
14
+ path "/chat"
15
+ http_method :post
16
+ http_timeout 600
15
17
 
16
18
  def build_request_body
17
19
  self.request_body = inputs.merge(stream: false)
@@ -3,10 +3,10 @@ require_relative "base_command"
3
3
  module Foobara
4
4
  module Ai
5
5
  module OllamaApi
6
- class ListLocalModels < BaseGetCommand
7
- result [LocalModel]
6
+ class ListLocalModels < BaseCommand
7
+ result [Types::LocalModel]
8
8
 
9
- path "tags"
9
+ path "/tags"
10
10
 
11
11
  def build_result
12
12
  response_body["models"]
@@ -1,12 +1,12 @@
1
- require_relative "base_get_command"
1
+ require_relative "base_command"
2
2
 
3
3
  module Foobara
4
4
  module Ai
5
5
  module OllamaApi
6
- class ListRunningModels < BaseGetCommand
7
- result [RunningModel]
6
+ class ListRunningModels < BaseCommand
7
+ result [Types::RunningModel]
8
8
 
9
- path "ps"
9
+ path "/ps"
10
10
 
11
11
  def build_result
12
12
  response_body["models"]
@@ -3,20 +3,22 @@ require_relative "message"
3
3
  module Foobara
4
4
  module Ai
5
5
  module OllamaApi
6
- class ChatCompletion < Foobara::Model
7
- attributes do
8
- model :string, :required # TODO: Make a model type
9
- created_at :datetime, :required
10
- message Message, :required
11
- done :boolean, :required
12
- total_duration :integer, :required # TODO: should we have a timespan type?
13
- load_duration :integer, :required
14
- prompt_eval_count :integer, :required
15
- prompt_eval_duration :integer, :required
16
- eval_count :integer, :required
17
- eval_duration :integer, :required
18
- # TODO: this one isn't documented for some reason
19
- done_reason :string # TODO: create an enum type for this
6
+ module Types
7
+ class ChatCompletion < Foobara::Model
8
+ attributes do
9
+ model :string, :required # TODO: Make a model type
10
+ created_at :datetime, :required
11
+ message Message, :required
12
+ done :boolean, :required
13
+ total_duration :integer, :required # TODO: should we have a timespan type?
14
+ load_duration :integer, :required
15
+ prompt_eval_count :integer, :required
16
+ prompt_eval_duration :integer, :required
17
+ eval_count :integer, :required
18
+ eval_duration :integer, :required
19
+ # TODO: this one isn't documented for some reason
20
+ done_reason :string # TODO: create an enum type for this
21
+ end
20
22
  end
21
23
  end
22
24
  end
@@ -1,9 +1,13 @@
1
+ require_relative "model"
2
+
1
3
  module Foobara
2
4
  module Ai
3
5
  module OllamaApi
4
- class LocalModel < OllamaApi::Model
5
- attributes do
6
- modified_at :datetime, :required
6
+ module Types
7
+ class LocalModel < Model
8
+ attributes do
9
+ modified_at :datetime, :required
10
+ end
7
11
  end
8
12
  end
9
13
  end
@@ -1,12 +1,14 @@
1
1
  module Foobara
2
2
  module Ai
3
3
  module OllamaApi
4
- class Message < Foobara::Model
5
- attributes do
6
- content :string, :required
7
- role :string, :required # TODO: make a role type
8
- images [:string] # TODO: make a base 64 image type
9
- tool_calls :duck # TODO: make a tool calls type
4
+ module Types
5
+ class Message < Foobara::Model
6
+ attributes do
7
+ content :string, :required
8
+ role :string, :required # TODO: make a role type
9
+ images [:string] # TODO: make a base 64 image type
10
+ tool_calls :duck # TODO: make a tool calls type
11
+ end
10
12
  end
11
13
  end
12
14
  end
@@ -1,15 +1,17 @@
1
1
  module Foobara
2
2
  module Ai
3
3
  module OllamaApi
4
- class Model < Foobara::Model
5
- class Details < Foobara::Model
6
- attributes do
7
- parent_model :string, :required # TODO: should this be real model names?
8
- format :string, :required # TODO: what are the valid values for this?
9
- family :string, :required # TODO: what are the valid values for this?
10
- families [:string], :required # TODO: what are the valid values for this?
11
- parameter_size :string, :required # TODO: should we have a type to encapsulate 7.2B? Can just be a decimal?
12
- quantization_level :string, :required # TODO: what are the valid values for this?
4
+ module Types
5
+ class Model < Foobara::Model
6
+ class Details < Foobara::Model
7
+ attributes do
8
+ parent_model :string, :required # TODO: should this be real model names?
9
+ format :string, :required # TODO: what are the valid values for this?
10
+ family :string, :required # TODO: what are the valid values for this?
11
+ families [:string], :required # TODO: what are the valid values for this?
12
+ parameter_size :string, :required # TODO: should we have a type to encapsulate 7.2B? Can be a decimal?
13
+ quantization_level :string, :required # TODO: what are the valid values for this?
14
+ end
13
15
  end
14
16
  end
15
17
  end
@@ -3,13 +3,15 @@ require_relative "model/details"
3
3
  module Foobara
4
4
  module Ai
5
5
  module OllamaApi
6
- class Model < Foobara::Model
7
- attributes do
8
- name :string, :required # TODO: what are the valid values for this?
9
- model :string, :required # TODO: what are the valid values for this?
10
- size :integer, :required
11
- digest :string, :required # TODO: create a type for this type of hash?
12
- details Details, :required
6
+ module Types
7
+ class Model < Foobara::Model
8
+ attributes do
9
+ name :string, :required # TODO: what are the valid values for this?
10
+ model :string, :required # TODO: what are the valid values for this?
11
+ size :integer, :required
12
+ digest :string, :required # TODO: create a type for this type of hash?
13
+ details Details, :required
14
+ end
13
15
  end
14
16
  end
15
17
  end
@@ -0,0 +1,14 @@
1
+ require_relative "../list_local_models"
2
+
3
+ module Foobara
4
+ module Ai
5
+ module OllamaApi
6
+ module Types
7
+ model_list = ListLocalModels.run!.map(&:model).sort
8
+ ModelEnum = Foobara::Enumerated.make_module(model_list)
9
+ end
10
+
11
+ foobara_register_type(:model, :string, one_of: Types::ModelEnum)
12
+ end
13
+ end
14
+ end
@@ -3,10 +3,12 @@ require_relative "model"
3
3
  module Foobara
4
4
  module Ai
5
5
  module OllamaApi
6
- class RunningModel < OllamaApi::Model
7
- attributes do
8
- expires_at :datetime, :required
9
- size_vram :integer, :required
6
+ module Types
7
+ class RunningModel < Model
8
+ attributes do
9
+ expires_at :datetime, :required
10
+ size_vram :integer, :required
11
+ end
10
12
  end
11
13
  end
12
14
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foobara-ollama-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-02-08 00:00:00.000000000 Z
10
+ date: 2025-02-27 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: foobara-http-api-command
@@ -36,9 +36,6 @@ files:
36
36
  - lib/foobara/ollama_api.rb
37
37
  - src/foobara/ai/ollama_api.rb
38
38
  - src/foobara/ai/ollama_api/base_command.rb
39
- - src/foobara/ai/ollama_api/base_get_command.rb
40
- - src/foobara/ai/ollama_api/base_post_command.rb
41
- - src/foobara/ai/ollama_api/concerns/url.rb
42
39
  - src/foobara/ai/ollama_api/generate_chat_completion.rb
43
40
  - src/foobara/ai/ollama_api/list_local_models.rb
44
41
  - src/foobara/ai/ollama_api/list_running_models.rb
@@ -47,6 +44,7 @@ files:
47
44
  - src/foobara/ai/ollama_api/types/message.rb
48
45
  - src/foobara/ai/ollama_api/types/model.rb
49
46
  - src/foobara/ai/ollama_api/types/model/details.rb
47
+ - src/foobara/ai/ollama_api/types/model_enum.rb
50
48
  - src/foobara/ai/ollama_api/types/running_model.rb
51
49
  homepage: https://github.com/foobara/ollama-api
52
50
  licenses:
@@ -63,7 +61,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
63
61
  requirements:
64
62
  - - ">="
65
63
  - !ruby/object:Gem::Version
66
- version: 3.4.1
64
+ version: 3.4.2
67
65
  required_rubygems_version: !ruby/object:Gem::Requirement
68
66
  requirements:
69
67
  - - ">="
@@ -1,11 +0,0 @@
1
- require_relative "base_command"
2
-
3
- module Foobara
4
- module Ai
5
- module OllamaApi
6
- class BaseGetCommand < BaseCommand
7
- include HttpApiGetCommand
8
- end
9
- end
10
- end
11
- end
@@ -1,11 +0,0 @@
1
- require_relative "base_command"
2
-
3
- module Foobara
4
- module Ai
5
- module OllamaApi
6
- class BasePostCommand < BaseCommand
7
- include HttpApiPostCommand
8
- end
9
- end
10
- end
11
- end
@@ -1,17 +0,0 @@
1
- module Foobara
2
- module Ai
3
- module OllamaApi
4
- module Concerns
5
- module Url
6
- include Concern
7
-
8
- module ClassMethods
9
- def path(path)
10
- url { "#{ENV["OLLAMA_API_URL"] || "http://localhost:11434"}/api/#{path}" }
11
- end
12
- end
13
- end
14
- end
15
- end
16
- end
17
- end