aiagent 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +19 -0
- data/Gemfile.lock +65 -0
- data/LICENSE.txt +21 -0
- data/README.md +61 -0
- data/Rakefile +17 -0
- data/lib/ai_agent/ai_agent/claude.rb +39 -0
- data/lib/ai_agent/base.rb +63 -0
- data/lib/ai_agent/ruby/version.rb +7 -0
- data/lib/ai_agent/ruby.rb +9 -0
- data/sig/ai_agent/ruby.rbs +6 -0
- metadata +58 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f54f71f8b08b031f351313bcf6fd253fdd2a588ef7d17da74115ff2b72561bb0
|
4
|
+
data.tar.gz: 2a8004689fc829d08872840029e8729be303aaf236f33500e8f979d8b8c4e92d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bf0f1f4447b4608769fdffe194bf210cd9f409bcf00c387c0e370466b2ca3188e3e3880075ac14267f62597ed62b2389632e7943e410004d80cedf82a0cab3f0
|
7
|
+
data.tar.gz: 44a6f23bfe09e4ce4e3a32ccbf8eecaa935d7b4b63aa59ffd98bb237a574731804036c51a79b42b14fd8a9113a23e4c8ad0b91484f1f938277eeb1f235049c68
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in the gemspec file
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
gem "rake", "~> 13.0"
|
9
|
+
|
10
|
+
gem "minitest", "~> 5.0"
|
11
|
+
|
12
|
+
gem "rubocop", "~> 1.21"
|
13
|
+
|
14
|
+
group :test do
|
15
|
+
gem 'simplecov', require: false
|
16
|
+
gem 'simplecov_json_formatter', require: false
|
17
|
+
end
|
18
|
+
|
19
|
+
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
aiagent (0.1.0)
|
5
|
+
httparty
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
ast (2.4.2)
|
11
|
+
docile (1.4.0)
|
12
|
+
httparty (0.21.0)
|
13
|
+
mini_mime (>= 1.0.0)
|
14
|
+
multi_xml (>= 0.5.2)
|
15
|
+
json (2.7.1)
|
16
|
+
language_server-protocol (3.17.0.3)
|
17
|
+
mini_mime (1.1.5)
|
18
|
+
minitest (5.22.2)
|
19
|
+
multi_xml (0.6.0)
|
20
|
+
parallel (1.24.0)
|
21
|
+
parser (3.3.0.5)
|
22
|
+
ast (~> 2.4.1)
|
23
|
+
racc
|
24
|
+
racc (1.7.3)
|
25
|
+
rainbow (3.1.1)
|
26
|
+
rake (13.1.0)
|
27
|
+
regexp_parser (2.9.0)
|
28
|
+
rexml (3.2.6)
|
29
|
+
rubocop (1.62.0)
|
30
|
+
json (~> 2.3)
|
31
|
+
language_server-protocol (>= 3.17.0)
|
32
|
+
parallel (~> 1.10)
|
33
|
+
parser (>= 3.3.0.2)
|
34
|
+
rainbow (>= 2.2.2, < 4.0)
|
35
|
+
regexp_parser (>= 1.8, < 3.0)
|
36
|
+
rexml (>= 3.2.5, < 4.0)
|
37
|
+
rubocop-ast (>= 1.31.1, < 2.0)
|
38
|
+
ruby-progressbar (~> 1.7)
|
39
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
40
|
+
rubocop-ast (1.31.2)
|
41
|
+
parser (>= 3.3.0.4)
|
42
|
+
ruby-progressbar (1.13.0)
|
43
|
+
simplecov (0.22.0)
|
44
|
+
docile (~> 1.1)
|
45
|
+
simplecov-html (~> 0.11)
|
46
|
+
simplecov_json_formatter (~> 0.1)
|
47
|
+
simplecov-html (0.12.3)
|
48
|
+
simplecov_json_formatter (0.1.4)
|
49
|
+
unicode-display_width (2.5.0)
|
50
|
+
|
51
|
+
PLATFORMS
|
52
|
+
arm64-darwin-22
|
53
|
+
ruby
|
54
|
+
|
55
|
+
DEPENDENCIES
|
56
|
+
aiagent!
|
57
|
+
httparty
|
58
|
+
minitest (~> 5.0)
|
59
|
+
rake (~> 13.0)
|
60
|
+
rubocop (~> 1.21)
|
61
|
+
simplecov
|
62
|
+
simplecov_json_formatter
|
63
|
+
|
64
|
+
BUNDLED WITH
|
65
|
+
2.5.3
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2024 Web Ventures Ltd (NZ)
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# aiagent
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/aiagent.svg)](https://badge.fury.io/rb/aiagent) [![License](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
|
4
|
+
|
5
|
+
** Example usage coming soon in the next version of this gem **
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'aiagent'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
$ bundle install
|
19
|
+
```
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
$ gem install aiagent
|
25
|
+
```
|
26
|
+
|
27
|
+
## Initializer
|
28
|
+
|
29
|
+
Create an initializer called config/initializers/ai_agent.rb \
|
30
|
+
And in that file simply require the agents that you'll use in your project.
|
31
|
+
|
32
|
+
E.g. \
|
33
|
+
require "ai_agent/ai_agent/claude"
|
34
|
+
|
35
|
+
## Usage
|
36
|
+
|
37
|
+
To use this gem you'll need an API key for the agents that you want to use.
|
38
|
+
|
39
|
+
Set your API keys as environment variables.
|
40
|
+
|
41
|
+
## Changelog
|
42
|
+
|
43
|
+
For a detailed list of changes for each version of this project, please see the [CHANGELOG](CHANGELOG.md).
|
44
|
+
|
45
|
+
## Development
|
46
|
+
|
47
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
48
|
+
|
49
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
50
|
+
|
51
|
+
## Contributing
|
52
|
+
|
53
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/webventures/aiagent.
|
54
|
+
|
55
|
+
## License
|
56
|
+
|
57
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
58
|
+
|
59
|
+
## Trademarks
|
60
|
+
|
61
|
+
This gem refers to agents that have been developed by third parties. Ownership of the respective trademarks remains with those parties.
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rake/testtask"
|
5
|
+
|
6
|
+
Rake::TestTask.new(:test) do |t|
|
7
|
+
t.libs << "test"
|
8
|
+
t.pattern = 'test/**/*_test.rb'
|
9
|
+
t.libs << "lib"
|
10
|
+
t.test_files = FileList["test/**/test_*.rb"]
|
11
|
+
end
|
12
|
+
|
13
|
+
require "rubocop/rake_task"
|
14
|
+
|
15
|
+
RuboCop::RakeTask.new
|
16
|
+
|
17
|
+
task default: %i[test rubocop]
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require "ai_agent/base"
|
2
|
+
if Gem.loaded_specs.has_key?('claude-ruby')
|
3
|
+
require 'claude/client'
|
4
|
+
else
|
5
|
+
Rails.logger.warn "claude-ruby gem is not loaded"
|
6
|
+
end
|
7
|
+
|
8
|
+
module AiAgent
|
9
|
+
CLAUDE = 'claude'.freeze
|
10
|
+
|
11
|
+
class Claude < Base
|
12
|
+
def initialize
|
13
|
+
super
|
14
|
+
self.agent = CLAUDE
|
15
|
+
end
|
16
|
+
|
17
|
+
def client
|
18
|
+
claude if agent == CLAUDE
|
19
|
+
end
|
20
|
+
|
21
|
+
def send_messages(messages, options)
|
22
|
+
client.messages(messages, options)
|
23
|
+
end
|
24
|
+
|
25
|
+
def format_response(response)
|
26
|
+
client.parse_response(response) rescue "ERROR: Couldn't extract text from Claude response"
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def claude
|
32
|
+
@claude ||= ::Claude::Client.new(anthropic_api_key)
|
33
|
+
end
|
34
|
+
|
35
|
+
def anthropic_api_key
|
36
|
+
@anthropic_api_key ||= ENV['ANTHROPIC_API_KEY']
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module AiAgent
|
5
|
+
class Base
|
6
|
+
attr_accessor :agent
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
# be sure to set agent in the subclass initialize method
|
10
|
+
end
|
11
|
+
|
12
|
+
def client
|
13
|
+
raise NotImplementedError, "Subclasses must implement the client method"
|
14
|
+
end
|
15
|
+
|
16
|
+
def send_messages(messages, options)
|
17
|
+
raise NotImplementedError, "Subclasses must implement the send_message method"
|
18
|
+
end
|
19
|
+
|
20
|
+
def format_response(response)
|
21
|
+
raise NotImplementedError, "Subclasses must implement the format_response method"
|
22
|
+
end
|
23
|
+
|
24
|
+
def analyze_sentiment(text, strict: true, options: {})
|
25
|
+
prompt = "Analyze the sentiment of the following text and classify it as positive, negative, or neutral:\n\n#{text}\n\nSentiment: "
|
26
|
+
if strict
|
27
|
+
system = "If you are asked to return a word, then return only that word with no preamble or postamble. " if strict
|
28
|
+
max_tokens = 2
|
29
|
+
else
|
30
|
+
max_tokens = 100
|
31
|
+
end
|
32
|
+
|
33
|
+
send_messages([ { 'role': 'user', 'content': prompt } ],
|
34
|
+
options.reverse_merge( system: system, max_tokens: max_tokens ))
|
35
|
+
end
|
36
|
+
|
37
|
+
def recognize_entities(text, strict: true, options: {})
|
38
|
+
prompt = "Identify and list the named entities in the following text:\n\n#{text}\n\nEntities: "
|
39
|
+
if strict
|
40
|
+
system = "Be specific in your answer, with no preamble or postamble. If you are asked to list some names, then return only a list of those names, nothing else. "
|
41
|
+
max_tokens = 100
|
42
|
+
else
|
43
|
+
max_tokens = 500
|
44
|
+
end
|
45
|
+
|
46
|
+
send_messages([ { 'role': 'user', 'content': prompt } ],
|
47
|
+
options.reverse_merge( system: system, max_tokens: max_tokens ))
|
48
|
+
end
|
49
|
+
|
50
|
+
def summarize_text(text, strict: true, options: {})
|
51
|
+
prompt = "Summarize the following text:\n\n#{text}\n\nSummary: "
|
52
|
+
if strict
|
53
|
+
system = "Be specific in your answer, with no preamble or postamble. I.e. return only what the user asks for, nothing else. "
|
54
|
+
max_tokens = 100
|
55
|
+
else
|
56
|
+
max_tokens = 500
|
57
|
+
end
|
58
|
+
|
59
|
+
send_messages([ { 'role': 'user', 'content': prompt } ],
|
60
|
+
options.reverse_merge( system: system, max_tokens: max_tokens ))
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: aiagent
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Web Ventures Ltd
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-07-08 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Ruby SDK for interacting with LLM agents such as OpenAI's ChatGPT, Anthropic's
|
14
|
+
Claude, and Ollama.
|
15
|
+
email:
|
16
|
+
- webven@mailgab.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- CHANGELOG.md
|
22
|
+
- Gemfile
|
23
|
+
- Gemfile.lock
|
24
|
+
- LICENSE.txt
|
25
|
+
- README.md
|
26
|
+
- Rakefile
|
27
|
+
- lib/ai_agent/ai_agent/claude.rb
|
28
|
+
- lib/ai_agent/base.rb
|
29
|
+
- lib/ai_agent/ruby.rb
|
30
|
+
- lib/ai_agent/ruby/version.rb
|
31
|
+
- sig/ai_agent/ruby.rbs
|
32
|
+
homepage: https://github.com/webventures/aiagent.git
|
33
|
+
licenses:
|
34
|
+
- MIT
|
35
|
+
metadata:
|
36
|
+
homepage_uri: https://github.com/webventures/aiagent.git
|
37
|
+
source_code_uri: https://github.com/webventures/aiagent.git
|
38
|
+
changelog_uri: https://github.com/webventures/aiagent/blob/main/CHANGELOG.md
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.0.0
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
requirements: []
|
54
|
+
rubygems_version: 3.5.3
|
55
|
+
signing_key:
|
56
|
+
specification_version: 4
|
57
|
+
summary: A Ruby SDK for interacting with AI Agents such as ChatGPT and Claude
|
58
|
+
test_files: []
|