ai_client

`ai_client` is a versatile Ruby gem that serves as a generic client for interacting with various AI service providers through a unified API. Designed to simplify the integration of large language models (LLMs) into applications, `ai_client` allows developers to create instances using just the model name, greatly reducing configuration overhead. With built-in support for popular AI providers—including OpenAI, Anthropic, Google, Mistral, LocalAI and Ollama—the gem abstracts the complexities of API interactions, offering methods for tasks such as chatting, transcription, speech synthesis, and embedding. The middleware architecture enables customizable processing of requests and responses, making it easy to implement features like logging and retry logic. Seamlessly integrated with the `OmniAI` framework, `ai_client` empowers developers to leverage cutting-edge AI capabilities without vendor lock-in, making it an essential tool for modern AI-driven applications.

MIT License

Downloads
103
Stars
0

AiClient

First and foremost a big THANK YOU to Kevin Sylvestre for his gem OmniAI upon which this effort depends.

This is a work in progress Its implemented as a class rather than the typical module for most gems. The AiClient::Configuration class is a little first draft-ish. I'm looking to bulk it up a lot. At this point I think some of the current tests are failing; but, over all AiClien is working. I've used early versions of it in several projects.

Summary

ai_client is a versatile Ruby gem that serves as a generic client for interacting with various AI service providers through a unified API provided by Kevin's gem OmniAI. The AiClient class is designed to simplify the integration of large language models (LLMs) into applications. AiClient allows developers to create instances using just the model name, greatly reducing configuration overhead.

With built-in support for popular AI providersincluding OpenAI, Anthropic, Google, Mistral, LocalAI and Ollamathe gem abstracts the complexities of API interactions, offering methods for tasks such as chatting, transcription, speech synthesis, and embedding.

The middleware architecture enables customizable processing of requests and responses, making it easy to implement features like logging and retry logic. Seamlessly integrated with the OmniAI framework, ai_client empowers developers to leverage cutting-edge AI capabilities without vendor lock-in, making it an essential tool for modern AI-driven applications.

Installation

If you are using a Gemfile and bundler in your project just install the gem by executing:

bundle add ai_client

If bundler is not being used to manage dependencies, install the gem by executing:

gem install ai_client

Usage

Basic usage:

AI = AiClient.new('gpt-4o')

That's it. Just provide the model name that you want to use. If you application is using more than one model, no worries, just create multiple AiClient instances.

c1 = AiClient.new('nomic-embeddings-text')
c2 = AiClient.new('gpt-4o-mini')

Configuration

There is an internal hard-coded configuration default. That default is duppled into a class-level configuration which can be over-ridden with a class-level config block like this ...

AiClient.configure do |config|
  config.some_item = some_value
end

Every instance of the AiClient inherents the class-level configuration; however, the instance configuration can also be over-ridden also with a block like this ...

client = AiClient.new('super-ai-overlord-model') do |config|
  config.some_item = some_value
end

But wait, there's more. You can also load a YAML file as a configuration of an instance like this ...

client = AiClient.new('baby-model', config: 'path/to/file.yml')

What Now?

TODO: Document the methods and their options.

AI.chat(...)
AI.transcribe(...)
AI.speak(...)
AI.embed(...)
AI.batch_embed(...)

TODO: see the [examples] directory.

System Environment Variables

The API keys used with each LLM provider have the pattern XXX_API_KEY where XXX is the name of the provided. For example OPENAI_API_KEY1 and ANTROPIC_API_KEY etc.

TODO: list all providers supported and their envar

Options

TODO: document the options like provider: :ollama

Contributing

I can sure use your help. This industry is moving faster than I can keep up with. If you have a bug fix or new feature idea then have at it. Send me a pull request so we all can benefit from your efforts.

If you only have time to report a bug, that's fine. Just create an issue in this repo.

License

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