aiagent 0.1.0 → 0.2.0

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: f54f71f8b08b031f351313bcf6fd253fdd2a588ef7d17da74115ff2b72561bb0
4
- data.tar.gz: 2a8004689fc829d08872840029e8729be303aaf236f33500e8f979d8b8c4e92d
3
+ metadata.gz: 2ca59dbb48716e29658c4e73e94e75c2c017f4b1f7bfb5b3a1a7865c4411ebf1
4
+ data.tar.gz: aa1d848208b8a9205cab096d382fb5ca40ad051507d4a09e0ec5f52160c2474b
5
5
  SHA512:
6
- metadata.gz: bf0f1f4447b4608769fdffe194bf210cd9f409bcf00c387c0e370466b2ca3188e3e3880075ac14267f62597ed62b2389632e7943e410004d80cedf82a0cab3f0
7
- data.tar.gz: 44a6f23bfe09e4ce4e3a32ccbf8eecaa935d7b4b63aa59ffd98bb237a574731804036c51a79b42b14fd8a9113a23e4c8ad0b91484f1f938277eeb1f235049c68
6
+ metadata.gz: 42ca5e9c3e0234e6671afcf986d5525b1cb8fb9fd5fb00652e66e7072d424007c09b22c302065040ea1abc9b2c57c7e90acffa128c51adc7d7a2fa738259e6ff
7
+ data.tar.gz: e4789e27b79fe54fcafc800e47326a192dafcf57e3411fbdf4cf66a92834947d77b59e676ed83cdfd2e439067d471c6e97503763f3fb8f3572edd2ac34e47af9
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [0.2.0] - 2024-07-09
2
+
3
+ - Allow API key to be set when instantiating the agent
4
+ - Allow timeout to be set
5
+ - Allow endpoint to be customised
6
+ - Improved documentation
7
+
1
8
  ## [0.1.0] - 2024-07-09
2
9
 
3
10
  - Initial release
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
- E.g. \
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
- To use this gem you'll need an API key for the agents that you want to use.
56
+ Basic example usage for Claude:
38
57
 
39
- Set your API keys as environment variables.
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(anthropic_api_key)
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
@@ -4,6 +4,9 @@ require 'json'
4
4
  module AiAgent
5
5
  class Base
6
6
  attr_accessor :agent
7
+ attr_accessor :api_key
8
+ attr_accessor :endpoint
9
+ attr_accessor :timeout
7
10
 
8
11
  def initialize
9
12
  # be sure to set agent in the subclass initialize method
@@ -2,6 +2,6 @@
2
2
 
3
3
  module AiAgent
4
4
  module Ruby
5
- VERSION = "0.1.0"
5
+ VERSION = "0.2.0"
6
6
  end
7
7
  end
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.1.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-08 00:00:00.000000000 Z
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.