Commit 58a70af
Changed files (5)
lib/net/llm/version.rb
@@ -2,6 +2,6 @@
module Net
module Llm
- VERSION = "0.4.0"
+ VERSION = "0.5.0"
end
end
lib/net/llm/vertex_ai.rb
@@ -5,7 +5,7 @@ module Net
class VertexAI
attr_reader :project_id, :region, :model
- def initialize(project_id: ENV.fetch("GOOGLE_CLOUD_PROJECT"), region: ENV.fetch("GOOGLE_CLOUD_REGION", "us-east5"), model: "claude-sonnet-4@20250514", http: Net::Llm.http)
+ def initialize(project_id: ENV.fetch("GOOGLE_CLOUD_PROJECT"), region: ENV.fetch("GOOGLE_CLOUD_REGION", "us-east5"), model: "claude-opus-4-5@20251101", http: Net::Llm.http)
@project_id = project_id
@region = region
@model = model
CHANGELOG.md
@@ -1,5 +1,7 @@
## [Unreleased]
+## [0.5.0] - 2025-01-07
+
### Added
- VertexAI provider for Claude models via Google Cloud
- Uses Application Default Credentials (ADC) for authentication
@@ -8,12 +10,26 @@
- Unified `fetch(messages, tools = [], &block)` method across all providers
- Normalized response format with `:delta` and `:complete` types
- Consistent `tool_calls` structure: `{ id:, name:, arguments: }`
+ - Thinking content support in streaming responses
- Claude class for shared Anthropic protocol logic
+ - Automatic system message extraction from messages array
+ - Message normalization for tool results and tool_calls
+- Environment variable support for provider configuration
+ - `OLLAMA_HOST` for Ollama (default: localhost:11434)
+ - `OPENAI_API_KEY` and `OPENAI_BASE_URL` for OpenAI
+ - `ANTHROPIC_API_KEY` for Anthropic
+ - `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_REGION` for VertexAI
### Changed
- Refactored Anthropic provider to delegate to Claude class
- Refactored VertexAI provider to delegate to Claude class
- Updated default Anthropic model to claude-sonnet-4-20250514
+- Updated default VertexAI model to claude-opus-4-5@20251101
+
+### Fixed
+- Fixed streaming tool_calls accumulation in Ollama provider
+- Fixed error responses to include response body for debugging
+- Fixed VertexAI model name format (@ separator instead of -)
## [0.4.0] - 2025-10-15
### Added
Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
- net-llm (0.4.0)
+ net-llm (0.5.0)
json (~> 2.0)
net-hippie (~> 1.0)
uri (~> 1.0)
README.md
@@ -1,6 +1,6 @@
# Net::Llm
-A minimal Ruby gem providing interfaces to connect to OpenAI, Ollama, and Anthropic (Claude) LLM APIs.
+A minimal Ruby gem providing interfaces to connect to OpenAI, Ollama, Anthropic (Claude), and VertexAI LLM APIs.
## Installation
@@ -144,7 +144,7 @@ require 'net/llm'
client = Net::Llm::Anthropic.new(
api_key: ENV['ANTHROPIC_API_KEY'],
- model: 'claude-3-5-sonnet-20241022'
+ model: 'claude-sonnet-4-20250514'
)
messages = [
@@ -194,6 +194,54 @@ tools = [
response = client.messages(messages, tools: tools)
```
+### VertexAI
+
+```ruby
+require 'net/llm'
+
+client = Net::Llm::VertexAI.new(
+ project_id: ENV['GOOGLE_CLOUD_PROJECT'],
+ region: ENV.fetch('GOOGLE_CLOUD_REGION', 'us-east5'),
+ model: 'claude-opus-4-5@20251101'
+)
+
+messages = [
+ { role: 'user', content: 'Hello!' }
+]
+
+response = client.messages(messages)
+puts response.dig('content', 0, 'text')
+```
+
+Uses Application Default Credentials (ADC) for authentication. Run `gcloud auth application-default login` to configure.
+
+### Unified Fetch Interface
+
+All providers support a unified `fetch` method with a normalized response format:
+
+```ruby
+result = client.fetch(messages, tools)
+
+result[:type] # :complete
+result[:content] # "Response text"
+result[:thinking] # Extended thinking (Claude only)
+result[:tool_calls] # [{ id:, name:, arguments: }]
+result[:stop_reason] # :end_turn, :tool_use, :max_tokens
+```
+
+#### Streaming
+
+```ruby
+client.fetch(messages, tools) do |chunk|
+ case chunk[:type]
+ when :delta
+ print chunk[:content]
+ when :complete
+ puts "\nDone: #{chunk[:stop_reason]}"
+ end
+end
+```
+
## Error Handling
All non-streaming API methods return error information as a hash when requests fail:
@@ -227,6 +275,9 @@ Streaming methods still raise exceptions on HTTP errors.
### Anthropic (Claude)
- `/v1/messages` (with streaming and tools)
+### VertexAI
+- Claude models via Google Cloud AI Platform (with streaming and tools)
+
## 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.