activellm 0.0.0.alpha

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9199c544536ea093fa65deec1bc3db50fd2afa1b7b6ff3c37f6e7cf0d017959f
4
+ data.tar.gz: f5e498bd6feeb4f01903c68bf405511e9ec73d4596cbdf75784c26a370b86d52
5
+ SHA512:
6
+ metadata.gz: a8a1ffc270c9c7ea1b37cd5729ed02842a056643ef60704a10bb5a03ef138118aa057b00b84834cbd64a65f71a3db776decfc08fd538edef95c6e3b79776a0ae
7
+ data.tar.gz: 2cdb8b757fa7ff18218be11e866bd09f33090a0e7471434c586c424f1c1af8952f258c450048a2dbd706351e789738975e22af89e04c9b7022dbe3a5910acd65
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright Abdelkader Boudih
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # ActiveLLM
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ How to use my plugin.
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem "active_llm"
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install active_llm
22
+ ```
23
+
24
+ ## Contributing
25
+ Contribution directions go here.
26
+
27
+ ## License
28
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/setup"
4
+
5
+ APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
6
+ load "rails/tasks/engine.rake"
7
+
8
+ load "rails/tasks/statistics.rake"
9
+
10
+ require "bundler/gem_tasks"
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveLLM
4
+ class ApplicationRecord < ActiveRecord::Base
5
+ self.abstract_class = true
6
+ end
7
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveLLM
4
+ module ConnectionAdapters
5
+ module OllamaAdapter
6
+ module Health
7
+ def healthy?
8
+ raise NotImplementedError
9
+ end
10
+
11
+ def available?
12
+ raise NotImplementedError
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveLLM
4
+ module ConnectionAdapters
5
+ class AbstractAdapter
6
+ autoload :Health, "active_llm/connection_adapters/abstract_adapter/health"
7
+
8
+ def support_streaming?
9
+ false
10
+ end
11
+
12
+ def supported_formats
13
+ [:json]
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveLLM
4
+ module ConnectionAdapters
5
+ module OllamaAdapter
6
+ module Features
7
+ def generate(payload, server_sent_events: nil, &callback)
8
+ request("api/generate", payload, server_sent_events:, &callback)
9
+ end
10
+
11
+ def chat(payload, server_sent_events: nil, &callback)
12
+ request("api/chat", payload, server_sent_events:, &callback)
13
+ end
14
+
15
+ def create(payload, server_sent_events: nil, &callback)
16
+ request("api/create", payload, server_sent_events:, &callback)
17
+ end
18
+
19
+ def tags(server_sent_events: nil, &callback)
20
+ request("api/tags", nil, server_sent_events:, request_method: "GET", &callback)
21
+ end
22
+
23
+ def show(payload, server_sent_events: nil, &callback)
24
+ request("api/show", payload, server_sent_events:, &callback)
25
+ end
26
+
27
+ def copy(payload, server_sent_events: nil, &callback)
28
+ request("api/copy", payload, server_sent_events:, &callback)
29
+ true
30
+ end
31
+
32
+ def delete(payload, server_sent_events: nil, &callback)
33
+ request("api/delete", payload, server_sent_events:, request_method: "DELETE", &callback)
34
+ true
35
+ end
36
+
37
+ def pull(payload, server_sent_events: nil, &callback)
38
+ request("api/pull", payload, server_sent_events:, &callback)
39
+ end
40
+
41
+ def push(payload, server_sent_events: nil, &callback)
42
+ request("api/push", payload, server_sent_events:, &callback)
43
+ end
44
+
45
+ def embeddings(payload, server_sent_events: nil, &callback)
46
+ request("api/embeddings", payload, server_sent_events:, &callback)
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveLLM
4
+ module ConnectionAdapters
5
+ module OllamaAdapter
6
+ module Models
7
+ def get_models
8
+ request("/models")
9
+ end
10
+
11
+ def get_model(id)
12
+ request("/models/#{id}")
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ gem "faraday", "~> 2.9"
4
+ gem "async-http-faraday"
5
+ require "async/http/faraday"
6
+
7
+ module ActiveLLM
8
+ module ConnectionAdapters
9
+ class OllamaAdapter < AbstractAdapter
10
+ class << self
11
+ def new_client(_conn_params)
12
+ Faraday.new do |builder|
13
+ builder.adapter :async_http
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveLLM
4
+ module ConnectionAdapters
5
+ module OpenaiAdapter
6
+ module Features
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveLLM
4
+ module ConnectionAdapters
5
+ class OpenaiAdapter < AbstractAdapter
6
+ class << self
7
+ def new_client(_conn_params)
8
+ Faraday.new do |builder|
9
+ builder.adapter :async_http
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveLLM
4
+ module ConnectionAdapters
5
+ end
6
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveLLM
4
+ class EndpointConfigurations
5
+ # ActiveLLM::Model.configurations will return either a HashConfig or
6
+ # UrlConfig respectively. It will never return a +DatabaseConfig+ object,
7
+ # as this is the parent class for the types of database configuration objects.
8
+ class EndpointConfig # :nodoc:
9
+ attr_reader :env_name, :name
10
+
11
+ def initialize(env_name, name)
12
+ @env_name = env_name
13
+ @name = name
14
+ end
15
+
16
+ def adapter_method
17
+ "#{adapter}_connection"
18
+ end
19
+
20
+ def adapter_class_method
21
+ "#{adapter}_adapter_class"
22
+ end
23
+
24
+ def host
25
+ raise NotImplementedError
26
+ end
27
+
28
+ def adapter
29
+ raise NotImplementedError
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,164 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveRecord
4
+ class EndpointConfigurations
5
+ # = Active LLM Database Hash Config
6
+ #
7
+ # A +HashConfig+ object is created for each database configuration entry that
8
+ # is created from a hash.
9
+ #
10
+ # A hash config:
11
+ #
12
+ # { "development" => { "database" => "db_name" } }
13
+ #
14
+ # Becomes:
15
+ #
16
+ # #<ActiveRecord::EndpointConfigurations::HashConfig:0x00007fd1acbded10
17
+ # @env_name="development", @name="primary", @config={database: "db_name"}>
18
+ #
19
+ # See ActiveRecord::EndpointConfigurations for more info.
20
+ class HashConfig < EndpointConfig
21
+ attr_reader :configuration_hash
22
+
23
+ # Initialize a new +HashConfig+ object
24
+ #
25
+ # ==== Options
26
+ #
27
+ # * <tt>:env_name</tt> - The \Rails environment, i.e. "development".
28
+ # * <tt>:name</tt> - The db config name. In a standard two-tier
29
+ # database configuration this will default to "primary". In a multiple
30
+ # database three-tier database configuration this corresponds to the name
31
+ # used in the second tier, for example "primary_readonly".
32
+ # * <tt>:config</tt> - The config hash. This is the hash that contains the
33
+ # database adapter, name, and other important information for database
34
+ # connections.
35
+ def initialize(env_name, name, configuration_hash)
36
+ super(env_name, name)
37
+ @configuration_hash = configuration_hash.symbolize_keys.freeze
38
+ end
39
+
40
+ # Determines whether a database configuration is for a replica / readonly
41
+ # connection. If the +replica+ key is present in the config, +replica?+ will
42
+ # return +true+.
43
+ def replica?
44
+ configuration_hash[:replica]
45
+ end
46
+
47
+ # The migrations paths for a database configuration. If the
48
+ # +migrations_paths+ key is present in the config, +migrations_paths+
49
+ # will return its value.
50
+ def migrations_paths
51
+ configuration_hash[:migrations_paths]
52
+ end
53
+
54
+ def host
55
+ configuration_hash[:host]
56
+ end
57
+
58
+ def socket # :nodoc:
59
+ configuration_hash[:socket]
60
+ end
61
+
62
+ def database
63
+ configuration_hash[:database]
64
+ end
65
+
66
+ def _database=(database) # :nodoc:
67
+ @configuration_hash = configuration_hash.merge(database:).freeze
68
+ end
69
+
70
+ def pool
71
+ (configuration_hash[:pool] || 5).to_i
72
+ end
73
+
74
+ def min_threads
75
+ (configuration_hash[:min_threads] || 0).to_i
76
+ end
77
+
78
+ def max_threads
79
+ (configuration_hash[:max_threads] || pool).to_i
80
+ end
81
+
82
+ def query_cache
83
+ configuration_hash[:query_cache]
84
+ end
85
+
86
+ def max_queue
87
+ max_threads * 4
88
+ end
89
+
90
+ def checkout_timeout
91
+ (configuration_hash[:checkout_timeout] || 5).to_f
92
+ end
93
+
94
+ # +reaping_frequency+ is configurable mostly for historical reasons, but it could
95
+ # also be useful if someone wants a very low +idle_timeout+.
96
+ def reaping_frequency
97
+ configuration_hash.fetch(:reaping_frequency, 60)&.to_f
98
+ end
99
+
100
+ def idle_timeout
101
+ timeout = configuration_hash.fetch(:idle_timeout, 300).to_f
102
+ timeout if timeout.positive?
103
+ end
104
+
105
+ def adapter
106
+ configuration_hash[:adapter]
107
+ end
108
+
109
+ # The path to the schema cache dump file for a database.
110
+ # If omitted, the filename will be read from ENV or a
111
+ # default will be derived.
112
+ def schema_cache_path
113
+ configuration_hash[:schema_cache_path]
114
+ end
115
+
116
+ def default_schema_cache_path
117
+ "db/schema_cache.yml"
118
+ end
119
+
120
+ def lazy_schema_cache_path
121
+ schema_cache_path || default_schema_cache_path
122
+ end
123
+
124
+ def primary? # :nodoc:
125
+ Base.configurations.primary?(name)
126
+ end
127
+
128
+ # Determines whether to dump the schema/structure files and the
129
+ # filename that should be used.
130
+ #
131
+ # If +configuration_hash[:schema_dump]+ is set to +false+ or +nil+
132
+ # the schema will not be dumped.
133
+ #
134
+ # If the config option is set that will be used. Otherwise \Rails
135
+ # will generate the filename from the database config name.
136
+ def schema_dump(format = ActiveRecord.schema_format)
137
+ if configuration_hash.key?(:schema_dump)
138
+ if (config = configuration_hash[:schema_dump])
139
+ config
140
+ end
141
+ elsif primary?
142
+ schema_file_type(format)
143
+ else
144
+ "#{name}_#{schema_file_type(format)}"
145
+ end
146
+ end
147
+
148
+ def database_tasks? # :nodoc:
149
+ !replica? && !!configuration_hash.fetch(:database_tasks, true)
150
+ end
151
+
152
+ private
153
+
154
+ def schema_file_type(format)
155
+ case format
156
+ when :ruby
157
+ "schema.rb"
158
+ when :sql
159
+ "structure.sql"
160
+ end
161
+ end
162
+ end
163
+ end
164
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveLLM
4
+ class EndpointConfigurations
5
+ class InvalidConfigurationError < StandardError; end
6
+
7
+ attr_reader :configurations
8
+
9
+ def initialize(configurations = {})
10
+ @configurations = build_configs(configurations)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails"
4
+ require "action_controller/railtie"
5
+ require "active_record/railtie"
6
+
7
+ require "active_llm"
8
+
9
+ module ActiveLLM
10
+ class Engine < ::Rails::Engine
11
+ isolate_namespace ActiveLLM
12
+
13
+ config.active_llm = ActiveSupport::OrderedOptions.new
14
+
15
+ config.eager_load_namespaces << ActiveLLM
16
+ end
17
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveLLM
4
+ def self.gem_version
5
+ Gem::Version.new VERSION::STRING
6
+ end
7
+
8
+ module VERSION
9
+ MAJOR = 0
10
+ MINOR = 0
11
+ TINY = 0
12
+ PRE = "alpha"
13
+
14
+ STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
15
+ end
16
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveLLM
4
+ class Model
5
+ extend ConnectionAdapters
6
+ end
7
+ ActiveSupport.run_load_hooks(:active_llm, Model)
8
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "gem_version"
4
+
5
+ module ActiveLLM
6
+ def self.version
7
+ gem_version
8
+ end
9
+ end
data/lib/active_llm.rb ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_llm/version"
4
+ require "active_llm/engine"
5
+ require "faraday"
6
+ require "async/http/faraday"
7
+
8
+ module ActiveLLM
9
+ extend ActiveSupport::Autoload
10
+
11
+ autoload :ConnectionAdapters
12
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ namespace :active_llm do
4
+ # Prevent migration installation task from showing up twice.
5
+ Rake::Task["install:migrations"].clear_comments
6
+
7
+ desc "Copy over the migration needed to the application"
8
+ task install: :environment do
9
+ if Rake::Task.task_defined?("active_llm:install:migrations")
10
+ Rake::Task["active_llm:install:migrations"].invoke
11
+ else
12
+ Rake::Task["app:active_llm:install:migrations"].invoke
13
+ end
14
+ end
15
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activellm
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0.alpha
5
+ platform: ruby
6
+ authors:
7
+ - Abdelkader Boudih
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-03-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '7'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: async-http-faraday
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: faraday
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.9'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.9'
55
+ - !ruby/object:Gem::Dependency
56
+ name: railties
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '7'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '7'
69
+ description: 'ActiveLLM: Integrate Large Language Models with Rails'
70
+ email:
71
+ - terminale@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - MIT-LICENSE
77
+ - README.md
78
+ - Rakefile
79
+ - app/models/active_llm/application_record.rb
80
+ - lib/active_llm.rb
81
+ - lib/active_llm/connection_adapters.rb
82
+ - lib/active_llm/connection_adapters/abstract_adapter.rb
83
+ - lib/active_llm/connection_adapters/abstract_adapter/health.rb
84
+ - lib/active_llm/connection_adapters/ollama_adapter.rb
85
+ - lib/active_llm/connection_adapters/ollama_adapter/features.rb
86
+ - lib/active_llm/connection_adapters/ollama_adapter/models.rb
87
+ - lib/active_llm/connection_adapters/openai_adapter.rb
88
+ - lib/active_llm/connection_adapters/openai_adapter/features.rb
89
+ - lib/active_llm/endpoint_configurations.rb
90
+ - lib/active_llm/endpoint_configurations/endpoint_config.rb
91
+ - lib/active_llm/endpoint_configurations/hash_config.rb
92
+ - lib/active_llm/engine.rb
93
+ - lib/active_llm/gem_version.rb
94
+ - lib/active_llm/model.rb
95
+ - lib/active_llm/version.rb
96
+ - lib/tasks/activellm.rake
97
+ homepage: https://github.com/seuros/active_llm
98
+ licenses:
99
+ - MIT
100
+ metadata:
101
+ homepage_uri: https://github.com/seuros/active_llm
102
+ source_code_uri: https://github.com/seuros/active_llm
103
+ changelog_uri: https://github.com/seuros/active_llm/blob/master/CHANGELOG.md
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">"
116
+ - !ruby/object:Gem::Version
117
+ version: 1.3.1
118
+ requirements: []
119
+ rubygems_version: 3.4.10
120
+ signing_key:
121
+ specification_version: 4
122
+ summary: 'ActiveLLM: Integrate Large Language Models with Rails'
123
+ test_files: []