Async::OllamaSourceAsyncOllamaTransform

class Transform

Transforms file content using a local Ollama model.

Useful for intelligently merging template changes into existing files, without overwriting user modifications.

Example: Transform a bake.rb to add missing release hooks:

new_content = Async::Ollama::Transform.call(
  File.read("bake.rb"),
  instruction: "Add the after_gem_release hooks if they are not already present.",
  template: File.read(template_path)
)
File.write("bake.rb", new_content)

Signature

Definitions

def initialize(model: MODEL)

Signature

parameter model String

The Ollama model to use.

Implementation

def initialize(model: MODEL)
	@model = model
end

def call(content, instruction:, template: nil, model: @model)

Transform file content according to the given instruction.

Signature

parameter content String

The current file content.

parameter instruction String

What change to make.

parameter template String | nil

An optional reference example showing the desired structure.

returns String

The transformed file content.

Implementation

def call(content, instruction:, template: nil, model: @model)
	messages = [
		{role: "system", content: SYSTEM_PROMPT},
		{role: "user", content: build_prompt(content, instruction, template)}
	]
	
	Client.open do |client|
		reply = client.chat(messages, model: model)
		
		self.strip_fences(reply.response)
	end
end

def self.call(content, **options)

Convenience class method.

Signature

parameter content String

The current file content.

parameter options Hash

Keyword arguments forwarded to #call.

returns String

The transformed file content.

Implementation

def self.call(content, **options)
	new.call(content, **options)
end