Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Add this line to your application's Gemfile:
gem 'aiagent'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install aiagent
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"
require "ai_agent/ai_agent/open_ai"
You'll also need to add supporting gems to your Gemfile for each of the agents that you enable.
gem 'claude-ruby'
gem 'ruby-openai'
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')
Basic example usage for OpenAI ChatGPT:
ai_agent = AiAgent::OpenAI.new(timeout: 30)
prompt = "Generate 5 inspirational quotes."
messages = [{ 'role': 'user', 'content': prompt }]
response = ai_agent.chat(messages, options: {})
ai_agent.format_response(response)
Basic example usage for Anthropic Claude:
ai_agent = AiAgent::Claude.new(timeout: 30)
prompt = "Generate 5 inspirational quotes."
messages = [{ 'role': 'user', 'content': prompt }]
response = ai_agent.chat(messages, options: {})
ai_agent.format_response(response)
At the API level Claude 'system' message needs to be a parameter in the options rather than an element in the messages array.
Using AiAgent you have the choice of using a Claude-specific 'send_messages' method which takes the data in the format expected by Claude, or you can use the more standard 'chat' interface, which follows the openai convention and will be mapped seamlessly by AiAgent.
Example using send_messages:
ai_agent = AiAgent::Claude.new(timeout: 30)
prompt = "Generate 5 inspirational quotes."
messages = [{ 'role': 'user', 'content': prompt }]
response = ai_agent.send_messages(messages, options: { system: 'Reply only in Spanish.' })
ai_agent.format_response(response)
Example using chat:
ai_agent = AiAgent::Claude.new(timeout: 30)
prompt = "Generate 5 inspirational quotes."
messages = [{ 'role': 'system', 'content': 'Reply only in Spanish' }, { 'role': 'user', 'content': prompt }]
response = ai_agent.chat(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)
For a detailed list of changes for each version of this project, please see the CHANGELOG.
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
.
Bug reports and pull requests are welcome on GitHub at https://github.com/webventures/aiagent.
The gem is available as open source under the terms of the MIT License.
This gem refers to agents that have been developed by third parties. Ownership of the respective trademarks remains with those parties.
FAQs
Unknown package
We found that aiagent demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.