Commit f8e0591
Changed files (1)
lib
net
llm
lib/net/llm/vertex_ai.rb
@@ -9,19 +9,27 @@ module Net
@project_id = project_id
@region = region
@model = model
- @claude = Claude.new(
- endpoint: "https://#{region}-aiplatform.googleapis.com/v1/projects/#{project_id}/locations/#{region}/publishers/anthropic/models/#{model}:rawPredict",
- headers: -> { { "Authorization" => "Bearer #{access_token}" } },
- http: http,
- anthropic_version: "vertex-2023-10-16"
- )
+ @handler = build_handler(http)
end
- def messages(...) = @claude.messages(...)
- def fetch(...) = @claude.fetch(...)
+ def messages(...) = @handler.messages(...)
+ def fetch(...) = @handler.fetch(...)
private
+ def build_handler(http)
+ if model.start_with?("claude-")
+ Claude.new(
+ endpoint: "https://#{region}-aiplatform.googleapis.com/v1/projects/#{project_id}/locations/#{region}/publishers/anthropic/models/#{model}:rawPredict",
+ headers: -> { { "Authorization" => "Bearer #{access_token}" } },
+ http: http,
+ anthropic_version: "vertex-2023-10-16"
+ )
+ else
+ raise NotImplementedError, "Model '#{model}' is not yet supported. Only Claude models (claude-*) are currently implemented."
+ end
+ end
+
def access_token
@access_token ||= `gcloud auth application-default print-access-token`.strip
end