clawdforge/clients/ruby/examples/basic.rb

44 lines
1.3 KiB
Ruby

# frozen_string_literal: true
# Basic usage example for the clawdforge Ruby SDK.
#
# Run with:
# CLAWDFORGE_URL=http://localhost:8800 \
# CLAWDFORGE_TOKEN=cf_xxx \
# ruby -Ilib examples/basic.rb
require "clawdforge"
base_url = ENV.fetch("CLAWDFORGE_URL", "http://localhost:8800")
token = ENV.fetch("CLAWDFORGE_TOKEN")
forge = Clawdforge::Client.new(base_url: base_url, token: token)
# 1) Healthz — verify the service is up and `claude` is installed.
health = forge.healthz
puts "claude_present: #{health["claude_present"]}"
puts "claude_version: #{health["claude_version"]}"
# 2) Run a prompt that asks for JSON. `result` will be a parsed Hash.
result = forge.run(
prompt: 'Reply with JSON: {"hello": "world"}',
model: "sonnet",
system: "Be terse. Reply with JSON only.",
timeout_secs: 60,
)
puts "duration_ms: #{result.duration_ms}"
puts "stop_reason: #{result.stop_reason}"
puts "result: #{result.result.inspect}"
# 3) Upload a file, then reference it from a /run call.
if File.file?("./recipe.png")
ft = forge.upload_file("./recipe.png", ttl_secs: 3600)
puts "uploaded #{ft.size} bytes; token=#{ft.file_token} ttl=#{ft.ttl_secs}s"
vision = forge.run(
prompt: "extract recipe data as JSON",
files: [ft.file_token],
timeout_secs: 120,
)
puts vision.result.inspect
end