Commit 6a98e2a
Changed files (4)
CHANGELOG.md
@@ -3,3 +3,5 @@
## [0.1.0] - 2025-10-07
- Initial release
+- OpenAI provider with chat/completions endpoint
+- Support for OpenAI-compatible APIs via custom base_url
Gemfile.lock
@@ -0,0 +1,53 @@
+PATH
+ remote: .
+ specs:
+ net-llm (0.1.0)
+
+GEM
+ remote: https://rubygems.org/
+ specs:
+ cgi (0.4.2)
+ date (3.4.1)
+ diff-lcs (1.6.2)
+ erb (4.0.4)
+ cgi (>= 0.3.3)
+ io-console (0.8.1)
+ irb (1.14.3)
+ rdoc (>= 4.0.0)
+ reline (>= 0.4.2)
+ psych (5.2.2)
+ date
+ stringio
+ rake (13.3.0)
+ rdoc (6.14.0)
+ erb
+ psych (>= 4.0.0)
+ reline (0.6.0)
+ io-console (~> 0.5)
+ rspec (3.13.1)
+ rspec-core (~> 3.13.0)
+ rspec-expectations (~> 3.13.0)
+ rspec-mocks (~> 3.13.0)
+ rspec-core (3.13.5)
+ rspec-support (~> 3.13.0)
+ rspec-expectations (3.13.5)
+ diff-lcs (>= 1.2.0, < 2.0)
+ rspec-support (~> 3.13.0)
+ rspec-mocks (3.13.5)
+ diff-lcs (>= 1.2.0, < 2.0)
+ rspec-support (~> 3.13.0)
+ rspec-support (3.13.6)
+ stringio (3.1.2)
+
+PLATFORMS
+ ruby
+ x86_64-linux
+
+DEPENDENCIES
+ irb
+ net-llm!
+ rake (~> 13.0)
+ rspec (~> 3.0)
+
+BUNDLED WITH
+ 2.7.2
net-llm.gemspec
@@ -8,13 +8,11 @@ Gem::Specification.new do |spec|
spec.authors = ["mo khan"]
spec.email = ["mo@mokhan.ca"]
- spec.summary = "TODO: Write a short summary, because RubyGems requires one."
- spec.description = "TODO: Write a longer description or delete this line."
+ spec.summary = "Ruby client for OpenAI, Ollama, and Anthropic LLM APIs"
+ spec.description = "A minimal Ruby gem providing interfaces to connect to OpenAI, Ollama, and Anthropic (Claude) LLM APIs"
spec.homepage = "https://github.com/xlgmokha/net-llm"
spec.license = "MIT"
spec.required_ruby_version = ">= 3.2.0"
-
- spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
spec.metadata["homepage_uri"] = spec.homepage
spec.metadata["source_code_uri"] = "https://github.com/xlgmokha/net-llm"
spec.metadata["changelog_uri"] = "https://github.com/xlgmokha/net-llm/blob/main/CHANGELOG.md"
README.md
@@ -1,28 +1,84 @@
# Net::Llm
-TODO: Delete this and the text below, and describe your gem
-
-Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/net/llm`. To experiment with that code, run `bin/console` for an interactive prompt.
+A minimal Ruby gem providing interfaces to connect to OpenAI, Ollama, and Anthropic (Claude) LLM APIs.
## Installation
-TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
-
Install the gem and add to the application's Gemfile by executing:
```bash
-bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
+bundle add net-llm
```
If bundler is not being used to manage dependencies, install the gem by executing:
```bash
-gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
+gem install net-llm
```
## Usage
-TODO: Write usage instructions here
+### OpenAI
+
+```ruby
+require 'net/llm'
+
+client = Net::Llm::OpenAI.new(
+ api_key: ENV['OPENAI_API_KEY'],
+ model: 'gpt-4o-mini'
+)
+
+messages = [
+ { role: 'user', content: 'Hello!' }
+]
+
+response = client.chat(messages, [])
+puts response.dig('choices', 0, 'message', 'content')
+```
+
+#### Custom Base URL
+
+```ruby
+client = Net::Llm::OpenAI.new(
+ api_key: ENV['OPENAI_API_KEY'],
+ base_url: 'https://custom-openai-compatible-api.com/v1',
+ model: 'gpt-4o-mini'
+)
+```
+
+#### With Tools
+
+```ruby
+tools = [
+ {
+ type: 'function',
+ function: {
+ name: 'get_weather',
+ description: 'Get current weather',
+ parameters: {
+ type: 'object',
+ properties: {
+ location: { type: 'string' }
+ },
+ required: ['location']
+ }
+ }
+ }
+]
+
+response = client.chat(messages, tools)
+```
+
+## API Coverage
+
+### OpenAI
+- `/v1/chat/completions` (with tools support)
+
+### Ollama
+Coming soon
+
+### Anthropic (Claude)
+Coming soon
## Development