ai-engine 0.3.0 → 0.4.1
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 +4 -4
- data/README.md +6 -2
- data/app/models/concerns/ai/engine/assistable.rb +3 -3
- data/app/models/concerns/ai/engine/threadable.rb +1 -1
- data/app/services/ai/engine/openai/assistants/create.rb +2 -7
- data/app/services/ai/engine/openai/assistants/update.rb +2 -7
- data/db/migrate/20240528153439_create_ai_engine_assistants.rb +1 -1
- data/lib/ai/engine/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0702cfaf1ad63d8a98a0b8acb67fdd0b1d3cf46320652f8f86df6b677af981ac
|
4
|
+
data.tar.gz: 1adacb8b8e2ef7da675077a79950ca342df9401a62780b8955c5b785f3d32538
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1270b59cdbe033e1147cc54ca9124145d3670363ec73b51854832983ae6f1d5dc88ead7ad726d99d641b4c7a9b0d2fe4eb5b236b7c6bdcb792d44c9f175fd77
|
7
|
+
data.tar.gz: 12e4f4c75a87e9f5b3c67312009906f981e01ebe340c2de3f6c8420a625bf2b7bddde7507bd9d0246747434d8ba95c5cd9cf6e4d6d1741cefdd15906d3774d6b
|
data/README.md
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
# AI::Engine
|
2
2
|
|
3
|
-
|
3
|
+
AI::Engine is the fastest way to get AI Assistants into your Rails app! It's a Rails Engine which sets up everything you need to start streaming from OpenAI Assistants in your Rails app.
|
4
|
+
|
5
|
+
Full docs can be found at [RailsAI.com](https://railsai.com/docs/installation).
|
6
|
+
|
7
|
+
A demo app can be found [here](https://github.com/alexrudall/ai-engine-starter-kit/).
|
4
8
|
|
5
9
|
## Usage
|
6
10
|
|
@@ -22,7 +26,7 @@ And run them:
|
|
22
26
|
bundle exec rails db:migrate
|
23
27
|
```
|
24
28
|
|
25
|
-
Full
|
29
|
+
Full docs can be found at [RailsAI.com](https://railsai.com/docs/installation).
|
26
30
|
|
27
31
|
## Engine Development
|
28
32
|
|
@@ -4,7 +4,7 @@ module AI
|
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
6
|
included do
|
7
|
-
has_one :assistant, as: :assistable, class_name: "AI::Engine::Assistant"
|
7
|
+
has_one :assistant, as: :assistable, class_name: "AI::Engine::Assistant", dependent: :nullify
|
8
8
|
|
9
9
|
before_create :create_openai_assistant
|
10
10
|
before_update :update_openai_assistant
|
@@ -29,7 +29,7 @@ module AI
|
|
29
29
|
def create_openai_assistant
|
30
30
|
build_assistant
|
31
31
|
begin
|
32
|
-
assistant.remote_id = AI::Engine::OpenAI::Assistants::Create.call(
|
32
|
+
assistant.remote_id = AI::Engine::OpenAI::Assistants::Create.call(ai_engine_assistant)
|
33
33
|
rescue Faraday::Error => e
|
34
34
|
errors.add(:base, e.message)
|
35
35
|
throw(:abort)
|
@@ -37,7 +37,7 @@ module AI
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def update_openai_assistant
|
40
|
-
AI::Engine::OpenAI::Assistants::Update.call(remote_id: assistant&.remote_id,
|
40
|
+
AI::Engine::OpenAI::Assistants::Update.call(remote_id: assistant&.remote_id, parameters: ai_engine_assistant)
|
41
41
|
rescue Faraday::Error => e
|
42
42
|
errors.add(:base, e.message)
|
43
43
|
throw(:abort)
|
@@ -4,7 +4,7 @@ module AI
|
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
6
|
included do
|
7
|
-
has_many :assistant_threads, as: :threadable, class_name: "AI::Engine::AssistantThread"
|
7
|
+
has_many :assistant_threads, as: :threadable, class_name: "AI::Engine::AssistantThread", dependent: :nullify
|
8
8
|
|
9
9
|
def ai_engine_on_message_create(message:)
|
10
10
|
# This is a hook for the AI Engine to notify the AssistantThreadtable that a Message has been updated.
|
@@ -1,14 +1,9 @@
|
|
1
1
|
class AI::Engine::OpenAI::Assistants::Create
|
2
2
|
# Creates a new Assistant on the OpenAI API.
|
3
3
|
# Returns the OpenAI ID of the new Assistant.
|
4
|
-
def self.call(
|
4
|
+
def self.call(parameters)
|
5
5
|
response = client.assistants.create(
|
6
|
-
parameters:
|
7
|
-
name: name,
|
8
|
-
model: model,
|
9
|
-
description: description,
|
10
|
-
instructions: instructions
|
11
|
-
}
|
6
|
+
parameters: parameters
|
12
7
|
)
|
13
8
|
|
14
9
|
response["id"]
|
@@ -1,12 +1,7 @@
|
|
1
1
|
class AI::Engine::OpenAI::Assistants::Update
|
2
2
|
# Updates an OpenAI Assistant with the given parameters.
|
3
|
-
def self.call(remote_id:,
|
4
|
-
parameters =
|
5
|
-
name: name,
|
6
|
-
model: model,
|
7
|
-
description: description,
|
8
|
-
instructions: instructions
|
9
|
-
}.compact
|
3
|
+
def self.call(remote_id:, parameters:)
|
4
|
+
parameters = parameters.compact
|
10
5
|
|
11
6
|
client.assistants.modify(
|
12
7
|
id: remote_id,
|
@@ -7,6 +7,6 @@ class CreateAIEngineAssistants < ActiveRecord::Migration[7.1]
|
|
7
7
|
t.timestamps
|
8
8
|
end
|
9
9
|
|
10
|
-
add_index :ai_engine_assistants, %i[assistable_type assistable_id remote_id], unique: true
|
10
|
+
add_index :ai_engine_assistants, %i[assistable_type assistable_id remote_id], unique: true, name: "ai_engine_assistants_unique_index"
|
11
11
|
end
|
12
12
|
end
|
data/lib/ai/engine/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ai-engine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Rudall
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-09-
|
11
|
+
date: 2024-09-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-openai
|
@@ -24,7 +24,7 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 7.1.0
|
27
|
-
description:
|
27
|
+
description: The fastest way to get AI Assistants into your Rails app!
|
28
28
|
email:
|
29
29
|
- hello@alexrudall.com
|
30
30
|
executables: []
|
@@ -86,5 +86,5 @@ requirements: []
|
|
86
86
|
rubygems_version: 3.5.11
|
87
87
|
signing_key:
|
88
88
|
specification_version: 4
|
89
|
-
summary: The
|
89
|
+
summary: The fastest way to get AI Assistants into your Rails app!
|
90
90
|
test_files: []
|