Skip to content

Instantly share code, notes, and snippets.

@kuredev
Created September 6, 2025 06:01
Show Gist options
  • Select an option

  • Save kuredev/b44254e32b7eeb33dc08bcba74073172 to your computer and use it in GitHub Desktop.

Select an option

Save kuredev/b44254e32b7eeb33dc08bcba74073172 to your computer and use it in GitHub Desktop.
langchainrb で Open AI の API で Function Calling でCloud Automatorのジョブを取得するサンプル
require 'net/http'
require 'uri'
require "json"
require "langchain"
class KureTool
extend Langchain::ToolDefinition
define_function :get_jobs, description: "KureTool: Get Cloud Automator Jobs from Cloud Automator by using Cloud Automator's API"
def get_jobs
uri = URI.parse("https://manager.cloudautomator.com/api/v1/jobs")
request = Net::HTTP::Get.new(uri)
request.content_type = "application/json"
request["Authorization"] = "Bearer xxxxxxxxxxxxxxxxxxxxx"
req_options = {
use_ssl: uri.scheme == "https",
}
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
http.request(request)
end
tool_response(content: JSON.parse(response.body)["data"])
end
end
kure_tool = KureTool.new
llm = Langchain::LLM::OpenAI.new(
api_key: "xxxxxxxxxxxxxxx",
default_options: { temperature: 0.7, chat_model: "gpt-4o" }
)
assistant = Langchain::Assistant.new(
llm: llm,
instructions: "You're a helpful AI assistant that can provide movie information",
tools: [kure_tool]
)
assistant.add_message_and_run!(content: "Cloud Automatorのジョブの一覧出して。")
pp assistant.messages
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment