Class: Autotype::OpenAiCapabilityNamer

Inherits:
Object
  • Object
show all
Defined in:
lib/autotype/engine.rb

Constant Summary collapse

DEFAULT_MODEL =
"gpt-5.6-luna"
DEFAULT_BATCH_SIZE =
100
DEFAULT_CONCURRENCY =
16
SYSTEM_PROMPT =
<<~PROMPT.freeze
  Name every anonymous structural Ruby capability below.

  Return one concise PascalCase interface name per id using the "-able"
  framework. Describe what values can do, not their implementation or a
  nominal class.

  Examples: Stringifiable, Enumerable, KeyFetchable, EventEmittable,
  CurrentQuestionReadable, CacheClearable, ScoreRankable.

  Rules:
  - Return every input id exactly once.
  - Use one to four semantic words.
  - End with Able, Ible, Ifiable, or Izable.
  - Prefer established Ruby vocabulary when precise.
  - Name the combined ability when multiple methods are present.
  - Never include hashes, ids, generic parameter names, or "Capability".
  - Return only a JSON object mapping each id to its name.
PROMPT
MAX_COLLISION_ROUNDS =
5
CLUSTER_PROMPT =
<<~PROMPT.freeze
  These distinct structural Ruby capability types were all given the name
  "%<shared_name>s". Rename them so every id gets a unique PascalCase name.

  Rules:
  - Return every input id exactly once, each with a different name.
  - Distinguish members using their methods, argument types, and result types.
  - The most general member may stay close to "%<shared_name>s"; the others
    must be more specific.
  - Never use numbers, hashes, or the words "Variant" or "Capability".
  - Use one to five semantic words ending with Able, Ible, Ifiable, or Izable.
  - Return only a JSON object mapping each id to its name.
PROMPT

Instance Method Summary collapse

Constructor Details

#initialize(registry, cache_path:, model: DEFAULT_MODEL, batch_size: DEFAULT_BATCH_SIZE, concurrency: DEFAULT_CONCURRENCY, runner: nil) ⇒ OpenAiCapabilityNamer

Returns a new instance of OpenAiCapabilityNamer.



4269
4270
4271
4272
4273
4274
4275
4276
4277
# File 'lib/autotype/engine.rb', line 4269

def initialize(registry, cache_path:, model: DEFAULT_MODEL, batch_size: DEFAULT_BATCH_SIZE,
  concurrency: DEFAULT_CONCURRENCY, runner: nil)
  @registry = registry
  @cache_path = cache_path
  @model = model
  @batch_size = batch_size
  @concurrency = concurrency
  @runner = runner || method(:run_openai)
end

Instance Method Details

#name!Object



4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
# File 'lib/autotype/engine.rb', line 4294

def name!
  names = load_cache
  missing = @registry.definitions.reject { |definition| names.key?(definition.fetch(:id)) }
  batches = missing.each_slice(@batch_size).to_a
  puts "Naming #{missing.length} capabilities in #{batches.length} parallel batches with #{@model}..." if batches.any?
  parallel_map(batches) { |batch| name_batch(batch) }.each { |batch_names| names.merge!(batch_names) }
  File.write(@cache_path, JSON.pretty_generate(names.sort.to_h)) if batches.any?

  resolve_collisions!(names)
  @registry.apply_names!(names)
  names
end