aiagent 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +55 -5
- data/lib/ai_agent/ai_agent/claude.rb +5 -7
- data/lib/ai_agent/base.rb +3 -0
- data/lib/ai_agent/ruby/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ca59dbb48716e29658c4e73e94e75c2c017f4b1f7bfb5b3a1a7865c4411ebf1
|
4
|
+
data.tar.gz: aa1d848208b8a9205cab096d382fb5ca40ad051507d4a09e0ec5f52160c2474b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 42ca5e9c3e0234e6671afcf986d5525b1cb8fb9fd5fb00652e66e7072d424007c09b22c302065040ea1abc9b2c57c7e90acffa128c51adc7d7a2fa738259e6ff
|
7
|
+
data.tar.gz: e4789e27b79fe54fcafc800e47326a192dafcf57e3411fbdf4cf66a92834947d77b59e676ed83cdfd2e439067d471c6e97503763f3fb8f3572edd2ac34e47af9
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -2,8 +2,6 @@
|
|
2
2
|
|
3
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
4
|
|
5
|
-
** Example usage coming soon in the next version of this gem **
|
6
|
-
|
7
5
|
## Installation
|
8
6
|
|
9
7
|
Add this line to your application's Gemfile:
|
@@ -29,14 +27,66 @@ $ gem install aiagent
|
|
29
27
|
Create an initializer called config/initializers/ai_agent.rb \
|
30
28
|
And in that file simply require the agents that you'll use in your project.
|
31
29
|
|
32
|
-
|
30
|
+
Example initializer:
|
31
|
+
```ruby
|
32
|
+
# config/initializers/ai_agent.rb
|
33
|
+
|
33
34
|
require "ai_agent/ai_agent/claude"
|
35
|
+
```
|
36
|
+
## Setup
|
37
|
+
|
38
|
+
To use this gem you'll need an API key for the agents that you want to use.
|
39
|
+
|
40
|
+
Set your API keys as environment variables, or pass them to the AiAgent initialize method.
|
41
|
+
|
42
|
+
Example with environment variables:
|
43
|
+
```ruby
|
44
|
+
# ENV['ANTHROPIC_API_KEY'] = 'YOUR_ANTHROPIC_API_KEY'
|
45
|
+
|
46
|
+
ai_agent = AiAgent::Claude.new
|
47
|
+
```
|
48
|
+
|
49
|
+
Example passing the api_key to the initalizer:
|
50
|
+
```ruby
|
51
|
+
ai_agent = AiAgent::Claude.new(api_key: 'ANTHROPIC_API_KEY')
|
52
|
+
```
|
34
53
|
|
35
54
|
## Usage
|
36
55
|
|
37
|
-
|
56
|
+
Basic example usage for Claude:
|
38
57
|
|
39
|
-
|
58
|
+
```ruby
|
59
|
+
ai_agent = AiAgent::Claude.new(timeout: 30)
|
60
|
+
prompt = "Generate 5 inspirational quotes."
|
61
|
+
messages = [{ 'role': 'user', 'content': prompt }]
|
62
|
+
options = {}
|
63
|
+
response = ai_agent.send_messages(messages, options)
|
64
|
+
ai_agent.format_response(response)
|
65
|
+
```
|
66
|
+
|
67
|
+
Sentiment analysis:
|
68
|
+
```ruby
|
69
|
+
ai_agent = AiAgent::Claude.new
|
70
|
+
review = "The product quality is excellent and the customer service was very helpful!"
|
71
|
+
response = ai_agent.analyze_sentiment(review, options: { model: Claude::Model::CLAUDE_CHEAPEST })
|
72
|
+
ai_agent.format_response(response)
|
73
|
+
```
|
74
|
+
|
75
|
+
Named entity recognition:
|
76
|
+
```ruby
|
77
|
+
ai_agent = AiAgent::Claude.new
|
78
|
+
abstract = "Anthropic released Claude 3.5 Sonnet on 21 June 2024."
|
79
|
+
response = ai_agent.recognize_entities(abstract, options: { model: Claude::Model::CLAUDE_CHEAPEST })
|
80
|
+
ai_agent.format_response(response)
|
81
|
+
```
|
82
|
+
|
83
|
+
Text summarization:
|
84
|
+
```ruby
|
85
|
+
ai_agent = AiAgent::Claude.new
|
86
|
+
abstract = "A long message" # customise this for your own example
|
87
|
+
response = ai_agent.summarize_text(abstract, strict: false, options: { model: Claude::Model::CLAUDE_SMARTEST })
|
88
|
+
ai_agent.format_response(response)
|
89
|
+
```
|
40
90
|
|
41
91
|
## Changelog
|
42
92
|
|
@@ -9,9 +9,11 @@ module AiAgent
|
|
9
9
|
CLAUDE = 'claude'.freeze
|
10
10
|
|
11
11
|
class Claude < Base
|
12
|
-
def initialize
|
13
|
-
super
|
12
|
+
def initialize(api_key: nil, endpoint: nil, timeout: 60)
|
14
13
|
self.agent = CLAUDE
|
14
|
+
self.api_key = api_key || ENV['ANTHROPIC_API_KEY']
|
15
|
+
self.endpoint = endpoint # nil for default as defined in claude/client
|
16
|
+
self.timeout = timeout
|
15
17
|
end
|
16
18
|
|
17
19
|
def client
|
@@ -29,11 +31,7 @@ module AiAgent
|
|
29
31
|
private
|
30
32
|
|
31
33
|
def claude
|
32
|
-
@claude ||= ::Claude::Client.new(
|
33
|
-
end
|
34
|
-
|
35
|
-
def anthropic_api_key
|
36
|
-
@anthropic_api_key ||= ENV['ANTHROPIC_API_KEY']
|
34
|
+
@claude ||= ::Claude::Client.new(api_key, endpoint: endpoint, timeout: timeout)
|
37
35
|
end
|
38
36
|
end
|
39
37
|
end
|
data/lib/ai_agent/base.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aiagent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Web Ventures Ltd
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-07-
|
11
|
+
date: 2024-07-09 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Ruby SDK for interacting with LLM agents such as OpenAI's ChatGPT, Anthropic's
|
14
14
|
Claude, and Ollama.
|