aiagent

Gem Version License

Installation

Add this line to your application's Gemfile:

gem 'aiagent'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install aiagent

Initializer

Create an initializer called config/initializers/ai_agent.rb \ And in that file simply require the agents that you'll use in your project.

Example initializer:

# config/initializers/ai_agent.rb

require "ai_agent/ai_agent/claude"

Setup

To use this gem you'll need an API key for the agents that you want to use.

Set your API keys as environment variables, or pass them to the AiAgent initialize method.

Example with environment variables:

# ENV['ANTHROPIC_API_KEY'] = 'YOUR_ANTHROPIC_API_KEY'

ai_agent = AiAgent::Claude.new

Example passing the api_key to the initalizer:

ai_agent = AiAgent::Claude.new(api_key: 'ANTHROPIC_API_KEY')

Usage

Basic example usage for Claude:

ai_agent = AiAgent::Claude.new(timeout: 30)
prompt = "Generate 5 inspirational quotes."
messages = [{ 'role': 'user', 'content': prompt }]
options = {}
response = ai_agent.send_messages(messages, options)
ai_agent.format_response(response)

Sentiment analysis:

ai_agent = AiAgent::Claude.new
review = "The product quality is excellent and the customer service was very helpful!"
response = ai_agent.analyze_sentiment(review, options: { model: Claude::Model::CLAUDE_CHEAPEST })
ai_agent.format_response(response)

Named entity recognition:

ai_agent = AiAgent::Claude.new
abstract = "Anthropic released Claude 3.5 Sonnet on 21 June 2024."
response = ai_agent.recognize_entities(abstract, options: { model: Claude::Model::CLAUDE_CHEAPEST })
ai_agent.format_response(response)

Text summarization:

ai_agent = AiAgent::Claude.new
abstract = "A long message" # customise this for your own example
response = ai_agent.summarize_text(abstract, strict: false, options: { model: Claude::Model::CLAUDE_SMARTEST })
ai_agent.format_response(response)

Changelog

For a detailed list of changes for each version of this project, please see the CHANGELOG.

Development

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.

To install this gem onto your local machine, run bundle exec rake install.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/webventures/aiagent.

License

The gem is available as open source under the terms of the MIT License.

Trademarks

This gem refers to agents that have been developed by third parties. Ownership of the respective trademarks remains with those parties.