Llmclt
A simple client for Gemini API.
For an authentication, this gem uses a service account json file.
Installation
Add this line to your application's Gemfile:
gem 'llmclt'
And then run:
$ bundle install
Or install it yourself as:
$ gem install llmclt
Usage
Use as follows:
client = Llmclt::Client.new(
project_id: project_id,
location_id: location_id,
model: model,
service_account_json: service_account_json
)
prompt = 'Hello. This is Tom!. How are you?'
response = client.request(prompt)
response.text
client.shutdown
System instruction
client = Llmclt::Client.new(
project_id: project_id,
location_id: location_id,
model: model,
service_account_json: service_account_json,
system_instruction_prompt: 'You are a helpful assistant.'
)
prompt = 'Hello. This is Tom!. How are you?'
response = client.request(prompt)
response.text
client.shutdown
Stream mode
response = client.request(prompt, stream: true)
response.text
Multi turn
histories = [
{ role: 'user', text: 'Hello! This is Tom.' },
{ role: 'model', text: 'Hello, Tom. Can I help you?' }
]
prompt = 'Do you know my name?'
response = client.request(prompt, histories: histories)
response.text
Configuration
client = Llmclt::Client.new(
project_id: project_id,
location_id: location_id,
model: model,
service_account_json: service_account_json,
safety_settings: [
{
category: 'HARM_CATEGORY_DANGEROUS_CONTENT',
threshold: 'BLOCK_LOW_AND_ABOVE'
}
],
generation_config: {
temperature: 1.0,
top_p: 0.95
}
)
Refer the API references for configuration.
Development
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
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
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and the created tag, and push the .gem
file to rubygems.org.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/MasatoMiyoshi/llmclt. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
License
The gem is available as open source under the terms of the MIT License.
Code of Conduct
Everyone interacting in the Llmclt project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.